|
本帖最后由 wuming123 于 2019-7-21 17:20 编辑
请老师帮我看一下,为什么我的小波去噪程序把有用的信号去掉了结果噪声确没怎么去掉?
程序:
clear all;
close all;
clc
m=audioread('C:\Users\张大少爷\Desktop\2.wav'); % 读入数据文件
s=m';
%整个信号的长度
N = numel(s);
%小波分解;
[c,l]=wavedec(s,7,'db5'); %小波基为db2,分解层数为7层
ca11=appcoef(c,l,'db5',7); %获取低频信号
cd1=detcoef(c,l,1);
cd2=detcoef(c,l,2); %获取高频细节
cd3=detcoef(c,l,3);
cd4=detcoef(c,l,4);
cd5=detcoef(c,l,5);
cd6=detcoef(c,l,6);
cd7=detcoef(c,l,7);
% cd8=detcoef(c,l,8);
%对信号进行强制去噪
sd1=zeros(1,length(cd1));
sd2=zeros(1,length(cd2)); %1-3层置0,4-7层用软阈值函数处理
sd3=zeros(1,length(cd3));
sd4=zeros(1,length(cd4));
sd5=zeros(1,length(cd5));
sd6=zeros(1,length(cd6));
sd7=zeros(1,length(cd7));
% sd8=zeros(1,length(cd8));
c1=[ca11 sd7,sd6,sd5,sd4,sd3,sd2,sd1];
s0=waverec(c1,l,'db5'); %小波重构
%默认阈值去噪
[thr,sorh,keepapp]=ddencmp('den','wv',s);
s1=wdencmp('gbl',c,l,'db5',7 ,thr,sorh,keepapp);
%软阈值去噪
%用给定的软阈值进行去噪处理
thr1=thselect(cd1,'rigrsure')%获取阈值,使用Stein的无偏风险估计原理
thr2=thselect(cd2,'rigrsure')
thr3=thselect(cd3,'rigrsure')
thr4=thselect(cd4,'rigrsure')%获取阈值,使用Stein的无偏风险估计原理
thr5=thselect(cd5,'rigrsure')
thr6=thselect(cd6,'rigrsure')
thr7=thselect(cd7,'rigrsure')
% thr8=thselect(cd8,'rigrsure')
cd1soft=wthresh(cd1,'s',thr1);
cd2soft=wthresh(cd2,'s',thr2);
cd3soft=wthresh(cd3,'s',thr3);
cd4soft=wthresh(cd4,'s',thr4);
cd5soft=wthresh(cd5,'s',thr5);
cd6soft=wthresh(cd6,'s',thr6);
cd7soft=wthresh(cd7,'s',thr7);
% cd8soft=wthresh(cd8,'s',thr8);
c3=[ca11 cd7soft cd6soft cd5soft cd4soft cd3soft cd2soft cd1soft];
s2=waverec(c3,l,'db5');
%用给定的硬阈值进行去噪处理
cd1hard=wthresh(cd1,'h',thr1);
cd2hard=wthresh(cd2,'h',thr2);
cd3hard=wthresh(cd3,'h',thr3);
cd4hard=wthresh(cd4,'h',thr4);
cd5hard=wthresh(cd5,'h',thr5);
cd6hard=wthresh(cd6,'h',thr6);
cd7hard=wthresh(cd7,'h',thr7);
% cd8hard=wthresh(cd8,'h',thr8);
% ca1=zero(1:length(ca11);
c4=[ca11 cd7hard cd6hard cd5hard cd4hard cd3hard cd2hard cd1hard];
s3=waverec(c4,l,'db5');
figure;
subplot(321);plot(s),title('原图');subplot(322);plot(s0),title('强制去噪');subplot(323);plot(s1),title('默认阈值去噪');
subplot(324);plot(s2),title('软阈值去噪'); subplot(325);plot(s3),title('硬阈值去噪'); %画图
|
|