%加载纯净语音信号
x = wnoise('bumps',8);
%加载高斯白噪声
snr=15;%修改含噪信号的信噪比
y=awgn(x,snr,'measured');
%含噪信号的信噪比与均方误差
snro=SNR(x,y)
d= MSE(x,y)
%小波分解
[c,l]=wavedec(y,6,'sym7');
ca6=appcoef(c,l,'sym7',6);
cd6=detcoef(c,l,6);
cd5=detcoef(c,l,5);
cd4=detcoef(c,l,4);
cd3=detcoef(c,l,3);
cd2=detcoef(c,l,2);
cd1=detcoef(c,l,1);
%获得默认阈值%
sigma= median(abs(cd1))/0.6745;
alpha=2;
thr=wbmpen(c,l,sigma,alpha);
%软阈值去噪%
cd1soft=wthresh(cd1,'s',thr);
cd2soft=wthresh(cd2,'s',thr);
cd3soft=wthresh(cd3,'s',thr);
cd4soft=wthresh(cd4,'s',thr);
cd5soft=wthresh(cd5,'s',thr);
cd6soft=wthresh(cd6,'s',thr);
csoft=[ca6 cd6soft cd5soft cd4soft cd3soft cd2soft cd1soft];
xsoft=waverec(csoft,l ,'sym7');
%硬阈值去噪
cdhard1=wthresh(cd1,'h',thr);
cdhard2=wthresh(cd2,'h',thr);
cdhard3=wthresh(cd3,'h',thr);
cdhard4=wthresh(cd4,'h',thr);
cdhard5=wthresh(cd5,'h',thr);
cdhard6=wthresh(cd6,'h',thr);
chard=[ca6 cdhard6 cdhard5 cdhard4 cdhard3 cdhard2 cdhard1];
xhard=waverec(chard,l,'sym7');
%默认去噪方法%
%xd=wdencmp('gbl',x,'db4',3,thr,sorh,keepapp);
%新去噪方法%
cd1new=newthresh(cd1,thr,0.3);
cd2new=newthresh(cd2,thr,0.3);
cd3new=newthresh(cd3,thr,0.3);
cd4new=newthresh(cd4,thr,0.3);
cd5new=newthresh(cd5,thr,0.3);
cd6new=newthresh(cd6,thr,0.3);
cnew=[ca6 cd6new cd5new cd4new cd3new cd2new cd1new];
xnew=waverec(cnew,l,'sym7');
%计算去噪后的SNR%
snrsoft=SNR_singlech(x,xsoft)
ds= MSE(x,xsoft)
snrhard=SNR_singlech(x,xhard)
dh= MSE(x,xhard)
snrnew=SNR_singlech(x,xnew)
dn= MSE(x,xnew)
%画图%
figure(1)
subplot(311);plot(x);
axis([0 1200 -5 10]);
xlabel('(a) 原始纯净bumps信号 (采样点)');ylabel('幅度');
subplot(312);plot(y);
axis([0 1200 -5 10]);
xlabel('(b) 含噪bumps信号 (采样点)');ylabel('幅度');
subplot(313);plot(xsoft);
axis([0 1200 -5 10]);
xlabel('(c) 软阈值降噪后bumps信号 (采样点)');ylabel('幅度');
figure(2)
subplot(311);plot(x);
axis([0 1200 -5 10]);
xlabel('(a) 原始纯净bumps信号 (采样点)');ylabel('幅度');
subplot(312);plot(y);
axis([0 1200 -5 10]);
xlabel('(b) 含噪bumps信号 (采样点)');ylabel('幅度');
subplot(313);plot(xhard);
axis([0 1200 -5 10]);
xlabel('(c) 硬阈值降噪后bumps信号 (采样点)');ylabel('幅度');
figure(3)
subplot(311);plot(x);
axis([0 1200 -5 10]);
xlabel('(a) 原始纯净bumps信号 (采样点)');ylabel('幅度');
subplot(312);plot(y);
axis([0 1200 -5 10]);
xlabel('(b) 含噪bumps信号 (采样点)');ylabel('幅度');
subplot(313);plot(xnew);
axis([0 1200 -5 10]);
xlabel('(c) 改进阈值降噪后bumps信号 (采样点)');ylabel('幅度');