14
$\begingroup$

I am having problems in understanding how to do it practically

I have a wav file that contains pure speech and another ave file that just contains the background noise (can be various things, such as white noise, crowd noise, a recording of blowing wind, etc). These are either purely speech or purely noise. So I suppose I can get an SNR value from them by simple division of corresponding samples (or the average of a frame of samples) in both files. I then combine them in audacity to get a noisy speech file. I am guessing this file will still have the same SNR.

Now I pass this file through my noise reduction program and get another file as a result. How do I calculate the SNR of this "noise reduced" file?

--- EDIT ---

follow-up question posted HERE

$\endgroup$

2 Answers 2

8
$\begingroup$

The common definition of SNR is the power of the wanted signal divided by the noise power. Suppose you have obtained the wanted and the noise signal as arrays, calculation of the SNR in Matlab before noise reduction can be done like this:

snr_before = mean( signal .^ 2 ) / mean( noise .^ 2 );
snr_before_db = 10 * log10( snr_before ) % in dB

After noise reduction, the residual noise can be calculated as the difference of the wanted signal and the actual signal. Calculation of SNR is then straightforward:

residual_noise = signal - noise_reduced_signal; 
snr_after = mean( signal .^ 2 ) / mean( residual_noise .^ 2 ); 
snr_after_db = 10 * log10( snr_after )
$\endgroup$
11
  • 2
    $\begingroup$ signal and noise_reduced_signal has to be time-aligned in your case. $\endgroup$
    – dspGuru
    Commented Nov 2, 2012 at 16:19
  • $\begingroup$ @dspGuru True, I assumed that the noise reduction algorithm doesn't introduce a time delay. $\endgroup$
    – Deve
    Commented Nov 3, 2012 at 13:45
  • $\begingroup$ @DspGuru and Dev: In these places, instead of taking the var and mean of the whole signal, what if I specify some portion of the signal that definitely contains speech? For s\example, replace signal by signal(start_speech:end_speech) in Matlab, since my signal is 5 seconds long with pause between words $\endgroup$
    – user13267
    Commented Nov 8, 2012 at 5:42
  • $\begingroup$ @user13267 Of which signal? Before or after noise reduction? Generally, the longer the signal you analyze the better will be your estimate of the SNR. $\endgroup$
    – Deve
    Commented Nov 8, 2012 at 6:47
  • $\begingroup$ both of them. What I mean is, my sound sample has some one speaking a short sentence so when i open it in audacity I can see the waveform high intensity and low intensity areas (presence of words and silence between words I think). So I just want to select those samples that contain words and not include those samples that contain silence. $\endgroup$
    – user13267
    Commented Nov 8, 2012 at 7:34
3
$\begingroup$

On the input side:

  1. Calculate DB1 = 10*log10(var(noiseSignal))
  2. Calculate DB2 = 10*log10(var(cleanSpeechSignal))

The SNR is = DB2 - DB1

On the output side:

  1. Send the clean speech signal through your noise suppression algo. Denote the output Y1.
  2. Send the noisy speech signal through your noise suppression algo. Denote that output Y2.
  3. Calculate Z = Y2 - Y1
  4. residualNoiseDB = 10 * log10(var(Z))
  5. speechDB = 10*log10(var(Y1))
  6. SNR = speechDB - residualNoiseDB
$\endgroup$
3
  • $\begingroup$ Is it really necessary to pass the clean speech signal through the noise reduction algorithm as well? Shouldn't the speech signal be same before and after the noise reduction algorithm so that we have a common reference point? $\endgroup$
    – user13267
    Commented Nov 8, 2012 at 5:47
  • $\begingroup$ That totally depends on your algorithm. Most likely the output won't match the clean input- due to delay and filtering. $\endgroup$
    – dspGuru
    Commented Nov 14, 2012 at 19:00
  • $\begingroup$ The output (when clean speech is passed through the noise reduction algorithm) does not indeed match the input, but I am quite sure the algorithm does not introduce any delays. Please check my follow up question (the link has been edited into this question). It has the waveforms of clean speech before (top of the figure) noise reduction and after (bottom of the figure) noise reduction. There is no delay but there is very high amplification and some of the speech has been filtered out. $\endgroup$
    – user13267
    Commented Nov 15, 2012 at 0:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.