# Calculation of SNR

I have implemented RLS algorithm using adaptive filter on TMS320C6713 DSK.I want to calculate the signal to noise ratio.

In this forum I found a method that I should input a speech signal with a silence portions in between. From the output of the adaptive filter I took sample of the silence considering it as a residual noise and the speech part considering it as (speech+ residual noise).

And then calculated SNR in MATLAB as follows:

snr=mse(output_speech)-mse(residual_noise)/mse(residual_noise);
snr_db=10*log10(snr);


If I calculate using this formula I get $40\textrm{ dB}$ improvement.Is this a correct way to calculate SNR?

Second method that I found on this forum was:

residual_noise = mse(output)-mse(input_speech);
snr_after = mse(speech) /residual_noise;
snr_after_db = 10 * log10( snr_after);


with the second method I had to normalize the two signals. I made the max amplitude of both signals look same using MATLAB:

output=output*(max(input)/max(output));


Is this a corect way to normalize it? Using this normalization and formula I got SNR improvement of $10\textrm{ dB}$.

I aligned the signal using MATLAB's scorer function, but still I see some misalignment.

I am really confused which method to use and how can I verify it. Kindly please help.

I have a suggestion for you.

1. Compute the mean power of the signal at the input of the filter without any signal applied at the input. You should only receive noise. This will be the noise power $P_{N}$.
2. Compute the mean power of the signal at the input of your filter when you apply your signal. You should have there your signal plus noise. Then, this will be the power of your signal plus noise $P_{S+N}$.
3. Compute your signal power by $P_{S} = P_{S+N} - P_{N}$.
4. Compute the ratio $SNR = P_{S}/P_{N}$ and convert to dB if necessary.

It is very similar to the first method that you exposed. In your method, I have not understood the meaning of mse, but if is the mean squared error, you need to take care. The correct way to compute the power of a signal $x$ from $N$ samples is:

$$P_{x} = \frac{1}{N} \sum_{n=0}^{N-1} |x(n)|^{2}$$

• Ok,I will correct the formula .I have tried this method earlier and got an improvement of 40 dB.But I was confused if I can apply this method for adaptive filters cause the filter characteristics are different when only input signal is applied and when only noise signal is applied.If I give only the speech,the output of the adaptive filter y(n) is zero.So the filter characterstics are totally different in both cases(with speech signal and with noise signal ).Am I wrong anywhere ? – Abhishek Vazrekar Aug 11 '16 at 14:51
• In youir code, you should use: snr=(mse(output_speech)-mse(residual_noise))/mse(residual_noise); so that not only the second term is divided. – JohnMarvin Aug 11 '16 at 22:58
• Do you only have access to the signal in the output of the filter? Don't you have access to the signal at the input of the filter? You should make this measurements at the input of your filter. I updated my answer explaining this better. – JohnMarvin Aug 11 '16 at 23:06
• I have acess to all input signals(speech and noise).I researched many papers none of them have mentioned this method of finding residual_noise.I need a reference before putting down in my paper.Can you please help me with that.One more thing why calculation of snr fail in 1st method.Even if I align them manually still problem exists. – Abhishek Vazrekar Aug 12 '16 at 14:41
• The method I mentioned is to calculate SNR, not the residual noise. You did not mention that you wanted to find the residual noise. For SNR, there is no problem if your signals are not aligned. – JohnMarvin Aug 12 '16 at 21:02