필터 지우기
필터 지우기

How to calculate SNR before and after filtering in Matlab?

조회 수: 5 (최근 30일)
Nur Fauzira Saidin
Nur Fauzira Saidin 2015년 11월 29일
답변: Walter Roberson 2015년 11월 30일
Hi. I have this noisy signal and I want to calculate its SNR before and after filtering process. Please help me!!
f1=50;
f2=100;
fsampling=1000;
fn1_normfreq=0.4;
fn2_normfreq=0.5;
x1 = cos(2*pi*f1*[0:1/fsampling:1.23]);
x2 = cos(2*pi*f2*[0:1/fsampling:1.23]);
x = x1 + x2;
x(end) = [];
[b,a] = butter(2,[fn1_normfreq fn2_normfreq],'bandpass');
filtered_noise = filter(b,a,randn(1, length(x)*2));
noise = 0.5*filtered_noise(500:500+length(x)-1);
y = (x + noise)/length(x)*2; %noisy signal
%Lowpass FIR filter using rectangular window
fp=300;
fs=400;
rp=0.005;
rs=0.1;
% Normalizing the frequencies
wp=2*fp/fsampling;
ws=2*fs/fsampling;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/fsampling;
n=ceil(num/dem);
n1=n+1;
if (rem(n,2)~=0)
n1=n;
n=n-1;
end
w=rectwin(n1);
b=fir1(n,wp,'high',w);%Filter coefficients
%filtering
Y_filtered=filtfilt(b,1,y); %filtered signal

답변 (1개)

Walter Roberson
Walter Roberson 2015년 11월 30일
A signal in isolation must always be considered to be a perfect signal, noiseless. You can only calculate SNR if you have at least two signals (one of which might be the constant signal, all 0, if you know that the other signal consists entirely of noise.)

카테고리

Help CenterFile Exchange에서 Digital and Analog Filters에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by