|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
请教:请问为何这段程序每次运行得到的信噪比结果都不一样呢
x=0:1:1600;
n=1:length(x);
a=50*exp(-(n-420).^2/144);
d=70*exp(-(n-1200).^2/324);
g=a+d;
h=40*exp(-(n-800).^2/2);
i1=g+h;
r=randn(1,1601);
r=r-mean(r);
r=sqrt(2.56)*r./sqrt(var(r));
ii=i1+r;
np=3;h=1/np;
h=h(ones(1,np));
y1=conv(h,ii);
y2=filter(h,1,ii);
subplot(221);plot(x,ii);axis([0 1600 -20 80]);grid on;
subplot(222);
plot(y1,'r');axis([0 1600 -20 80]);grid on;
subplot(223);
plot(y2,'r');axis([0 1600 -20 80]);grid on;
[row,col,nchannel]=size(i1);
snr=0;
if nchannel==1%gray image
Ps=sum(sum((i1-mean(mean(i1))).^2));%signal power
Pn=sum(sum((i1-y2).^2));%noise power
snr=10*log10(Ps/Pn);
elseif nchannel==3%color image
for i=1:3
Ps=sum(sum((i1(:,:,i)-mean(mean(i1(:,:,i)))).^2));%signal power
Pn=sum(sum((i1(:,:,i)-y2(:,:,i)).^2));%noise power
snr=snr+10*log10(Ps/Pn);
end
snr=snr/3;
end
disp(snr); |
|