- Can I use
filtfiltfunction in realtime filter.
filtfiltfirst filters a piece of data forward and then filters it backward. I want to collect a piece of data first and then output a piece of data after each input. Is this possible?
- Can you introduce me some methods in filtering, the filter delay is no more than the sample frequency 3-5 times.
Can I use filtfilt function in realtime filter
filtfilt() is a method to create zero phase IIR filters. These are infinitely non-causal, so you can't implement them in real time. You can truncate an IIR filter to a finite length, but than it becomes a regular FIR filter and
filtfilt() doesn't make sense anymore.
Can you introduce me some methods in filtering, the filter delay is no more than the sample frequency 3-5 times.
Most control systems use minimum phase filters (IIR or FIR) to minimize the latency. For any given transfer function magnitude. this class of filters minimizes the group delay between input and output. However, the delay is not constant and varies by frequency.
The alternative would be linear phase filters (FIR only). These have the same delay at every frequency, but the latency is half the filter length, so you would be constrained to very short filters and a very limited frequency resolution.
The only filter that should be used in a control system is the Loop Filter, and this is typically designed using control loop theory together with the transfer function of the rest of the loop rather than a traditional FIR or IIR filer design (and certainly not an application for
filtfilt). The loop filter can be developed through frequency domain analysis techniques (which is very intuitive once used) using the open loop and closed loop gain with a stability metrics such as phase and gain margin, or in the time domain using state-space matrix equations. Higher order loops are more challenging to control but offer tighter rejection in the frequency domain.
Ultimately design the loop filter according to standard practices for an assumed loop order and type. Once designed, be very careful of temptations to to reduce noise in the error signal by adding additional filters- let the loop filter remove the noise! Additional filtering can be added only when the poles of the additional filtering are significantly higher than the poles in the primary loop as given by the open loop transfer function of all functional blocks in the loop (which end up being equivalent to minimum delay).
Please see this other post detailing example "loop filters" typically used in phase lock loop applications where an oscillator is phase-locked to a reference. Note there is only one delay element in the loop filter itself. What is shown is a "Proportional-Integral Loop Filter", which isn't the solution for all applications. The actual loop filter to use depends on the element being controlled and it's characteristics and the requirements for the closed loop design.