1
$\begingroup$

I am trying to filter a sinusoid ($f_{sample}=50 Hz$) ,, i need to remove all frequencies above 10 Hz with accepted transition region 2 Hz (stop band freq=12 Hz)

the question is why after filtering this signal is the 20 Hz still appearing in the FFT? is there something wrong ? I know results should be the same in frequency and time domain filtering but the first in multiplication and the 2nd in convolution.

here is the code :

 t=[0:1/50:1];  
 y=cos(2*pi*20*t)+0.5*sin(2*pi*5*t);  
 fsamp=50;      
 frange=[10 12];    
 mag=[1 0];  
 devs=[0.02 0.02];  
 frange=[10 12];  
 [n,fo,ao,w] = firpmord(frange,mag,devs,fsamp);  
 n = n + rem(n,2);  
 b=firpm(n,fo,ao,w,'hilbert');  
 %%% filter in time domain
 final1=filter(b,1,y);  
 finalfft=abs(fft(final1));
 t=[0:1/50:(length(finalfft)-1)/50];  
 f=[(t/t(end))*50];  
 figure(1);plot(f,abs(fft(y)));   
 figure(2);plot(f,finalfft);    

 %%% filter in freq domain 
 paddedfft=fft(y);  
 bfft=fft(b,length(y));  
 finalfft=paddedfft.*bfft;  
 final1=ifft(finalfft);  
 t=[0:1/50:(length(finalfft)-1)/50];  
 f=[(t/t(end))*50];  
 t=[0:1/50:(length(final1)-1)/50];  
 figure(3);plot(f,abs(fft(final1))); 

input signal signal fft
fft of the filtered signal ,, filtered in time domain fft of the filtered signal ,, filtered in frequency domian

$\endgroup$
2
$\begingroup$

Some time ago I wrote some codes just to test some filters methods, and i could see how can be hard make certain frequencies disappear completely, some methods cause ripple effects in the signal and when you apply FFT on the filtred signal to see the frequency response, you note that the frequency you want to eliminate still be there, attenuated, but you can still see!

Lets go, three(3) sinusoidal concatenated at 250 hz, 400 hz and 900hz sampled in 8000hz and I will try to eliminate 900hz from the original signal!

My First test, AKA a very simple equalizer in Frequency Domain, calculate the dB attenuation 10.^(dB/20) and multiply by the FFT bin that you want eliminate, for dB attenuation -24dB my result was:

enter image description here

My Second test EQ biquad filter by Robert Bristow-Johnson (time domain), for dB attenuation -24dB my result was:

enter image description here

My Third test biquad LPF by Robert Bristow-Johnson (time domain), my result was:

enter image description here

And my last test using Sinc Filter (Frequency Domain), my result was:

enter image description here

And that's all, in short, everything depends on what you really need !

$\endgroup$
1
$\begingroup$

Your passband ripple value is very wrong. It is just 0.3dB(=0.02) which is a very stringent requirement from the filter. Your problem will be solved if you used something like a 3dB. Also you could decrease your stopband attenuation by a further 6dB(now it is at 34dB). With a passband ripple of 3dB and a stopband attenuation of 40dB, the filter will be designed as:

fsamp=50;      
frange=[10 12];    
mag=[1 0];  
devs=[0.170997357 0.01];  
frange=[10 12];  
[n,fo,ao,w] = firpmord(frange,mag,devs,fsamp);  
n = n + rem(n,2);  
b=firpm(n,fo,ao,w,'hilbert');  <br>

Notice the change in the values of "devs". The filter will work perfectly now.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.