小波变换3级分解Mallat图:
将带噪语音作为输入信号进行逐级DWT小波分解,并将分解出的低频成分
c
A
3
cA_3
cA3?
与强制置零后的高频成分
c
D
3
cD_3
cD3?,
c
D
2
cD_2
cD2?,
c
D
1
cD_1
cD1?进行小波重构。
Demo:
clc,clear
[x,Fs]= audioread('MUsic_Test.wav');
snr = 5; %设定信噪比,单位db
noise = randn(size(x)); % 用randn函数产生高斯白噪声
Nx = length(x); % 求出信号x长
signal_power = 1/Nx*sum(x.*x); % 求出信号的平均能量
noise_power = 1/Nx*sum(noise.*noise); % 求出噪声的能量
noise_variance = signal_power / ( 10^(snr/10) ); % 计算出噪声设定的方差值
noise = sqrt(noise_variance/noise_power)*noise; % 按噪声的平均能量构成相应的白噪声
y = x + noise; % 合成带噪语音
[c,l]=wavedec(y,3,'db4');
ca3=appcoef(c,l,'db4',3)';
cd3=detcoef(c,l,3);
cd2=detcoef(c,l,2);
cd1=detcoef(c,l,1);
cdd3=zeros(1,length(cd3));
cdd2=zeros(1,length(cd2));
cdd1=zeros(1,length(cd1));
c1=[ca3,cdd3,cdd2,cdd1];
s2=waverec(c1,l,'db4');
[thrl,sorh,keepapp]=ddencmp('den','wv',y);
% s2=wdencmp('gbl',c,l,'db4',4,thrl,sorh,keepapp);
%绘图
windowLength = 256; %帧长,语谱图参数
win = hamming(windowLength,'periodic'); %窗口函数(汉明窗)
overlap = 128; %帧移(一般为帧长的一半)
ffTLength = windowLength; %做DFT的点数,一般和帧长一样
subplot(3,2,1)
plot(x)
subplot(3,2,2)
spectrogram(x,win,overlap,ffTLength,Fs,'yaxis')
subplot(3,2,3)
plot(y)
subplot(3,2,4)
spectrogram(y,win,overlap,ffTLength,Fs,'yaxis');
subplot(3,2,5)
plot(s2);
subplot(3,2,6)
spectrogram(s2,win,overlap,ffTLength,Fs,'yaxis');
sound(s2,Fs)
signal_power = sum(abs(x').^2)/length(x');
noise_Power0 = sum(abs(y'-x').^2)/length(y'-x');
SNR0 = 10*log10(signal_power/noise_Power0);
disp(['带噪音频信噪比:',num2str(SNR0)])
noise_Power2 = sum(abs(s2-x').^2)/length(s2-x'); %(带噪信号-纯信号)的平方
SNR = 10*log10(signal_power/noise_Power2);
disp(['强制消噪后信噪比:',num2str(SNR)])
结果:
带噪音频信噪比:5(单位dB) 强制消噪后信噪比:7.9071
|