2
$\begingroup$

I'm doing basic signal processing in Python. I'm filtering consecutive blocks of a signal with scipy's filtfilt (to get zero phase). I would like to concatenate several blocks after filtering, however, each filtered block doesn't seem to be properly continuous with the other filtered blocks. Is there some way to work this out?

I'd like to note that when I'm doing the same with scipy's lfilter with "Initial Conditions"(zi) parameter being passed to it at each iteration the filtered blocks seems to be continuous.

Any help will be highly appreciated.

Mike

$\endgroup$
1
$\begingroup$

Both the SciPy and MATLAB implementations of filtfilt use a mirrored part of the beginning and end of the signal (roughly with a length equal to the impulse response of the filter) to reduce the effect of initial conditions on the filtered signal (i.e. to reduce ringing the signal is artificially lengthened by concatenating mirrored parts of the signal).

As these mirrored signal parts are probably not equal to the data in the previous and subsequent data blocks, concatenation of the filtered blocks will not result in a continuous signal.

A possible workaround might be to select longer data blocks from the original signal and discard a part from the beginning and end after application of the filter but before concatenation. Note that this might require a FIR filter to work properly although I would expect acceptable results for a IIR filter if the data block can be made long enough.

$\endgroup$
  • $\begingroup$ Interesting. I will give it a try, although I doubt that this will work. I'm using butterworth filter(stop pass) to remove EMF noise from a signal. Again, with lfilter it seems to work well when I save the initial conditions and pass it to lfilter with every run. However, with the lfilter solution I have a problem with its phase delay. $\endgroup$ – mike Aug 24 '17 at 10:05
  • $\begingroup$ You could concatenate the signal after the first pass through lfilter, flip it / reverse the signal, chop it in blocks, pass these blocks through lfilter (passing initial conditions from block to block) and concatenate and flip again. This should cancel out the phase delay while effectively applying the filter twice. I think this should also be analogous to the proposed filtfilt approach, provide that the data blocks are extended sufficiently. $\endgroup$ – user883521 Aug 24 '17 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.