用Matlab语言编写一个语音信号或图象信号去噪的程序?请高手帮忙

用Matlab语言编写一个语音信号或图象信号去噪的程序?请高手帮忙,第1张

不好意思,没看到维纳滤波,程序就不删了

%谱减法语音增强

%输入参数s 语音数据,fs 采样频率,p 下面有说明,共11个,可不输入,有默认值

%“过度减法(oversubtraction)”作减法的时候,保留一小部分原来的背景噪音,用这部分背景噪音来掩盖住音乐噪音的谱峰,从而消除了令人不悦的音乐噪音。

%通过给的参数p,估计噪音,做谱减法。从而消除噪音。

function [ss,po]=specsubm(s,fs,p)

%利用频谱相减(spectral subtraction)增强 [SS,PO]=(S,FS,P)

%

% implementation of spectral subtraction algorithm by R Martin (rather slow)

% algorithm parameters: t* in seconds, f* in Hz, k* dimensionless

% 1: tg = smoothing time constant for signal power estimate (0.04): high=reverberant, low=musical

% 2: ta = smoothing time constant for signal power estimate

%

used in noise estimation (0.1)

% 3: tw = fft window length (will be rounded up to 2^nw samples)

% 4: tm = length of minimum filter (1.5): high=slow response to noise increase, low=distortion

% 5: to = time constant for oversubtraction factor (0.08)

% 6: fo = oversubtraction corner frequency (800): high=distortion, low=musical

% 7: km = number of minimisation buffers to use (4): high=waste memory, low=noise modulation

% 8: ks = oversampling constant (4)

% 9: kn = noise estimate compensation (1.5)

% 10:kf = subtraction floor (0.02): high=noisy, low=musical

% 11:ko = oversubtraction scale factor (4): high=distortion, low=musical

%检查函数的输入参数,如果输入少于三个,po为默认值,po的参数上面有说明

if nargin<3 po=[0.04 0.1 0.032 1.5 0.08 400 4 4 1.5 0.02 4].'else po=pend

ns=length(s)

ts=1/fs

ss=zeros(ns,1)

ni=pow2(nextpow2(fs*po(3)/po(8)))

ti=ni/fs

nw=ni*po(8)

nf=1+floor((ns-nw)/ni)

nm=ceil(fs*po(4)/(ni*po(7)))

win=0.5*hamming(nw+1)/1.08win(end)=[]

zg=exp(-ti/po(1))

za=exp(-ti/po(2))

zo=exp(-ti/po(5))

px=zeros(1+nw/2,1)

pxn=px

os=px

mb=ones(1+nw/2,po(7))*nw/2

im=0

osf=po(11)*(1+(0:nw/2).'*fs/(nw*po(6))).^(-1)

imidx=[13 21]'

x2im=zeros(length(imidx),nf)

osim=x2im

pnim=x2im

pxnim=x2im

qim=x2im

for is=1:nf

idx=(1:nw)+(is-1)*ni

x=rfft(s(idx).*win)

x2=x.*conj(x)

pxn=za*pxn+(1-za)*x2

im=rem(im+1,nm)

if im

mb(:,1)=min(mb(:,1),pxn)

else

mb=[pxn,mb(:,1:po(7)-1)]

end

pn=po(9)*min(mb,[],2)

%os= oversubtraction factor

os=zo*os+(1-zo)*(1+osf.*pn./(pn+pxn))

px=zg*px+(1-zg)*x2

q=max(po(10)*sqrt(pn./x2),1-sqrt(os.*pn./px))

ss(idx)=ss(idx)+irfft(x.*q)

end

if nargout==0

soundsc([sss],fs)

end

x=[-1.58 0.42 0.46 0.78 -0.49 0.59 -1.3 -1.42 -0.16 -1.47 -1.350.36 -0.44 -0.14 1 -0.5 -0.2 -0.06 -0.6 0.42 -1.52 0.51 0.76 -1.50.16 -1.29 -0.65 -1.48 0.6 -1.65 -0.55]

lev=5

wname='db3'

[c,l]=wavedec(x,lev,wname)

sigma=wnoisest(c,l,1)

alpha=2

thr1=wbmpen(c,l,sigma,alpha)

[thr2,nkeep]=wdcbm(c,l,alpha)

xd1=wdencmp('gbl',c,l,wname,lev,thr1,'s',1)

[xd2,cxd,lxd,perf0,perfl2]=wdencmp('lvd',c,l,wname,lev,thr2,'h')

[thr,sorh,keepapp]=ddencmp('den','wv',x)

xd3=wdencmp('gbl',c,l,wname,lev,thr,'s',1)

subplot(411)plot(x)title('原始信号','fontsize',12)

subplot(412)plot(xd1)title('使用penalty阈值降噪后信号','fontsize',12)

subplot(413)plot(xd2)title('使用Birge-Massart阈值降噪后信号','fontsize',12)

subplot(414)plot(xd3)title('使用缺省阈值降噪后信号','fontsize',12)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8153063.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-13
下一篇 2023-04-13

发表评论

登录后才能评论

评论列表(0条)

保存