10
$\begingroup$

When applying a low-pass filter to a constantly changing signal, there will be a lag between the actual value and the filtered value. For example, if f(x) = x, the regular low-pass filter output will always be less than f(x).

I remember coming across a filter that also tracked the rate of change, thus eliminating the lag when the rate of change is constant. At the time I didn't have any use for it, but it struck me as a clever solution to the problem.

This seems rather straightforward, but instead of trying to reinvent it myself I would like to read what has already been written. But I can't seem to find the name for it.

Is there a name for some common low-pass filter algorithm that accurately tracks a signal that has constant rate of change?

$\endgroup$

2 Answers 2

14
$\begingroup$

I was able to remember how the filter works. The idea is very simple, a second low-pass filter tracks the steady-state error in the result of the first one, and it is then added to the output:

Diagram of filter, own work

Based on some testing it will work well for my purpose, which is in motor control where rotation rate is usually constant:

Simulated results

Best term I've found so far for this is 'linear prediction filter', as hinted by Marcus Müller in the comments.

$\endgroup$
4
  • 6
    $\begingroup$ That looks like a linear predictor ;) $\endgroup$ Sep 16, 2023 at 14:04
  • 1
    $\begingroup$ @MarcusMüller Wow, thanks! "Linear prediction" gives very useful results. $\endgroup$
    – jpa
    Sep 16, 2023 at 16:44
  • $\begingroup$ But it can be reduced/transformed to some well-known type of filter, right? $\endgroup$ Sep 18, 2023 at 23:13
  • $\begingroup$ @PeterMortensen If the low-pass filters are FIR, the combination can be reduced to a single FIR filter, but AFAIK not to any of the common types with simple formulas for the coefficients. And similarly for IIR. $\endgroup$
    – jpa
    Sep 19, 2023 at 5:08
6
$\begingroup$

I do not think that there's a specific name for this type of lowpass filter. There are indeed similarities between the cascade of two lowpass filters as suggested in the OP's answer, and a combination of a lowpass filter with a linear predictor for a ramp signal. It's interesting to compare the behavior of these two systems when tracking a ramp at the input. The two approaches are not identical, but they do have some similarities.

A linear predictor predicting a ramp $M$ samples in the future is given by

$$y[n] = x[n] + M\big(x[n]-x[n-1]\big)\tag{1}$$

The prediction length $M$ must be chosen to equal the delay of the lowpass filter. In case of a linear phase FIR filter we have a constant delay of $M=(N-1)/2$, where $N$ is the number of filter taps. For (minimum phase) IIR filters we can use the group delay at DC.

I used a simple $21$-tap FIR lowpass filter (cut-off at Nyquist$/2$) designed by windowing, and cascaded it with the predictor $(1)$. The figure below shows the time domain signals and the frequency domain responses of this cascade, and of the cascaded lowpass filters as described in the OP's answer. It can be seen that the system with the predictor recovers faster after a change in the input signal. This comes at the price of a higher overshoot in the frequency domain. The latter problem could be alleviated by choosing a lower cut-off frequency of the lowpass filter.

enter image description here

I did exactly the same comparison with a Butterworth IIR lowpass filter (order $10$). The figure below shows that the differences between the two methods are less pronounced in the time domain. Yet, there's still a significant difference in the frequency domain. enter image description here

Note that for both filter types (FIR and IIR), I've used identical filters for implementing the cascade of lowpass filters. In this case, the complexity of the solution using cascaded lowpass filters is approximately twice the complexity of the solution with the linear predictor.

The reason why both systems can track a ramp at the input without delay is the fact that both systems have zero group delay at DC. Furthermore, the group delay is flat at DC, which means that a number of derivatives also vanish. The figure below shows the phase and group delay responses of the cascade of two lowpass filters and of the lowpass filter combined with the linear predictor. In both cases, the lowpass filter is the same tenth order Butterworth filter shown above. Clearly, for both systems the phase as well the group delay are flat at DC, and the group delay vanishes at DC.

enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ Interesting Matt! Thanks for pointing out the impact the the filter's frequency response. I see how x[n]-x[n-1] is just a slope predictor (differencer) and that M * the slope would be the ideal correction; this then made me start thinking of how alternate differencing implementations that are less sensitive to higher frequency noise (such as the central difference 0.5(x[n]-x[n-2]) and others that are not as simple) could perform in comparison. I didn't try but suspect it would have similar time performance with some reduction in the frequency peaking. $\endgroup$ Sep 18, 2023 at 10:54
  • 1
    $\begingroup$ @DanBoschen: Yes, you're right I guess. But I think a very similar thing can be achieved by just lowering the cut-off frequency of the lowpass filter. This is all very similar to lowpass differentiators, which I've discussed a bit in this answer. $\endgroup$
    – Matt L.
    Sep 18, 2023 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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