matlab2021a
处理宽带噪声的最通用技术是谱减法,即从带噪语音估值中减去噪声频谱估值,而得到纯净语音的频谱。由于人耳对语音频谱分量的相位不敏感,因而这种方法主要针对短时幅度谱。假定语音为平稳信号,而噪声和语音为加性信号且彼此不相关。此时带噪语音信号可表示为
。
登录后复制
function enhancedsignal=wiener(noisyspeech,samplefrequency)x=noisyspeech;fs=samplefrequency;nx=length(x);enhanced_x=zeros(1,nx); %分帧和加窗FrameLen=fix(0.025*fs); %取25毫秒为一帧overlap=FrameLen/2;inc=FrameLen-overlap; %帧移x_frame=enframe(x,FrameLen,inc); %分帧nf=size(x_frame,1); % 帧数win=hamming(FrameLen)';x_window=[];for k=1:nf x_row=x_frame(k,:).*win; % 加窗 x_window=[x_window;x_row]; end%对带噪语音进行DFTy=fft(x_window');ymag = abs(y); yphase = angle(y); NNoise=23; %取噪音段(语音的初始段)帧数MN=mean(ymag(:,1:NNoise)')';PN=mean(ymag(:,1:NNoise)'.^2)'; %初始噪声功率谱均值NoiseCounter=0;%连续噪声段长度SmoothFactor=9;%噪声平滑因子Alpha=0.95; %语音平滑因子SNRPre=ones(size(MN));%维纳滤波for k=1:nf if k<=NNoise SpeechFlag=0; NoiseCounter=NNoise; else NoiseMargin=3; HangOver=8; SpectralDist= 20*(log10(ymag(:,k))-log10(MN)); SpectralDist(find(SpectralDist<0))=0; Dist=mean(SpectralDist); if (Dist < NoiseMargin) NoiseFlag=1; NoiseCounter=NoiseCounter+1; else NoiseFlag=0; NoiseCounter=0; end if (NoiseCounter > HangOver) SpeechFlag=0; else SpeechFlag=1; end end if SpeechFlag==0 MN=(SmoothFactor*MN+ymag(:,k))/(SmoothFactor+1); %更新噪声均值 PN=(SmoothFactor*PN+(ymag(:,k).^2))/(1+SmoothFactor); %更新噪声功率 end %------滤波SNRNew=(ymag(:,k).^2)./PN-1;SNRPost=Alpha*SNRPre+(1-Alpha).*max(SNRNew,0);Gain=SNRPost./(SNRPost+1);smag=Gain.*ymag(:,k);SNRPre=smag.^2./PN;spectrum= smag.*exp(j*yphase(:,k));enhanced_x((inc*(k-1)+1):(inc*(k-1)+FrameLen))=enhanced_x((inc*(k-1)+1):(inc*(k-1)+FrameLen))+real(ifft(spectrum,FrameLen))';endenhancedsignal=enhanced_x;1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.59.60.61.62.63.64.65.66.67.68.69.70.
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删