# SNR from sampled signal

Is there any procedure described, or some example code (in Matlab) to calculate SNR from the sampled real signal?

• Not without some underlying assumptions and a lot more detail. The general answer is "no". Commented Jun 30, 2023 at 15:15
• What underlaying assumptions are needed? Commented Jun 30, 2023 at 16:23
• I have a data = [sample_time, values], The sample_time have a constant time step and the sampled values are expected to be a noisy DC signal. Commented Jun 30, 2023 at 16:39
• You need some assumptions about the noise and the signal and how they are different. For example if you already know that this is a DC signal, you can simply calculate the mean and call it "signal" and the subtract the mean from the signal and call it "noise". Commented Jul 1, 2023 at 0:45

If you have a replica "perfect" copy of the signal, I use the procedure of carefully time aligning the signal (depending on the SNR floor required) and then using the correlation coefficient to determine the SNR. I have done this effectively with over 150 dB dynamic range (when such precision required) which requires much more expertise in resampling to properly adjust for time offsets. For lower ranges (SNR's < 40 dB) the process is quite simple and straight forward (Including using the peak of the cross-corrrelation function with the signal sufficiently interpolated to find the local peak which would be the time-aligned correlation coefficient once properly normalized such that infinite SNR corresponds to $$\rho=1$$).

Further details on this approach are provided here:

Computing the normalized correlation coefficient:

https://dsp.stackexchange.com/a/30854/21048

Converting correlation coefficient to SNR:

How can I find SNR, PEAQ, and ODG values by comparing two audios?

If there are both time and frequency offsets:

SNR estimation prior to demodulation?

Alternate approaches that use the spectrum from an FFT to compare the power spectral in band to the noise floor given by the power spectral density out of band are flawed an inaccurate for all cases except for single tone testing as they assume the noise spectrum in band is the same as the noise spectrum out of band. The correlation approach is very robust and includes the effects of noise and all other distortions such as non-linearities, inter-symbol interference, reflections, etc.

Given your additional detail that the sampled values are expected to be a noisy DC signal, you can follow a simple method to compute the SNR.

For a noisy DC signal, the Signal-to-Noise Ratio (SNR) can be calculated as the ratio of the square of the mean of the signal (which is the DC component) to the variance of the signal (which is the noise).

Here is an example Matlab code to compute the SNR:

% Assuming 'data' is your signal
data = [sample_time, values];

% Extract the signal values
signal_values = data(:,2);

% Calculate the DC component (mean of the signal)
dc_component = mean(signal_values);

% Calculate the noise (standard deviation of the signal)
noise = std(signal_values);

% Calculate the SNR in dB
snr = 20*log10(dc_component / noise);


This is a simple way to calculate SNR, but it might not be applicable in all cases, particularly if the signal is not stationary or if there are other sources of noise. For a more robust estimate, you might want to consider applying a periodogram or other spectral estimation method, but those are beyond the scope of this simple example.

Hope this helps!