Determining Signal to Noise Ratio

206 Ansichten (letzte 30 Tage)
M
M am 9 Sep. 2023
Kommentiert: Image Analyst am 11 Sep. 2023
Hi everyone,
I would like to determine the Signal to Noise Ration for an electrical signal, which was already amplified. I have multiple input channels, which experience noise and sometimes a real signal, which is easily visible with the naked eye. My Input arguments are x (Voltage) and y (time). My goal is to determine the SNR accurately for all channels, to compare their SNR and performance.
I have tried using the snr-function in MATLAB in two ways:
  1. r = snr(x): I'm not sure if this is correct for my application since this function is meant for a "real-valued sinusoidal input signal x", which I´m not certain my signal is. Also, channels which just experience noise somehow have a higher SNR than channels with visible peaks when I use this formula.
  2. r = snr(xi,y): I manually estimated the noise y (not to be confused with time, I just copied the definition from MATLAB), for the upper example about 0.004. The problem is the exact same as before, channels with just noise have a higher SNR than others. Also for some reason it does not matter what I input as noise, the result from the snr-function always stays the same.
One last question: Can a channel which does not record a valuable signal, just noise, even posses a SNR? Maybe thats part of my mistake.
I know I´m doing something wrong or I´m missing something, any help would be greatly appreciated!
  1 Kommentar
Paul
Paul am 9 Sep. 2023
I don't fully understand snr. Example straight from that doc page:
rng(100);
fs = 48e3;
t = 0:1/fs:1-1/fs;
A = 1.0;
powfund = A^2/2;
a = 0.4;
powharm = a^2/2;
s = 0.1;
varnoise = s^2;
x = A*cos(2*pi*1000*t) + ...
a*sin(2*pi*2000*t) + s*randn(size(t));
defSNR = 10*log10(powfund/varnoise)
defSNR = 16.9897
figure
snr(x)
ans = 17.0130
copyobj(gca,figure)
xlim([0 50])
If the sampling frequency is 48 kHz, how can the frequency axis go out to 500 megaHz?
Why is the fundamental shown at 21 mHz, as opposed to 1 kHz?
Why is the noise power shown at around -60 dB? Shouldn't it be around
10*log10(varnoise)
ans = -20
which would then result in the expected (and shown) snr of 17 dB, because the power in the fundamental is
10*log10(powfund)
ans = -3.0103
Can anyone clarify ...

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Star Strider
Star Strider am 9 Sep. 2023
Calculating SNR can be difficult if the underlying signal is unknown. An extended discussion is in the Analyzing Harmonic Distortion documentation section.
A sort of ‘hack’ I sometimes use involves first computing the fft of the signal to see what its frequency content is. After that, since broadband noise is not completely eliminated by frequency-selective filters, I use the Savitzky-Golay filter (the sgolayfilt function) to eliminate as much of the broadband noise as I can. (It operates as a sort of FIR filter with multiple attenuation frequencies.) I then subtract that result from the original signal, calculate the noise power, and the ‘filtered’ signal poweor, and be done with it.
With respect to the ‘sinusoidal signal’ requirement, as a general rule, any periodic signal can be expressed as a sum or sinusoids of varying frequency and phase (this underlies the assumptions of the Fourier transform), so that may be enough.
I usually work with physiologic signals that are nonlinear and nonstationary, so always challenging. If there is some sort of magickal procedure that will always produce a robust and correct result for SNR, I have thus far not discovered it.
I am not certain that this answers your question, so if it does not, I will delete it.
  4 Kommentare
M
M am 10 Sep. 2023
I implemented the changes and it works very well by now, my SNR is as between 5.5-6.5 on average, and behaves the way I hoped it would across channels.
Thank you for your help Star Strider!
Star Strider
Star Strider am 10 Sep. 2023
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Image Analyst
Image Analyst am 9 Sep. 2023
You need to smooth the data somehow, like with movmean, movmedian, or sgolayfilt. Then once you have the "noise free signal, you can subtract and get some stats on it.
smoothSignal = movmean(signal, 9);
noiseOnly = signal - smoothSignal; % A vector
snrSignal = signal / abs(noiseOnly);
meanNoise = mean(noiseOnly); % Or use rms function.
meanSNR = mean(snrSignal);
or something similar.
  7 Kommentare
M
M am 10 Sep. 2023
Thanks, I managed to get rid of the problem, but my SNR was still all over the place using this method, so I`ll stick to the other one for now.
Nonetheless thanks for your help Image Analyst!
Image Analyst
Image Analyst am 11 Sep. 2023
OK, no problem. Though the "other method" was also my method. There are several ways to smooth the data and Star and I both suggested sgolayfilt to smooth the data to get an estimate of the "noise-free" data, and then subtracting that from the signal to get an estimate of only the noise. Then compute the SNR from the ratio of the noise-free signal to the noise-only signal.

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by