Sunday, January 26, 2014

On Signal to Noise Ratio (SNR)

A large part of circuit design is about making trade-offs between speed, cost, power consumption and so on while meeting some design specification that can often be traced to Signal to Noise ratio (SNR). Yet, possibly for pedagogical reasons, SNR is often under-emphasized in undergraduate classes. Remember those amplifiers you heard/read about years ago ? This post will demonstrate a canonical application of amplifiers and show you how to measure SNR of a signal captured from an Arduino.

For this demonstration, I hooked up a signal generator to an Arduino powered from 5v. To prevent clipping, the sine wave fed to the Arduino was given an offset of 1.5v. The signal amplitude (Vac) was set to 25 mV, frequency was set to 1 Hz and the sampling rate was 250 Hz with 10 bits per sample. Small mV level signals are commonly found in outputs of sensors such as microphone, ECG, EMG etc. So this 25 mV signal serves as a representative example.



With this setup, I captured 1500 readings from the ADC and plotted them in MATLAB. This is what it looks like.


Lets go ahead and measure SNR of the captured data by plotting its Fourier transform.


I've removed the huge DC value at x=0 from the plot. To the very left, around x=6, there is a big spike, which is the signal. The rest is noise. Let's generously choose the signal bandwidth to be from x=2 to x=8 both inclusive and compute noise from x=150 to x=750 (we could have chosen x=9 to x=750 for calculating noise. The gap between x=8 to x=150 is to ensure that we don't flag signal harmonics as noise). Then,


The factor 1.25 in the denominator came in because the noise is summed from 150 to 750 and then scaled up over the entire range. Computing this gave an SNR value of 4. This seems OK from looking at the time domain waveform. Now, what if we want a better SNR ? Clearly, in our system, the ADC is limiting the SNR because each quantization step in the ADC is 5 mV. One way to improve the SNR is to use an ADC of higher resolution. But ADCs that have higher resolution are often slower and are more expensive (in power, area, cost, board space etc.). What if we wanted to improve SNR with the same ADC ? Since we are forced to accept the same quantization noise, the only way left to improve SNR is to make the signal bigger. That's where amplifiers come in. Let's see what happens when I amplify the 25 mV signal by a factor of about 50 before giving it to the ADC.


With the above setup, I got the following waveform by recording 1500 samples again.


It certainly appears as though SNR has improved. Lets have a look at the Fourier transform.


Even here, its obvious that noise has gone down. Using the same formula as before, the SNR turned out to be about 80.

So, we improved the SNR by amplifying the signal. How far can we go in improving the SNR ? The signal amplification is limited by the power supply. If the gain is too much, the output of the amplifier starts getting clipped. Lets say we've used the maximum gain possible. Is there anything else we can do ? Yes ! Each time an amplifier is added, it adds a certain amount of noise. The net noise added depends on the amplifier itself and the bandwidth. So, SNR can be further improved by restricting the bandwidth and by using a higher quality amplifier. Of course, before doing these things, one has to know how much SNR is "OK" and this depends on what you're trying to do with the digitized signal. After deciding on the acceptable SNR level, one has to measure the SNR and if it needs to be improved, find out where the bottle neck is (amplifier, ADC ?) and then modify the circuit.

Is there anything that can be done to improve SNR in the digital domain after recordings have been made ? Indeed ! Since the sampling rate was 250 Hz, the maximum signal bandwidth is 125 Hz. Suppose we knew that the signals of interest are only in the range 0-5 Hz, we can apply a digital filter to remove everything (especially noise) above 5 Hz. I've filtered the earlier recording (the one taken without the amplifier and which had an SNR of about 4). This is what it looks like after filtering.



It appears considerably improved. What is the SNR of the filtered signal ? We can't find this out easily from the Fourier transform of the filtered signal ! Thats because we applied a filter to remove noise outside the desired bandwidth. There is still noise in the desired bandwidth. But the signal is there too ! This makes estimating noise from the filtered a difficult task. But, since we applied a digital filter to remove everything beyond 5 Hz, whatever noise below 5 Hz that was in the signal before filtering will be the same even after filtering. And this can be estimated from the original un-filtered signal. It is 30/750 of the noise power (denominator term in SNR) calculated before (earlier we scaled noise power in the range 150-750 to 0-750 with the scaling factor 1.25. Now we are scaling from 0-750 to 0-30. This scaling works only because noise is assumed to be white). Thus, by filtering, SNR improves from 4 to 20.

No comments:

Post a Comment