15

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

user13267
  • 501
  • 1
  • 5
  • 20

2 Answers2

9

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 )
Deve
  • 4,031
  • 15
  • 26
  • 2
    signal and noise_reduced_signal has to be time-aligned in your case. – dspGuru Nov 02 '12 at 16:19
  • @dspGuru True, I assumed that the noise reduction algorithm doesn't introduce a time delay. – Deve Nov 03 '12 at 13:45
  • @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 – user13267 Nov 08 '12 at 05:42
  • @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. – Deve Nov 08 '12 at 06:47
  • 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. – user13267 Nov 08 '12 at 07:34
  • @user13267 What do you want to achieve by this? Your SNR would most likely increase because the average power of the signal would be higher while the noise power should be the same over the whole signal. It really depends on your point of view if this is a fair SNR estimation or not. – Deve Nov 08 '12 at 08:59
  • actually it's less now it's confusing me. And in audacity the new nose reduced waveform have higher amplitude, but on calculation the SNR is lesser – user13267 Nov 08 '12 at 11:48
  • @user13267 If the SNR after noise reduction is less than before it's a good thing, I guess ;) – Deve Nov 08 '12 at 12:03
  • I'm sorry? Shouldn't it be more? it's signal to noise right? So it being more means signal is stronger isn't it? – user13267 Nov 08 '12 at 12:24
  • @user13267 Ehrm, you're right, sorry. But I think we shouldn't discuss all this in the comments. You can edit and extend your question or ask a new question. – Deve Nov 08 '12 at 12:26
  • Look up segmented SNR – dspGuru Nov 14 '12 at 19:16
4

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
dspGuru
  • 146
  • 1
  • 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? – user13267 Nov 08 '12 at 05:47
  • That totally depends on your algorithm. Most likely the output won't match the clean input- due to delay and filtering. – dspGuru Nov 14 '12 at 19:00
  • 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. – user13267 Nov 15 '12 at 00:10