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!