Home > Mobile >  scipy.signal.lfilter in Python
scipy.signal.lfilter in Python

Time:09-17

I have used

scipy.signal.lfilter(coefficient, 1, input, axis=0)

for filtering a signal in python with 9830000 samples (I have to use axis=0 to get similar answer to matlab), compere to matlab

filter(coefficient, 1, input)(seconds),

it takes very long time (minus) and it becomes worse when I have to filtering several of time. is there any suggestion for that? I have tried numpy as well same timing issue. Is there any other filter that I can received similar answers?

CodePudding user response:

You can use ifilter from itertools to implement a faster filter. The problem with the build-in function filter from Python is that it returns a list that is memory-consuming when you are dealing with lots of data. Therefore, itertools.ifilter is a better option because it calls the function only when needed.

Some other ideas depending on your implementation are:

  1. If you are designing an FIR filter, you can apply convolve.
  2. Or you can use correlation, to get faster results, because it uses FFT.
  • Related