What is the name of this digital low pass filter?

I found this digital filter in code I am working on. It is a low pass filter. In the code it is called an "alpha filter", but it is not the same as the alpha filter mentioned here.

I post the relevant code below:

float alpha = 0.7;
float prev = 0.0;

float filter(float sample) {
float filtered = (sample * alpha) + (prev * (1.0 - alpha));
prev = sample;
return filtered;
}


It looks like alpha should be in range $[0, 1]$. By increasing alpha, the filter tracks the measurement with less delay, but lets more noise through.

I am tasked with writing library functions, and I would like to give this thing its proper name, and hopefully link to a Wikipedia article in the doc tags.

• Thanks Marcus. I did read the other question but I failed to catch that: out[i-1] + (alpha*(in[i] - out[i-1])); is mathematically the same as what I was dealing with. – Erik Van Hamme Jan 10 '18 at 12:55
• You can also check Is there a technical term for this simple method of smoothing out a signal? with both ways for writing the equation – Laurent Duval Jan 10 '18 at 16:36
• hay @MarcusMüller, take a look at Ced's answer. we got it wrong. it's not $y[n-1]$ that is fed back as "prev". it's $x[n-1]$. it's a two-sample FIR. – robert bristow-johnson Jan 11 '18 at 6:30
• i am opposed to closing. we all ('cept for @cedrondawg) read the question wrong. the OP should uncheck @MattL. 's answer or Matt should correct it. – robert bristow-johnson Jan 11 '18 at 6:32
• Oh, shoot, you're right! – Marcus Müller Jan 11 '18 at 8:03

I'm new, so I can't add this comment to Matt L.'s answer.

It is not an exponential filter, the equation is actually:

$$y[n] \ = \ \alpha \, x[n] \ + \ ( 1 - \alpha ) \, x[n-1]$$

So it is a very short FIR filter, not an IIR filter. I'm not expert enough to know a specific name.

Ced

============================================= Followup:

I want to thank everyone for their upvotes. Yes, I've contributed to comp.dsp and I am a blogger at dsprelated.com.

Like all of you, I suspect that the intent of the function was to be an exponential filter and was coded erroneously.

If I were to name the filter as coded, I would call it a "Linear Interpolation Filter", or perhaps a "Subsamplesize Time Shift filter" when $\alpha$ is between zero and one. It would make more sense as such if the $\alpha$ and $(1-\alpha)$ coefficients were reversed.

• hay Ced!! didn't we see you around comp.dsp or somewhere?  welcome. this answer tells us that you read the problem better than either @MattL. or myself. i totally missed that. – robert bristow-johnson Jan 11 '18 at 6:25
• You deserve additional votes to allow you comments – Laurent Duval Jan 11 '18 at 8:22
• Indeed. And I should in fact be detracted these reputation points that you deserve! – Marcus Müller Jan 11 '18 at 9:05
• I select this as the answer because this was the first correct identification of the filter, even though it is likely that an IIR filter was intended, but not implemented correctly. I also like Matt's answer. – Erik Van Hamme Jan 11 '18 at 16:16

This is a correction of my old answer (see below). It turns out that all of us misread the question except for Cedron Dawg in his answer.

Since prev is not the previous output sample but the previous input sample, this is no recursion and, consequently, not a 1-pole IIR filter, but a simple two-tap (finite impulse response) FIR filter:

$$y[n]=\alpha x[n]+(1-\alpha) x[n-1]$$

Since this is an FIR filter it is stable for any value of $\alpha$. For smoothing, a reasonable range for $\alpha$ is indeed $\alpha\in (0,1)$. Note that this filter doesn't really do that much, and it's much worse at smoothing than its IIR counterpart (see below).

Unlike the EWMA filter described below, this filter is no standard filter. It's just a two-tap FIR filter, and with $\alpha$ in the range $(0,1)$ it's a two-tap FIR smoothing filter. For $\alpha=0.5$ it would be a two-tap moving average filter.

I think what mislead most of us was the use of $\alpha$ in a convex combination of two samples. This is commonly done in a 1-pole IIR filter, but usually not in the FIR case. It could even be a bug, and that the author's intention actually was to code a 1-pole IIR filter.

[I keep it because it's an explanation of a standard filter that might be a good alternative to the filter in the question.]

It's called exponential smoothing or exponentially weighted moving average (EWMA) filter.

The corresponding difference equation is

\begin{align}y[n]&=\alpha x[n]+(1-\alpha)y[n-1]\\&=\alpha (x[n]-y[n-1])+y[n-1]\end{align}\tag{1}

For stability, $\alpha$ must be in the range $\alpha\in (0,2)$. For this to be a smoothing filter, one must choose $\alpha\in (0,1)$.

• a.k.a. a one-pole low-pass filter and the pole is $p = 1-\alpha$ . sometimes called "high-cut" in the audio domain. – robert bristow-johnson Jan 11 '18 at 6:22
• @robertbristow-johnson: Corrected, finally ... – Matt L. Jan 11 '18 at 7:38
• @MattL I think your bug theory is on the money here. Unfortunately, the old-timer who wrote this code is retired. Based on your comment that the filter doesn't do that much, I have coded both in a quick ruby script and compared the 2. The IIR is indeed much better. I have implemented the IIR in my library project and flagged a possible bug for the application code. – Erik Van Hamme Jan 11 '18 at 16:12

As other contributors, I did not read the question correctly, and kept the initial answer at the bottom. So it is, generally and in special cases:

• a (stable) unit-sum 2-tap FIR filter
• $\alpha = 0,1$: a pure delay filter, with zero or unit delay
• $\alpha =1/2$: the two-tap averaging filter
• $\alpha \in ]0,1[$: a low-pass filter
• $\alpha = 2$: the 2-tap linear extrapolating filter.

Details are the following:

$$\hat{s}[n] = \alpha s[n] + (1-\alpha) s[n-1]$$

is a 2-tap FIR filter. When $\alpha =1$ or $0$, it reduces to a one-tap filter, producing either the same output as the input or with a 1-unit delay (flat spectrum). Since the sum of the coefficients is always $1$, it leaves unchanged constant components: the frequency response is $1$ is one. When $\alpha = 2$, $[2 - 1]$ is the 2-tap linear extrapolating filter.

Several frequency responses are given below: [OLD ANSWER, KEPT IN CASE THE DESIGN WERE RECURSIVE] As this structure is one of the simplest/shortest one can imagine with a recursive form, it has likely emerged in different context, and got different names. Some of the names identified are:

Other details, including historical notes on its emergence, can be retrieved at:

Its behavior, as answered by Matt L., is driven by $\alpha$. For smoothing, the closer $\alpha$ to one, the higher the relative weight of the latest samples with respect to "filtered data". So the result is less immediate (more delay), but the larger the smoothing effect, as you benefit from the averaving of longer stationary sequences, weighted by an exponential window. Conversely, shortest delays correspond to less noise reduction. There is no free lunch in filtering: shorter filters, poorer frequency selection.

This filter does not deal too well with non stationarity (like trends) and was subsequently extended to double or triple exponential filters, giving rise to Holt-Winters smoothers, see for instance Exponential Smoothing for Time Series Forecasting:

If you notice that your time series is not stationary, you’ll have to find something other than a simple EWMA to do your forecasting.

In the late 1950s, Charles Holt recognized the issue with the simple EWMA model with time series with trend. He modified the simple exponential smoothing model to account for a linear trend. This is known as Holt’s exponential smoothing.

• You might also want to change your answer since we've all misread the question :) – Matt L. Jan 11 '18 at 7:40
• I have corrected the answer, there are names, finally – Laurent Duval Jan 11 '18 at 16:04
• Thank you for the frequency plots. Also, excellent info on the names of the IIR filter in the old answer! – Erik Van Hamme Jan 11 '18 at 16:23
• For a variation of an exponential filter that I discovered and have not seen anywhere else, check out my blog article: "Exponential Smoothing with a Wrinkle" dsprelated.com/showarticle/896.php Yay, I can comment now. – Cedron Dawg Jan 11 '18 at 16:35
• Excellent, i'll check that – Laurent Duval Jan 11 '18 at 16:52