Signal quality assessment with SNR in Matlab

22 次查看(过去 30 天)
Elzbieta
Elzbieta 2024-11-29,14:50
评论: Elzbieta 2024-12-3,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

回答(1 个)

praguna manvi
praguna manvi 2024-12-3,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 个评论
Elzbieta
Elzbieta 2024-12-3,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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Assessments, Criteria, and Verification 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by