如何通过对小波系数进行阈值化来重构信号?

时间:2018-09-03 20:24:15

标签: matlab signal-processing threshold adaptive-threshold

我想通过对小波系数进行阈值重构来重构一维音频信号。首先,我读取音频信号并将其标准化。之后,我添加了白色高斯噪声。随后,我计算了分解的最大体积水平。

我使用db2小波对噪声信号进行了多级小波分解,并获得了近似系数和详细系数。对于使用wdencmp的阈值计算,我使用软阈值获得阈值,并将此阈值应用于小波系数。最后,我使用waverec使用新系数重建原始信号。

[x,Fs] = audioread('audio8.wav');   %Read cough sound
sound(x,Fs)
figure
plot(x(1:end,1))
title('Original Cough Sound')
xlabel('Frequency (Hz)')
ylabel('Amplitude')

x = x/abs(max(x));      %Normalization of Cough Sound
normalized_snr = snr(x,Fs);    %SNR of Normalized Cough Sound
figure
plot(x)
title('Normalized Cough Sound')
xlabel('Frequency (Hz)')
ylabel('Amplitude')

gauss_noise = awgn(x,20,'measured');  %Adding White Gaussian Noise 20db
sound(gauss_noise,Fs)
disp(length(gauss_noise))
noisy_snr = snr(gauss_noise,Fs);     %SNR of Noisy Cough Sound
figure
plot(gauss_noise)
title('Noisy Cough Sound')
xlabel('Frequency (Hz)')
ylabel('Amplitude')

level = floor(log2(length(gauss_noise))); %Get the maximum level for decomposition
disp(level)

[c,l] = wavedec(gauss_noise,level,'db2'); %multi level wavelet decomposition
figure
plot(c)
grid on
title('Wavelet Coefficients')

[thr,sorh,keepapp] = ddencmp('den','wv',gauss_noise); %Values for denoising like thr = value of thresholding, sorh = soft/hard thrsholding, keepapp = keep the approximation coefficients as it is.
clean = wdencmp('gbl',c,l,'db2',level,thr,sorh,keepapp); %Denoise the signal
snr_clean = snr(clean,Fs);
sound(clean,Fs)
figure
subplot(211)
plot(x); title('Original Signal');
subplot(212)
plot(clean); title('Denoised Signal After thresholding');

xrec = waverec(c,l,'db2'); %Perform wavelet reconstruction on new coefficients after thresholding 
rec_snr = snr(xrec,Fs);
figure
plot(xrec)
grid on
title('Reconstructed Signal')
sound(xrec,Fs)

我是否以正确的方式将阈值应用于小波系数?重建的信号现在正确吗?

0 个答案:

没有答案