I'm applying an ideal filter on the frequency domain. My code below:
N=512;
fs=100;
t=0:1/fs:(N-1)/fs;
s1=sin(2*pi*2*t);
s2=0.2*sin(2*pi*20*t);
s=s1+s2;
subplot(321), plot(t,s)
S=fft(s);
w=linspace(0,fs,N);
subplot(322), plot(w,log(abs(S)))
fc=12;
H=zeros(1,N);
H( w<=fc ) = 1;
H( w>=fs-fc ) = 1;
subplot(323), plot(w,abs(H))
SF=H.*S;
subplot(324), plot(w,log(abs(SF)))
ss = ifft(SF);
subplot(325), plot(t,ss); title('Filtered on freq domain')
h=ifft(H);
ss2=conv(s,h);
subplot(326), plot(t,ss2(N:end)); title('Filtered on time domain')
The results are not the same.
And so my questions are:
What am I doing wrong?
Is it better to filter on frequency domain or time-domain or it's the same?
Sometimes applying a filter on frequency domain results on a "strange" signal after IFFT. Why?
No comments:
Post a Comment