Zero-phase digital real-time filter

In Matlab, we can use the filterfilt function to filter data that implements filtering methods forward and backward, which leads to a zero phase. But it is difficult to implement this filter in real time, since it includes filtering back.

I want to implement a first-order first or low-pass filter with a zero phase in real time. How can I achieve this?

I have been searching the Internet for several days, but I cannot figure out how to start with it!

Thanks in advance!

+4
source share
2 answers

It is not possible to execute a filter with a zero phase in real time because a filter with a zero phase requires filter coefficients that are symmetrical around zero. This means that the filter is not causal, or that the current output is dependent on future input. This, of course, is not possible in real time and can be faked, as in the case of filtfilt during subsequent processing.

What you are probably looking for is a linear phase . Do not let this name confuse you; this does not mean that the filter produces any phase distortion. This means that a time shift is applied to the output. A linear phase shift in frequency leads to a constant time shift. Thus, basically your output will delay a certain number of samples ( group delay ) from the input.

Thus, the only difference between filters with a zero phase and a linear phase is that the output of the filter of the linear phase is a delayed version of the output signal with a zero phase. This delay can be accounted for by tracking group delay if you need to keep output aligned in time with input.

Reply to comment:

FIR filters are guaranteed to be linear if their coefficients are symmetrical about the center. MATLAB can easily create these types of filters with features such as fir1 or firpm . The examples in the documentation of these functions should show you how to use them.

The group delay of the linear FIR filter is (L-1)/2 , where L is the filter length. Because of this and several other things, I usually choose an odd filter length so that the delay is aligned with the sample, and not between the samples. This basically means that the output signal will be delayed from the input using (L-1)/2 samples.

The implementation of the actual filtering process is basically a discrete convolution of input with a filter. This includes changing the filter coefficients, multiplying them by the most recent input samples L and adding these results to create one output sample. Then a new input pattern is introduced, and the whole process is performed again to create another pattern (mutiplying and summing over a sliding window). You should be able to find sample convolution code on the Internet.

This is a direct way to do FIR filtering, but for longer filters it might be more efficient to perform fast convolution using FFT.This will be much harder because if you are not talking about high sampling frequencies and long filters, I would just go with a direct approach .

+21
source

An “unreasonable” zero-phase filter plus a sufficient amount of added delay can be approximated by a linear linear FIR filter. This assumes that adding some delay meets your system requirements.

In your case, you can take the impulse response of the filtering process forward or backward of the asymmetric (or non-linear phase), a window in which the impulse response to make the answer finite in length, delay the core with a finite length so that it doesn’t run "future" samples and use this as the core of the FIR filter. You will need to check the results to see if the window you have selected is suitable in length and shape. There may be a trade-off in choosing a delay over the quality of the filter due to the window numbering needed for this delay.

+1
source

All Articles