3
$\begingroup$

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.

This algortihm is seen on wikipedia, this article and many more.

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.

$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – robert bristow-johnson Jun 21 '17 at 16:38
  • $\begingroup$ My apologies for my previous wrong! comment, here I correct: Your first line of code actually is equivalent to the following LCCDE of the form $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 is $$H(z) = \frac{a z^{-1}}{1 - (1-a)z^{-1}}$$. For the analysis of the filter type for possible range of $a$ values please see my answer below. $\endgroup$ – Fat32 Jul 23 '17 at 20:57
1
$\begingroup$

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:

RC filter

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] $$

$\endgroup$
0
$\begingroup$

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.

$\endgroup$
  • 1
    $\begingroup$ 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? $\endgroup$ – DH. Jun 22 '17 at 18:50
0
$\begingroup$

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 casual 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: enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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