# How to calculate signal to noise ratio (SNR) from a list (sequence) of amplitude?

Suppose I have a list of amplitude (straight line signal):

x = [1,1,1,0,1,1,1,1]


By intuition, zero value in list x makes the noise of straight signal.

If we modified some value, such as 2, we get more noise level.

y = [1,1,1,0,1,2,1,1]


Hence by my intuition, SNR of list x is greater than SNR of list y.

So how do I calculate SNR from a list?

I know that formula of SNR basically if signal amplitude is voltage.

SNR = 20*log(S_i/N_i)


Where S_i is value of a list signal in an index.

But I have no idea how to get N_i.

Assume we are using volt unit.

I expect I can compute SNR programmatically from scratch without any external library with python.

$$SNR = 10 * log((\sum_{i=0}^{N-1} s(i)^2) / (\sum_{i=0}^{N-1} n(i)^2))$$

Where $$N$$ is the length of the signal, $$s(i)$$ is signal amplitudes/magnitude and $$n(i)$$ is noise amplitude/magnitude.

In Your case the summation of noise signal for y is 2 and that of x is 1 hence SNR of x is more than y.

In your case where You are defining the signal to be "straight signal", the original signal can be considered as $$[1, 1, 1, 1, 1, 1, 1, 1]$$. Let's call this X

noise in signal $$n_x = X - x = [0, 0, 0, 1, 0, 0, 0, 0]$$

and

noise in signal $$n_y = X - y = [0, 0, 0, 1, 0, -1, 0, 0]$$

• Do I need to normalize the data, it seems you normalize to 0. Mar 21 at 14:00
• Normalization was not applied on the signal. Mar 22 at 5:19