
clear all
close all
x=0:0.2:10
data1=sin(x)
plot(x,data1)
hold on
data2=awgn(data1,10*log10(0.05))
plot(x,data2,'r-')
hold off
扩展资料
function [Y,NOISE] = noisegen(X,SNR)
% noisegen add white Gaussian noise to a signal.
% [Y, NOISE] = NOISEGEN(X,SNR) adds white Gaussian NOISE to X. The SNR is in dB.
NOISE=randn(size(X))
NOISE=NOISE-mean(NOISE)
signal_power = 1/length(X)*sum(X.*X)
noise_variance = signal_power / ( 10^(SNR/10) )
NOISE=sqrt(noise_variance)/std(NOISE)*NOISE
Y=X+NOISE
其中X是纯信号,SNR是要求的信噪比,Y是带噪信号,NOISE是叠加在信号上的噪声。
1、添加的是20%的随即噪声image=double(image)
I=image+20*randn(size(image))
figureimshow(uint8(I))
title('noised image')
[a1,h1,v1,d1]=dwt2(I,'sym8')
[a2,h2,v2,d2]=dwt2(a1,'sym8')
[a3,h3,v3,d3]=dwt2(a2,'sym8')
sigma=median(abs(d1(:)))/0.6745
thr1=thr*2^(-(3-1)/2)
thr2=thr*2^(-(3-2)/2)thr3=thr*2^(-(3-3)/2)
ccch=soft_t(h3,thr1)cccv=soft_t(v3,thr1)cccd=soft_t(d3,thr1)cch=soft_t(h2,thr2)ccv=soft_t(v2,thr2)ccd=soft_t(d2,thr2)ch=soft_t(h1,thr3)cv=soft_t(v1,thr3)cd=soft_t(d1,thr3)
cca=idwt2(a3,ccch,cccv,cccd,'sym8')ca=idwt2(cca,cch,ccv,ccd,'sym8')J1=idwt2(ca,ch,cv,cd,'sym8')J1=uint8(J1)
figureimshow(J1)title('denoised image')p=psnr(image,J1)
2、加高斯白噪声
image=double(image)
I=awgn(image,5)%加入信噪比为5分贝的高斯白噪声
figureimshow(uint8(I))title('noised image')
注:源代码是计算机语言,不能随便用自己语言的。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)