How to write lowpass filter for sampled signal in Python?

Alex picture Alex · Jul 11, 2012 · Viewed 10.1k times · Source

Sorry for question that may be trivial, but I am new in signal processing, and I didn't find python code with good explanation. So I will be glad to get explanation for dummy :)

I have some signal that sampled each 1 nsec (1e-9 sec) and have, let say, 1e4 points. I need to filter high frequencies from this signal. Let say I need to filter frequencies higher than 10MHz. I want that for frequencies lower than cutoff frequency signal will be passed unchanged. It means gain of the filter will be 1 for frequencies lower than cutoff frequency. I would like to be able to specify filter order. I mean, fitsr order filter have 20 db/decade slope (power rolloff) after cutoff frequency, second order filter have 40 db/dec slope after cutoff frequency and so on. High perfomance of code is importent.

Thank you very much for help. Alex.

Answer

Li-aung Yip picture Li-aung Yip · Jul 11, 2012

You appear to have two questions:

  1. How do I design a lowpass filter with a 10MHz cutoff frequency and an arbitrary filter order?
  2. How do I realise that filter in Python?

Filter design is beyond the scope of Stack Overflow - that's a DSP problem, not a programming problem. Filter design is covered by any DSP textbook - go to your library. I like Proakis and Manolakis' Digital Signal Processing. (Ifeachor and Jervis' Digital Signal Processing isn't bad either.)

If you must have teh coeds, try this blog post, which shows how to design a Butterworth lowpass filter with scipy.

As for implementation of the filter in Python, scipy has a lfilter() function which applies a FIR or IIR filter to a signal in one dimension.