|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
clear
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;
y=fft(ii,1600)
pyy=y.*conj(y)
y1=y;y1(20:890)=0
y2=y;y2(30:760)=0
y3=y;y3(40:1040)=0
xd1=real(ifft(y1,1600))
xd2=real(ifft(y2,1600))
xd3=real(ifft(y3,1600))
subplot(411);plot(ii);axis([0 1600 -50 100]);title('0');grid on;
subplot(412);plot(xd1);axis([0 1600 -50 100]);title('1');grid on;
subplot(413);plot(xd2);axis([0 1600 -50 100]);title('2');grid on;
subplot(414);plot(xd3);axis([0 1600 -50 100]);title('3');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-xd3).^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)-xd3(:,:,i)).^2));%noise power
snr=snr+10*log10(Ps/Pn);
end
snr=snr/3;
end
disp(snr); |
|