Signal quality assessment with SNR in Matlab

22 views (last 30 days)
Elzbieta
Elzbieta on 29 Nov 2024 at 14:50
Commented: Elzbieta on 3 Dec 2024 at 17:33
Hello,
I am trying to assess the quaity of signal with SNR procedure. I have been trying do that with Matlab function snr and the following procedure however they are giving different results. Which of them is correct? If any what is the right approach?
function [SNR] = calc_snr(data, Fs)
% SNR Calculation - Method 1
n = detrend(data(:,1)); % first step remove large DC offset
% Calculate FFT suing the embedded FFT algorithm
N = fft(n);
spect = 2*abs(N)/length(N);
%N is (likely) complex-valued. spect takes abs(N) so it contains only real non-negative values.
PN = spect.^2;
% the square of real non-negative values is real and non-negative.
PS_coeff = PN;
PS = PS_coeff;
%PS_coeff is not used later in the code, but PS is used. If we assume that the actual code assigns to PS instead of to PS_coeff then we can continue analyzing.
df = Fs/length(n);
Pnoise=sum(PS(1:round(0.67/df)))/round(0.67/df) + sum(PS(1+round(150/df):end))/(round(500/df)-(1+round(150/df))) + PS(round(50/df));
Psignal=sum(PS(1+round(0.67/df):1+round(149/df)));
SNR=10*log10(Psignal/Pnoise);
end %function
regards

Answers (1)

praguna manvi
praguna manvi on 3 Dec 2024 at 17:09
Refer to the following useful discussion that compares this "snr" function's implementation with the built-in function. The analysis points to potential issues with the computation of "df," the use of "mean" instead of "sum," and other aspects:
  1 Comment
Elzbieta
Elzbieta on 3 Dec 2024 at 17:33
Hi, I used this function and Matlab snr built-in function and they give different results. Which of them is valid and when to use each of them? What are the basic assumptions and theory behind the mentioned by you implemented snr function? Is it valid for sure?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!