1
$\begingroup$

Related to this question by @Molem7b5, what would be the frequency domain equivalent (filter implementation through overlap-add of DFT's) for a zero-phase filter as implemented with MATLAB/Octave/Python scipy.signal filtfilt command?

$\endgroup$

1 Answer 1

2
$\begingroup$

In essence filtfilt does the the following

$$y[n] = x[n] \ast h[n] \ast h[-n]$$

It's convolution with the impulse response and then the time reversed impulse response (in any order since the convolution is commutative).

So in the frequency domain it's simply

$$Y(z) = X(z) \cdot H(z) \cdot H'(z) = X(z) \cdot |H(z)|^2 $$

which obviously is zero-phase since $|H(z)|$ is real.

For an FIR filter that's easy enough: If your filter length is $N$, the cascade length is $2*N-1$ and your FFT length needs to be at least $4N-3$. Take your impulse response, zero pad it to the FFT size, take the magnitude squared and then mutliply with $e^{-j2\pi n/N} $ to get it circulated to the proper time location. Then proceed as with any other overlap add.

Alternatively you can just calculate the aggregate impules respones as

$$ h_{agg}[n] = h[n] \ast h[-n] $$

IIR filters can be done using the same approach but it requires turning the IIR into an FIR by suitable truncation of the impulse response. filtfilt() does that implicitly as well but uses the length of the signal as the truncation length.

$\endgroup$
4
  • $\begingroup$ Will that eliminate the start-up transients in an overlap-add approach such as the OP is asking here: dsp.stackexchange.com/questions/70589/… ? It should if this is identical to filtfilt, unless this is only half way there and then there are more factors to deal with the overlap-add effects of doing this on a longer dataset than the DFT length...I haven't thought this through. $\endgroup$ Commented Sep 29, 2020 at 22:29
  • $\begingroup$ No. The filter needs past input and past output samples. The transient is caused by the implicit assumption that these are zero. The signal you shove into a filter with its state variables set to zero is not just seeing the input but the input preceeded by a large number of zeros. That is in most cases a step (or at least a discontinuity in the deriviatives) so you get something that looks like step response, not a steady state response. $\endgroup$ Commented Sep 29, 2020 at 22:36
  • $\begingroup$ so then what can we do that would result in the same transient minimization as filtfilt (as I detailed in that post)--- or are we saying fundamentally it is the overlap-add aspect that is done to emulate the linear convolution (of any filter zero phase or otehrwise) that is at the heart of the problem? $\endgroup$ Commented Sep 29, 2020 at 23:12
  • 1
    $\begingroup$ Either change the filter itself or use information of the signal and the filter (including it's topology) to initialize the state variables with something that's not zero but a more reasonable guess. Simple example: Let's say you have a sine wave with a big DC offset and want to clean this up with a 1st order highpass. You can initialize the state with the an estimate of the DC offset and this can reduce the initial transient almost entirely $\endgroup$ Commented Sep 30, 2020 at 11:51

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.