【语音去噪】基于matlab 软阈值+硬阈值+折中阈值语音去噪【含Matlab源码 530期】
作者:互联网
一、简介
二、源代码
clc;
clear;
fs=wavread('C:\Users\lenovo\Desktop\93317443speech-denoising\Ring01.wav');
y=fs(40000:120000);
N=length(y);
figure(1);
subplot(111);
plot(y);
ylabel('幅值 A');
title('原始信号');
s=awgn(y,20,'measured');%加入高斯白噪声
figure(2);
plot(s);
ylabel('幅值 A');
title('加噪信号');
wname='db3';%选db3小波基
lev=5;%5层分解
[c,l]=wavedec(s,lev,wname);
a5=appcoef(c,l,wname,lev);
d5=detcoef(c,l,5);
d4=detcoef(c,l,4);
d3=detcoef(c,l,3);
d2=detcoef(c,l,2);
d1=detcoef(c,l,1);
cD=[d1,d2,d3,d4,d5];
a=8500;b=13;
sigma=median(abs(cD))/3.647
thr1=(sigma*sqrt(2*(log10(N))))/(log10(2));
cD1=wthresh(d1,'s',thr1);
thr2=(sigma*sqrt(2*(log10(N))))/(log10(3));
cD2=wthresh(d2,'s',thr2);
thr3=(sigma*sqrt(2*(log10(N))))/(log10(4));
cD3=wthresh(d3,'s',thr3);
thr4=(sigma*sqrt(2*(log10(N))))/(log10(5));
cD4=wthresh(d4,'s',thr4);
thr5=(sigma*sqrt(2*(log10(N))))/(log10(6));
cD5=wthresh(d5,'s',thr5);
cd=[a5,cD5,cD4,cD3,cD2,cD1];
c=cd;
ys=waverec(c,l,wname);
figure(3);
plot(ys);
title('软阈值处理');
thr1=(sigma*sqrt(2*(log10(N))))/(log10(2));
cD1=wthresh(d1,'h',thr1);
thr2=(sigma*sqrt(2*(log10(N))))/(log10(3));
cD2=wthresh(d2,'h',thr2);
thr3=(sigma*sqrt(2*(log10(N))))/(log10(4));
cD3=wthresh(d3,'h',thr3);
thr4=(sigma*sqrt(2*(log10(N))))/(log10(5));
cD4=wthresh(d4,'h',thr4);
thr5=(sigma*sqrt(2*(log10(N))))/(log10(6));
cD5=wthresh(d5,'h',thr5);
cd=[a5,cD5,cD4,cD3,cD2,cD1];
c=cd;
yh=waverec(c,l,wname);
figure(4);
plot(yh);
title('硬阈值处理');
thr1=(sigma*sqrt(2*(log10(length(d1)))))/(log10(1+1));
for i=1:length(d1)
if(abs(d1(i))>=thr1)
cD1(i)=sign(d1(i))*(abs(d1(i))-b*thr1/(a^(abs(abs(d1(i))-thr1))+b-1));%估计第一层小波系数
else
cD1(i)=0;
end
end
thr2=(sigma*sqrt(2*(log10(length(d2)))))/(log10(2+1));
for i=1:length(d2)
if(abs(d2(i))>=thr2)
cD2(i)=sign(d2(i))*(abs(d2(i))-b*thr2/(a^(abs(abs(d2(i))-thr2))+b-1));%估计第二层小波系数
else
cD2(i)=0;
end
end
thr3=(sigma*sqrt(2*(log10(length(d3)))))/(log10(3+1));
for i=1:length(d3)
if(abs(d3(i))>=thr3)
cD3(i)=sign(d3(i))*(abs(d3(i))-b*thr3/(a^(abs(abs(d3(i))-thr3))+b-1));%估计第三层小波系数
else
cD3(i)=0;
end
end
thr4=(sigma*sqrt(2*(log10(length(d4)))))/(log10(4+1));
for i=1:length(d4)
if(abs(d4(i))>=thr4)
cD4(i)=sign(d4(i))*(abs(d4(i))-b*thr4/(a^(abs(abs(d4(i))-thr4))+b-1));%估计第四层小波系数
else
cD4(i)=0;
end
end
thr5=(sigma*sqrt(2*(log10(length(d5)))))/(log10(5+1));
for i=1:length(d5)
if(abs(d5(i))>=thr5)
cD5(i)=sign(d5(i))*(abs(d5(i))-b*thr5/(a^(abs(abs(d5(i))-thr5))+b-1));%估计第五层小波系数
else
cD5(i)=0;
end
end
%%%%开始重构
cd=[a5,cD5,cD4,cD3,cD2,cD1];
c=cd;
yhs=waverec(cd,l,wname);
figure(5);
plot(ys,'LineWidth',1);
ylabel('幅值 A')
三、运行结果
四、备注
版本:2014a
标签:阈值,log10,sqrt,length,abs,语音,d4,sigma,源码 来源: https://blog.51cto.com/u_15287606/2975946