Signal quality assessment with SNR in Matlab
22 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
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:
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!