clear all;
clc;
load leleccum;
indx=1:1024;
x=leleccum(indx);
% 产生含噪信号
init=2055615866;
randn('seed',init);
nx=x+18*randn(size(x));
subplot(321);
plot(x);
title('原始信号');grid;
subplot(322);
plot(nx);
title('含噪信号');grid;
%用db1小波对原始信号进行2层分解并提取系数
[c,l]=wavedec(nx,2,'db1');
ca2=appcoef(c,l,'db1',2);
cd2=detcoef(c,l,2);
cd1=detcoef(c,l,1);
%对信号进行强制性消噪处理并图示结果
cdd2=zeros(1,length(cd2));
cdd1=zeros(1,length(cd1));
c1=[ca2 cdd2 cdd1];
s1=waverec(c1,l,'db1');
subplot(323);
plot(s1);
title('强制消噪后的信号');grid;
%用默认阈值对信号进行消噪处理并图示结果
%用ddencmp函数获得信号的默认阈值,使用wdencmp命令函数实现消噪过程
[thr,sorh,keepapp]=ddencmp('den','wv',nx);
s2=wdencmp('gbl',c,l,'db1',2,thr,sorh,keepapp);
subplot(324); plot(s2);
title('默认阈值消噪后的信号');grid;
%用给定的软阈值进行消噪处理,软阈值根据经验公式算
cd1soft=wthresh(cd1,'s',**);
cd2soft=wthresh(cd2,'s',**);
c2=[ca2 cd2soft cd1soft];
s3=waverec(c2,l,'db1');
subplot(325);
plot(s3);
title('给定软阈值消噪后的信号');grid
%去噪效果以均方差和信噪比为准则
rmse3=sqrt(sum((s3-x).^2))/1024
snr3=0;
Ps3=sum(sum((x-mean(mean(x))).^2));%signal power
Pn3=sum(sum((x-s3).^2));%noise power
snr3=10*log10(Ps3/Pn3)
% 得到Haar小波的提升方案
lshaar=liftwave('db1');
% 将提升步骤ELS添加到提升方案中
els={'p',[-0.125 0.125],0};
lsnew=addlift(lshaar,els);
% 进行提升小波分解
[cA1,cD1]=lwt(x,lsnew);
[cA2,cD2]=lwt(cA1,lsnew);
length=size(cA2,2);
c=zeros(1,length*4);
for i=1:length;
c(i)=cA2(i);
end
for i=length+1:2*length;
c(i)=cD2(i-length);
end;
for i=length*2+1:4*length;
c(i)=cD1(i-2*length);
end;
l(1)=length;
l(2)=length;
l(3)=length*2;
l(4)=length*4;
% 估计尺度1的噪声标准差
sigma=wnoisest(c,l,1);
alpha=2;
% 获得消噪过程中的阈值
thr=wbmpen(c,l,sigma,alpha);
keepapp=1;
% 对信号进行消噪
xd=wdencmp('gbl',c,l,'db1',2,thr,'s',keepapp);
subplot(326);
plot(xd(1:1024));
title('提升db1消噪后的信号');grid;
rmse4=sqrt(sum((xd-x).^2))/1024
snr4=0;
Ps4=sum(sum((x-mean(mean(x))).^2));%signal power
Pn4=sum(sum((x-xd).^2));%noise power
snr4=10*log10(Ps4/Pn4)
%%%只需将上文中的db1换为db4db6即可
xd1=wdencmp('gbl',c,l,'db4',2,thr,'s',keepapp);
figure(2)
subplot(121);
plot(xd1(1:1000));
title('提升db4消噪后的信号');grid;
xd2=wdencmp('gbl',c,l,'db6',2,thr,'s',keepapp);
subplot(122);
plot(xd2(1:1000));
title('提升db6消噪后的信号');grid;%边界显示效果待处理
1.与小波阈值去噪比较可知:
(1)相同条件下,去噪性能稍好;
(2)计算复杂度降低;
2.母函数阶数不同时,去噪效果无明显变化。