To discretely filter a signal in Python, you can use the lfilter
function from the scipy.signal
package, which is built on top of NumPy. Here's an example:
main.py439 chars17 lines
In this example, we first create a test input signal x
, with a frequency of 10 Hz. We then define a lowpass Butterworth filter with a cut-off frequency of 15 Hz and order
4.
Finally, we apply the filter to the input signal using lfilter
. The resulting filtered signal y
has been smoothed with the lowpass filter, removing high frequency noise beyond 15 Hz.
Note that you can also use other filter types (e.g. Chebyshev, Bessel, etc.) and other filter functions (e.g. filtfilt
) depending on your requirements.
gistlibby LogSnag