필터 지우기
필터 지우기

How to calculate SNR using Matlab?

조회 수: 17 (최근 30일)
Nur Fauzira Saidin
Nur Fauzira Saidin 2015년 11월 14일
댓글: PRANAV BIBRA 2022년 1월 3일
Hi. I want to calculate SNR of the noisy signal and the filtered signal. I used this following code but I am not sure whether the result is correct or not. Can somebody help me?
%generate the noisy signal which will be filtered
x= cos(2*pi*12*[0:0.001:1.23]);
x(end) = [];
[b,a] = butter(2,[0.6 0.7],'bandpass');
filtered_noise = filter(b,a,randn(1, length(x)*2));
y = (x + 0.5*filtered_noise(500:500+length(x)-1))/length(x)*2;
%Use matlabs built-in buttord function to get the optimum order to meet a specification
[N,Wn] = buttord(0.1, 0.5, 5, 40)
%use the N and Wn values obtained above to design the filter in the usual way
[b,a] = butter(N, Wn, 'low');
%filter the signal and plot the ouput of the filter
Y_filtered = filter(b,a,y);
%calculation of snr before filtering
snr_before = mean(x.^2) / mean(filtered_noise.^2);
snr_before_db = 10 * log10(snr_before) % in dB
%calculation of snr after filtering
residual_noise = x - Y_filtered;
snr_after = mean(x.^2) / mean(residual_noise.^2);
snr_after_db = 10 * log10(snr_after)
Result that I got is:
snr_before_db =
6.8725
snr_after_db =
0.0132

답변 (0개)

카테고리

Help CenterFile Exchange에서 Digital Filter Analysis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by