Tuesday, December 24, 2019

filter design - Filtering on time or frequency domain?


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:




  1. What am I doing wrong?





  2. Is it better to filter on frequency domain or time-domain or it's the same?




  3. Sometimes applying a filter on frequency domain results on a "strange" signal after IFFT. Why?




enter image description here




No comments:

Post a Comment

digital communications - Understanding the Matched Filter

I have a question about matched filtering. Does the matched filter maximise the SNR at the moment of decision only? As far as I understand, ...