# what kind of digital filter is this

Started by November 12, 2004
```Hello all,
I found the following digital filter algortihm

Function filter(input: extended):exteded;
begin
x[0]:=  (input+ a*x[-1]+b*x[-2]);
filter:=  (c*x[0]+d*x[-1]+e*x[-2]);
x[-2]:= x[-1];
x[-1]:= x[0];
end;

Can anybody tell my what type it is? Is it a IIR or a FIR filter,
or something special?

em
```
```"Erik" <markin@gmx.de> wrote in message
> Hello all,
> I found the following digital filter algortihm
>
> Function filter(input: extended):exteded;
> begin
>   x[0]:=  (input+ a*x[-1]+b*x[-2]);
>   filter:=  (c*x[0]+d*x[-1]+e*x[-2]);
>   x[-2]:= x[-1];
>   x[-1]:= x[0];
> end;
>
> Can anybody tell my what type it is? Is it a IIR or a FIR filter,
> or something special?
>
> em

Bog standard IIR

Draw it out  and you'll see it immediately.

JS

```
```"John Smith" <bill.gates@microsoft.com> wrote in message
news:cn221e\$q87\$1@newstree.wise.edt.ericsson.se...
>
> "Erik" <markin@gmx.de> wrote in message
>> Hello all,
>> I found the following digital filter algortihm
>>
>> Function filter(input: extended):exteded;
>> begin
>>   x[0]:=  (input+ a*x[-1]+b*x[-2]);
>>   filter:=  (c*x[0]+d*x[-1]+e*x[-2]);
>>   x[-2]:= x[-1];
>>   x[-1]:= x[0];
>> end;
>>
>> Can anybody tell my what type it is? Is it a IIR or a FIR filter,
>> or something special?

Use the canonical form of a filter (which can be either FIR or IIR) to
determine.  It will look like this:

/---\            p[k]          /---\
x[k]--------| + |----->-------+------>-----| + |----------> y[k]
\---/             |     b0     \---/
|               |              |
|            +--+--+           |
^            |     |           ^
|            |z^-1 |           |
|            +--+--+           |
/---\             |            /---\
| + |-----<-------+------>-----| + |
\---/    -a1      |     b1     \---/
|            +--+--+           |
|            |     |           |
^            |z^-1 |           ^
|            +--+--+           |
/---\             |            /---\
| + |-----<-------+------>-----| + |
\---/    -a2      |     b2     \---/

Where b0=c; -a1=a; -a2=b; b1=d; b2=e and, on inspection, your x[k] is the
point I've labeled
p[k].

y[k]=b0*x[k] + b1*x[k-1] + ... + a1*y[k-1] + a2*y[k-2] + ''''

H(z) =[b0 + b1*z^-1 +b2*z^-2...]/ [1 - a1*z^-1 -a2*z^-2 ...]

If the filter is a FIR, then all of the a's are zero (no feedback).

Hmmmmm... I've used these expressions a number of times ... so now why don't
I believe them?

Fred

```
```In article <42ff5eeb.0411120114.33bc915f@posting.google.com>,
Erik <markin@gmx.de> wrote:
>I found the following digital filter algortihm
>
>Function filter(input: extended):exteded;
>begin
>  x[0]:=  (input+ a*x[-1]+b*x[-2]);
>  filter:=  (c*x[0]+d*x[-1]+e*x[-2]);
>  x[-2]:= x[-1];
>  x[-1]:= x[0];
>end;
>
>Can anybody tell my what type it is? Is it a IIR or a FIR filter,
>or something special?

It's a standard IIR filter.

Depending on the coefficients a,b,c,d,e, you can get lowpass, highpass,
bandpass, band reject, or just about anything.

I wrote an article on constructing lowpass and highpass filters,
which end up in the form similar to what you show above.  You might
be interested: http://unicorn.us.com/alex/allpolefilters.html

-A
```