How filtering works?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi. My project is to filter sine signal with various types of IIR and FIR filter. As starting, I used Lowpass FIR filter using Hamming window. The coding has no error, but to be honest I don't really how DSP works. I don't know whether my choice of sampling frequency/frequency for the filter is correct. And I also don't know if the filter is filtering the frequency of noise or the frequency of the original sine signal. I'm still doing my reading on this but sometimes I ended up sleeping. Can somebody explain how this filtering works? Below is my coding and results.
close all;
%original signal
F = 1000; %frequency of the sine wave
Fs = 8000; %sampling frequency
ts = 1/Fs; %sampling time interval
t = 0:ts:1-ts;
N = length(t) %number of samples
y = sin(2*pi*F*t);
figure,plot(t,y), title('1000Hz sine wave');
YfreqDomain = fft(y);
stem(abs(YfreqDomain)),title('FFT Sine Signal'),grid on;
%noise
noise = 2*randn(size(y));
figure,plot(t,noise);
YfreqDomainNoise = fft(noise);
stem(abs(YfreqDomainNoise)),title('FFT Noise'), grid on;
%noisysignal
noisySignal = y + noise;
figure,plot(t,noisySignal);
YfreqDomainNoisySignal = fft(noisySignal);
stem(abs(YfreqDomainNoisySignal)), title ('FFT Noisy Signal'),grid on;
% Program for the design of Lowpass FIR filter using Hamming window
f=input('Enter the sampling frequency= ');
fp=input('Enter the passband frequency= ');
fs=input('Enter the stopband frequency= ');
rp=input('Enter the passband ripple= ');
rs=input('Enter the stopband ripple= ');
% Normalizing the frequencies
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
%Adjusting the filter order. The order of window must be an odd number
%and the order of filter must be one less than that of the window
if (rem(n,2)~=0)
n1=n;
n=n-1;
end
disp('Filter ordern n= ');n
w=hamming(n1);
%Filter coefficients
b=fir1(n,wp,w);
figure, plot(b); title('Hamming Lowpass FIR Filter Coefficient'),grid on;
%Plotting the filter response
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
figure, plot(o/pi,m);
ylabel('Gain in dB -->'), xlabel('Normalized Frequency -->');
title('Hamming Lowpass FIR Filter Response'), grid on;
%Filter
z=filtfilt(b,1,noisySignal);
figure, plot(z);
fftFilteredSignal = fft(z);
stem(abs(fftFilteredSignal)),title('FFT Filtered Signal'),grid on;
Parameters of the filter:
Enter the sampling frequency= 8000
Enter the passband frequency= 900
Enter the stopband frequency= 1100
Enter the passband ripple= 0.05
Enter the stopband ripple= 0.03
Filter ordern n=
n =
42
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Digital Filter Design에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!