[Speech denoising] based on matlab wavelet hard threshold speech denoising [including Matlab source code 532]

1. Introduction

Under normal circumstances, the signals we collect from the equipment have certain noise. In most cases, this noise can be regarded as Gaussian white noise. Signal contaminated by noise = clean signal + noise.

Why use threshold: Because the signal has a certain degree of continuity in space (or time domain), in the wavelet domain, the wavelet coefficients generated by effective signals tend to have larger modulus values; while Gaussian white noise is spatially (or Time domain) has no continuity, so the noise after wavelet transformation still shows strong randomness at the wavelet threshold, which is usually considered to be Gaussian white noise. Then we get such a conclusion: In the wavelet domain, the coefficient corresponding to the effective signal is very large, and the coefficient corresponding to the noise is very small. As I just said, the coefficients corresponding to noise in the wavelet domain still satisfy the Gaussian white noise distribution. If in the wavelet domain, the variance corresponding to the wavelet coefficients of the noise is sigma, then according to the characteristics of the Gaussian distribution, the vast majority (99.99%) of the noise coefficients are in the interval [-3sigma, 3sigma] (Chebyshev's inequality, 3sigma criterion) . Therefore, as long as the coefficients in the interval [-3sigma, 3sigma] are set to zero (this is the function of the commonly used hard threshold function), the noise can be suppressed to the greatest extent, while only slightly damaging the effective signal. The wavelet coefficients after threshold processing are reconstructed, and the denoised signal can be obtained. The commonly used soft threshold function is to solve the "one size fits all" impact of the hard threshold function (the wavelet coefficients with a modulus less than 3sigma are all removed, and all the coefficients greater than 3sigma are retained, which will inevitably produce abrupt changes in the wavelet domain, resulting in local jitter after denoising. , Similar to the frequency domain step in the Fourier transform will produce a tail in the time domain). The soft threshold function sets all wavelet coefficients with modulus less than 3sigma to zero, and takes a special treatment for those with modulus greater than 3sigma. Wavelet coefficients greater than 3sigma are subtracted from 3sigma, and wavelet coefficients less than -3sigma are uniformly added to 3sigma. After the soft threshold function, the wavelet coefficients are smoother in the wavelet domain, so the image obtained by denoising with soft threshold looks smooth, similar to looking outside through a window in winter, like a layer of fog on the image of.

Compare hard threshold function denoising and soft threshold function denoising: the peak signal-to-noise ratio (PSNR) obtained by hard threshold function denoising is higher, but there is a phenomenon of local jitter; the PSNR obtained by soft threshold function denoising is not as good as the hard threshold The function denoises, but the result looks smooth. The reason is that the soft threshold function has carried out a large "socialist transformation" on the wavelet coefficients, and the wavelet coefficients have changed greatly. Therefore, a variety of threshold functions have appeared, the purpose of which I think is to keep the large coefficients while the small coefficients are eliminated, and the transition of the coefficients in the wavelet domain should be smooth.
How to estimate the noise variance sigma in the wavelet domain is very simple: do a wavelet transform on the signal, and use robust estimator in each subband to estimate it (the variance of the high frequency band and the low frequency band may be different). The robust estimator is to arrange the wavelet coefficient modules in the subband according to the size, then take the middle one, and then divide the middle one by 0.6745 to get the variance sigma of the noise in a certain subband. Using this sigma, and then selecting a threshold function, you can denoise, and there is an implementation api available in matlab.
Insert picture description here
Approximation and details are often used in wavelet analysis, which approximately represents the high-scale of the signal, that is, low-frequency information; details represent the low-scale of the signal, that is, high-frequency information. For noisy signals, the main energy of the noise component is concentrated in the detail component of the wavelet solution.
In the above process, the selection of wavelet basis and the number of decomposition layers, the selection rules of the threshold, and the design of the threshold function are all key factors that affect the final denoising effect.
After determining the threshold threshold of Gaussian white noise in the wavelet coefficients (domain), a threshold function is needed to filter the wavelet coefficients with noise coefficients to remove Gaussian noise coefficients. Commonly used threshold functions include soft threshold and hard threshold methods. Many literature papers also have a lot of improvements and optimizations in the threshold function.
Insert picture description here

Second, the source code

clear all; clc; close all;

[xx, fs] = wavread('C5_4_y.wav');           % 读入数据文件
xx=xx-mean(xx);                         % 消除直流分量
x=xx/max(abs(xx));                      % 幅值归一化
N=length(x);
%-------------------------加入指定强度的噪声---------------------------------
SNR=5;
s=awgn(x,SNR,'measured','db');               % 叠加噪声
wname='db7';

jN=6;  %分解的层数
snrs=20*log10(norm(x)/norm(s-x));
signal=Wavelet_Hard(s,jN,wname);
signal=signal/max(abs(signal));
snr1=SNR_Calc(x,s);            % 计算初始信噪比
snr2=SNR_Calc(x,signal);            % 计算降噪后的信噪比
snr=snr2-snr1;
fprintf('snr1=%5.4f   snr2=%5.4f   snr=%5.4f\n',snr1,snr2,snr);
% 作图
time=(0:N-1)/fs;                        % 设置时间
subplot 311; plot(time,x,'k'); grid; axis tight;
title('纯语音波形'); ylabel('幅值')
subplot 312; plot(time,s,'k'); grid; axis tight;
%小波硬阈值函数
function signal=Wavelet_Hard(s,jN,wname)
[c,l]=wavedec(s,jN,wname);
%高频分量的索引
first = cumsum(l)+1;
first1=first;
first = first(end-2:-1:1);
ld   = l(end-1:-1:2);
last = first+ld-1;
%--------------------------------------------------------------------------
%硬阈值
cxdhard=c;
for j=1:jN                                      %j是分解尺度
    flk = first(j):last(j);                      %flk是di在c中的索引
    thr(j)=sqrt(2*log((j+1)/j))*median(c(flk))/0.6745;
    for k=0:(length(flk)-1)                 %k是位移尺度
        djk2=c(first(j)+k);
        absdjk=abs(djk2);
        thr1=thr(j);
        %阈值处理
       if absdjk<thr1
           djk2=0;
       end 

Three, running results

Insert picture description here

Four, remarks

Complete code or writing add QQ 1564658423 past review
>>>>>>
[Feature extraction] Audio watermark embedding and extraction based on matlab wavelet transform [Include Matlab source code 053]
[Speech processing] Voice signal processing based on matlab GUI [Include Matlab Source code issue 290]
[Voice acquisition] based on matlab GUI voice signal collection [including Matlab source code 291]
[Voice modulation] based on matlab GUI voice amplitude modulation [including Matlab source code 292]
[Speech synthesis] based on matlab GUI voice synthesis [including Matlab Source code issue 293]
[Voice encryption] Voice signal encryption and decryption based on matlab GUI [With Matlab source code 295]
[Speech enhancement] Matlab wavelet transform-based voice enhancement [Matlab source code 296]
[Voice recognition] Based on matlab GUI voice base frequency Recognition [Including Matlab source code 294]
[Speech enhancement] Matlab GUI Wiener filtering based voice enhancement [Including Matlab source code 298]
[Speech processing] Based on matlab GUI voice signal processing [Including Matlab source code 299]
[Signal processing] Based on Matlab speech signal spectrum analyzer [including Matlab source code 325]
[Modulation signal] Digital modulation signal simulation based on matlab GUI [including Matlab source code 336]
[Emotion recognition] Voice emotion recognition based on matlab BP neural network [including Matlab source code 349 Issue]
[Voice Steganography] Quantified Audio Digital Watermarking Based on Matlab Wavelet Transform [Include Matlab Source Code Issue 351]
[Feature extraction] based on matlab audio watermark embedding and extraction [including Matlab source code 350 period]
[speech denoising] based on matlab low pass and adaptive filter denoising [including Matlab source code 352 period]
[emotion recognition] based on matlab GUI voice emotion classification Recognition [Including Matlab source code 354 period]
[Basic processing] Matlab-based speech signal preprocessing [Including Matlab source code 364 period]
[Speech recognition] Matlab Fourier transform 0-9 digital speech recognition [Including Matlab source code 384 period]
[Speech Recognition] 0-9 digital speech recognition based on matlab GUI DTW [including Matlab source code 385]
[Voice playback] Matlab GUI MP3 design [including Matlab source code 425]
[Voice processing] Speech enhancement algorithm based on human ear masking effect Noise ratio calculation [Including Matlab source code 428]
[Speech denoising] Based on matlab spectral subtraction denoising [Including Matlab source code 429]
[Speech recognition] BP neural network speech recognition based on the momentum item of matlab [Including Matlab source code 430]
[Voice steganography] based on matlab LSB voice hiding [including Matlab source code 431]
[Voice recognition] based on matlab male and female voice recognition [including Matlab source code 452]
[Voice processing] based on matlab voice noise adding and noise reduction processing [including Matlab source code Issue 473]
[Speech denoising] based on matlab least squares (LMS) adaptive filter [including Matlab source code 481]
[Speech enhancement] based on matlab spectral subtraction, least mean square and Wiener filter speech enhancement [including Matlab source code 482 period】
[Communication] based on matlab GUI digital frequency band (ASK, PSK, QAM) modulation simulation [including Matlab source code 483]
[Signal processing] based on matlab ECG signal processing [including Matlab source code 484]
[Voice broadcast] based on matlab voice Broadcast [Including Matlab source code 507]
[Signal processing] Matlab wavelet transform based on EEG signal feature extraction [Including Matlab source code 511]
[Voice processing] Based on matlab GUI dual tone multi-frequency (DTMF) signal detection [Including Matlab source code 512 】
【Voice steganography】based on matlab LSB to realize the digital watermark of speech signal 【Include Matlab source code 513】
【Speech enhancement】Speech recognition based on matlab matched filter 【Include Matlab source code 514】
【Speech processing】Based on matlab GUI voice Frequency domain spectrogram analysis [including Matlab source code 527]
[Speech denoising] based on matlab LMS, RLS algorithm voice denoising [including Matlab source code 528]
[Voice denoising] based on matlab LMS spectral subtraction voice denoising [including Matlab Source code issue 529]
[Voice denoising] based on matlab soft threshold, hard threshold, compromise threshold voice denoising [including Matlab source code 530]
[Voice recognition] based on matlab specific person's voice recognition discrimination [including Matlab source code 534]
[ Speech denoising] based on matlab wavelet soft threshold speech denoising [including Matlab source code 531]

Guess you like

Origin blog.csdn.net/TIQCmatlab/article/details/114876490