DSPRelated.com
Forums

First order IIR filter

Started by Rohit February 24, 2009
Dear All,

I do not have any background in DSP, so please excuse if this question
seems silly.
I am working on a bugfix for an IIR filter implementation in C.
It takes samples from ADC and filters them. Filtering is done by an
First order IIR filter.
The transfer function is as follows:
  /* First order IIR filter z-transform(formula):

                     [ 2^-n/(1-(2^-n)) ]
            H(z) = ---------------------------------
                   [1 - (  (1/ (1- (2^-n)))*Z^-1  )]
and the final equation which is implemented into code is a sfollows:

Output = ([1/(2^n -1)]*input) + ([2^n/(2^n -1)]*PreviousOutput)

I googled a lot about IIR filters but nowhere I could find this
formula.
Can anyone of you please throw a light on whether this formula really
implements an IIR filter or not,
and where to find more information on this.

Thanks
Rohit
On Feb 24, 8:51&#4294967295;pm, Rohit <papakap...@gmail.com> wrote:
> Dear All, > > I do not have any background in DSP, so please excuse if this question > seems silly. > I am working on a bugfix for an IIR filter implementation in C. > It takes samples from ADC and filters them. Filtering is done by an > First order IIR filter. > The transfer function is as follows: > &#4294967295; /* First order IIR filter z-transform(formula): > > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295;[ 2^-n/(1-(2^-n)) ] > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; H(z) = --------------------------------- > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295;[1 - ( &#4294967295;(1/ (1- (2^-n)))*Z^-1 &#4294967295;)] > and the final equation which is implemented into code is a sfollows: > > Output = ([1/(2^n -1)]*input) + ([2^n/(2^n -1)]*PreviousOutput) > > I googled a lot about IIR filters but nowhere I could find this > formula. > Can anyone of you please throw a light on whether this formula really > implements an IIR filter or not, > and where to find more information on this. > > Thanks > Rohit
It's an IIR filter all right.You can find its dc gain when z=1 and gain at half sampling when z=-1. Otehr than that I have no idea what it does. I would plot the freq response in Matlab for a particular n. Should be Output = ([1/(2^n -1)]*PreviousOutput) + ([2^n/(2^n -1)]*input) Hardy
> /* First order IIR filter z-transform(formula): > > [ 2^-n/(1-(2^-n)) ] > H(z) = --------------------------------- > [1 - ( (1/ (1- (2^-n)))*Z^-1 )] >and the final equation which is implemented into code is a sfollows: > >Output = ([1/(2^n -1)]*input) + ([2^n/(2^n -1)]*PreviousOutput) >
Hello Rohit, It is an IIR. Best Regards, Markus PS: general transfer function for first order IIR: b0 H(z) = ------------------------ [1 - ( a1 * Z^-1 )] y[n] = x[n] b0 + y[n-1] * a1 y[n] is the same as Output in your formula, y[n-1] the same as PreviousOutput and x[n] is input, n is time index.
Rohit wrote:

> I am working on a bugfix for an IIR filter implementation in C. > It takes samples from ADC and filters them. Filtering is done by an > First order IIR filter. > The transfer function is as follows: > /* First order IIR filter z-transform(formula): > > [ 2^-n/(1-(2^-n)) ] > H(z) = --------------------------------- > [1 - ( (1/ (1- (2^-n)))*Z^-1 )] > and the final equation which is implemented into code is a sfollows:
> Output = ([1/(2^n -1)]*input) + ([2^n/(2^n -1)]*PreviousOutput)
http://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average (Though the two coefficients should add to one, not subtract to one, in the usual case.)
> I googled a lot about IIR filters but nowhere I could find this > formula.
Yes it is an IIR filter. It might be that it is used more by statisticians than EE/CS so it has a different name.
> Can anyone of you please throw a light on whether this > formula really implements an IIR filter or not, > and where to find more information on this.
http://en.wikipedia.org/wiki/Moving_average Otherwise, statistics books. -- glen
>Rohit wrote: > >> I am working on a bugfix for an IIR filter implementation in C. >> It takes samples from ADC and filters them. Filtering is done by an >> First order IIR filter. >> The transfer function is as follows: >> /* First order IIR filter z-transform(formula): >> >> [ 2^-n/(1-(2^-n)) ] >> H(z) = --------------------------------- >> [1 - ( (1/ (1- (2^-n)))*Z^-1 )] >> and the final equation which is implemented into code is a sfollows: > >> Output = ([1/(2^n -1)]*input) + ([2^n/(2^n -1)]*PreviousOutput) > >http://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average > >(Though the two coefficients should add to one, not subtract to one, >in the usual case.) > >> I googled a lot about IIR filters but nowhere I could find this >> formula. > >Yes it is an IIR filter. It might be that it is used more by >statisticians than EE/CS so it has a different name. > >> Can anyone of you please throw a light on whether this >> formula really implements an IIR filter or not, >> and where to find more information on this. > >http://en.wikipedia.org/wiki/Moving_average > >Otherwise, statistics books.
Huh? I would have thought the basic single pole LPF was about the most used filter for statisticians, EE, CS, DSP, or just about any other denomination of folks who filter that I can think of. Steve
On Feb 24, 1:44&#4294967295;pm, "mboigner" <mboig...@two-pi.com> wrote:
> > &#4294967295;/* First order IIR filter z-transform(formula): > > > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; [ 2^-n/(1-(2^-n)) ] > > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295;H(z) = --------------------------------- > > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; [1 - ( &#4294967295;(1/ (1- (2^-n)))*Z^-1 &#4294967295;)] > >and the final equation which is implemented into code is a sfollows: > > >Output = ([1/(2^n -1)]*input) + ([2^n/(2^n -1)]*PreviousOutput) > > Hello Rohit, > > It is an IIR. > > Best Regards, > Markus > > PS: general transfer function for first order IIR: > > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295;b0 > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; H(z) = ------------------------ > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295;[1 - ( &#4294967295; a1 &#4294967295;* Z^-1 &#4294967295;)] > > y[n] = x[n] b0 + y[n-1] * a1 > > y[n] is the same as Output in your formula, y[n-1] the same as > PreviousOutput and x[n] is input, n is time index.
Thanks to all for help. Possibly I could not convey my question properly. I do not know z- transform and filter design. I am a C programmer and I need to verify that whether the equation implemented in code i.e. Output = ([1/(2^n -1)]*input) + ([2^n/(2^n -1)] *PreviousOutput)...........................Eq.1 is implementing the 1st order IIR filter whose z - transform function is [ 2^-n/(1-(2^-n)) ] H(z) = --------------------------------- .....................................Eq. 2 [1 - ( (1/ (1- (2^-n)))*Z^-1 )] where n is filter constant. I am sure that Eq.1 is implemented correctly in code. But whether Eq.1 implements the requirement i.e. Eq.2 or not, is the question. So if anybody could help me in deriving Eq.1 from Eq.2, I will deeply appreciate. --Rohit
steveu wrote:

>>Rohit wrote:
(snip)
>>>I googled a lot about IIR filters but nowhere I could find this >>>formula.
>>Yes it is an IIR filter. It might be that it is used more by >>statisticians than EE/CS so it has a different name.
(snip)
> Huh? I would have thought the basic single pole LPF was about the most > used filter for statisticians, EE, CS, DSP, or just about any other > denomination of folks who filter that I can think of.
I have never seen the term "IIR filter" in a statistics book, or anything related to poles. The same filter under a different name. -- glen
Rohit wrote:
> Dear All, > > I do not have any background in DSP, so please excuse if this question > seems silly. > I am working on a bugfix for an IIR filter implementation in C. > It takes samples from ADC and filters them. Filtering is done by an > First order IIR filter. > The transfer function is as follows: > &#4294967295; /* First order IIR filter z-transform(formula): > > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295;[ 2^-n/(1-(2^-n)) ] > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; H(z) = --------------------------------- > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295;[1 - ( &#4294967295;(1/ (1- (2^-n)))*Z^-1 &#4294967295;)] > and the final equation which is implemented into code is a sfollows: > > Output = ([1/(2^n -1)]*input) + ([2^n/(2^n -1)]*PreviousOutput) > > I googled a lot about IIR filters but nowhere I could find this > formula. > Can anyone of you please throw a light on whether this formula really > implements an IIR filter or not, > and where to find more information on this.
Rick Lyons explains exactly this filter in a recent blog of his: http://www.dsprelated.com/showarticle/72.php
On Tue, 24 Feb 2009 04:10:15 -0800, Rohit wrote:

> On Feb 24, 1:44&nbsp;pm, "mboigner" <mboig...@two-pi.com> wrote: >> > &nbsp;/* First order IIR filter z-transform(formula): >> >> > &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [ 2^-n/(1-(2^-n)) ] >> > &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;H(z) = --------------------------------- >> > &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [1 - ( &nbsp;(1/ (1- (2^-n)))*Z^-1 &nbsp;)] >> >and the final equation which is implemented into code is a sfollows: >> >> >Output = ([1/(2^n -1)]*input) + ([2^n/(2^n -1)]*PreviousOutput) >> >> Hello Rohit, >> >> It is an IIR. >> >> Best Regards, >> Markus >> >> PS: general transfer function for first order IIR: >> >> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;b0 >> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; H(z) = ------------------------ >> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[1 - ( &nbsp; a1 &nbsp;* Z^-1 &nbsp;)] >> >> y[n] = x[n] b0 + y[n-1] * a1 >> >> y[n] is the same as Output in your formula, y[n-1] the same as >> PreviousOutput and x[n] is input, n is time index. > > Thanks to all for help. Possibly I could not convey my question > properly. I do not know z- transform and filter design. I am a C > programmer and I need to verify that whether the equation implemented in > code i.e. > > Output = ([1/(2^n -1)]*input) + ([2^n/(2^n -1)] > *PreviousOutput)...........................Eq.1 > > is implementing the 1st order IIR filter whose z - transform function is > > [ 2^-n/(1-(2^-n)) ] > H(z) = > --------------------------------- > .....................................Eq. 2 > [1 - ( (1/ (1- (2^-n)))*Z^-1 )] > where n is filter constant. > > I am sure that Eq.1 is implemented correctly in code. But whether Eq.1 > implements the requirement i.e. Eq.2 or not, is the question. > > So if anybody could help me in deriving Eq.1 from Eq.2, I will deeply > appreciate. > > --Rohit
Does this help? http://www.wescottdesign.com/articles/zTransform/z-transforms.html -- http://www.wescottdesign.com
  - Why it is impossible to have sex in the middle of the Red Square in 
Moscow?

  - Because every idiot bystander will be trying to give you the 
invaluable advice of how to do it.


VLV