2

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

我使用小波对噪声信号进行了多级小波分解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)

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

4

0 回答 0