# Low pass filter algorithm origin

I have been doing some research, because I used this algorithm that's very spread in the web:

y += a * (x - y)

or

y = (a * y) + (x - (a * x)

Where x is input, and y is the filter output, and a is actually alpha, which there's some math behind it to define it's value.

But none actually shows why this algorithm is a low pass filter and from which formula it actually came from(wikipedia has no source for it). I'm doing a small academic paper, so I need to know exactly from where it came.

• i think if there is any "ontological" origin to the low-pass filter, i think it would lie with the concept of the arithmetic mean. we do averaging to "filter out" variations and to leave a general trend. – robert bristow-johnson Jun 21 '17 at 16:38

I tried to make my derivation match up exactly with embeddedrelated's. The filter you cited uses an approximation, which further obfuscates intuitively understanding it.

embeddedrelated does cite the frequency transfer function that the IIR filter is based off of: $$H(s)=\frac{1}{1+s\tau}$$

The transfer function for a simple RC low pass filter is: $$H(s)_{RC}=\frac{1}{1+sRC}$$ $$\tau=RC$$

Schematic:

We can derive a difference equation from the above schematic.

$$I=C\frac{dV_{out}}{dt}$$ $$I = \frac{V_{in} - V_{out}}{R}$$ $$C\frac{dV_{out}}{dt}=\frac{V_{in} - V_{out}}{R}$$ $$C\frac{V_{out}[n]-V_{out}[n-1]}{ts}=\frac{V_{in}[n] - V_{out}[n]}{R}$$ $$V_{in}[n]+\tau f_s V_{out}[n-1]=\tau f_s V_{out}[n] + V_{out}[n]$$ I have tested this form: $$\frac{V_{in}[n]+\tau f_s V_{out}[n-1]}{\tau f_s + 1}=V_{out}[n]$$ $$\tau f_s >> 1$$ I have not tested this form: $$\frac{V_{in}[n]}{\tau f_s} + V_{out}[n-1]\approx V_{out}[n]$$

I've seen it called a recursive moving average filter, an $\alpha$ filter, and a forgetting filter. The $\alpha$ filter is covered in the Wikipedia article on Alpha Beta Filters.

The transfer function was given in one of the comments.

The origin is going to be hard to track down because it is a very simple filter.

• Yeah, I found out that it would be easier if I find papers and books about the types of filters and not this filter in particular. Those keywords said in your answer and in @Fat32 's comment helped me a lot. Maybe mix everything up so it can be a complete answer? – DH. Jun 22 '17 at 18:50

Looking at your first line of C-code:

y += a*(x-y)

It can be converted to an algebraic relation between the samples of the filter output sequence $$y[n]$$ and the filter input $$x[n]$$ as:

$$y[n+1]-(1-a)y[n]=ax[n]$$ which is also equivalent to $$y[n]-(1-a)y[n-1]=ax[n-1]$$

And the associated transfer function of this filter is $$H(z) = \frac{a z^{-1}}{1 - (1-a)z^{-1}} = \frac{a z^{-1}}{1 + (a-1)z^{-1}}$$

Now your application will probably require a causal filter, (which means only current and past input is available and should be used to produce current output) in which case then the poles of the filter should reside inside the unit circle , i.e., $$|z_p| < 1$$.

Since this filter has a single pole which is at $$z_p=(1-a)$$ then we have; $$|1-a| < 1$$ and hence; $$0 < a <2$$ is the allowed range of real $$a$$ for which you can have a stable and causal filter.

Now to have a casual and stable lowpass filter you require that the pole is along the positive side of the real line, i.e., $$0 < z_p < 1$$ which means that we require $$0 < a < 1$$.

Otherwise when $$1 < a < 2$$ the filter becomes a highpass filter (actually it will be some other form of high-boost or shelving type filter rather than a strict high-pass filter which should block low frequencies, which these filters won't), as the pole will become negative for that range of $$a$$.

Note also that $$a=1$$ produces output equal to input shifted by 1 samples: $$y[n] = x[n-1]$$

Below are a few frequency response plots for different values of valid $$a$$ range: