Alex
Alex

Reputation: 2074

How to write lowpass filter for sampled signal in Python?

I am new in signal processing, and I didn't find Python code with good explanation. So I will be glad to get a simple explanation.

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, first 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 performance of code is important.

Upvotes: 1

Views: 11233

Answers (1)

Li-aung Yip
Li-aung Yip

Reputation: 12486

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.

Upvotes: 9

Related Questions