Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fft bandpass filter in python

What I try is to filter my data with fft. I have a noisy signal recorded with 500Hz as a 1d- array. My high-frequency should cut off with 20Hz and my low-frequency with 10Hz. What I have tried is:

fft=scipy.fft(signal) 
bp=fft[:]  
for i in range(len(bp)): 
    if not 10<i<20:
        bp[i]=0

ibp=scipy.ifft(bp)

What I get now are complex numbers. So something must be wrong. What? How can I correct my code?

like image 230
men in black Avatar asked Oct 01 '13 17:10

men in black


People also ask

What does FFT bandpass filter do?

This plugin is built into ImageJ as the Process/FFT/Bandpass Filter command. Description: Filters out large structures (shading correction) and small structures (smoothing) of the specified size by gaussian filtering in fourier space.

How do I get frequencies from FFT in Python?

We can obtain the magnitude of frequency from a set of complex numbers obtained after performing FFT i.e Fast Fourier Transform in Python. The frequency can be obtained by calculating the magnitude of the complex number. So simple ab(x) on each of those complex numbers should return the frequency.


1 Answers

There's a fundamental flaw in what you are trying to do here - you're applying a rectangular window in the frequency domain which will result in a time domain signal which has been convolved with a sinc function. In other words there will be a large amount of "ringing" in the time domain signal due to the step changes you have introduced in the frequency domain. The proper way to do this kind of frequency domain filtering is to apply a suitable window function in the frequency domain. Any good introductory DSP book should cover this.

like image 95
Paul R Avatar answered Nov 15 '22 15:11

Paul R