DSPRelated.com
Forums

Analog to digital IIR filter

Started by Bhaskar Thiagarajan May 4, 2006
Hi all

I know this topic has been discussed at several levels in this group before.
Tim Wescott even worked out a similar scenario with me a few months
back...but either I'm really bad at algaebra or I'm missing something. I'd
appreciate if some of you can help me find the problem

My goal is to model a simple 'charge' circuit using a digital filter.
In the time domain, I guess you can describe this circuit as
Vout = Vin*(1-exp^(-t/T)), where T is the time constant, Vin is the input
voltage, Vout is output voltage.

When t=T, you'd expect Vout = 0.632*Vin

To convert this to a filter, let's start with the time domain response of
this block as
h(t) = 1-exp^(-at), where a = 1/T

In the Laplace domain, this would be
H(s) =    a
      ---------
       s(s+a)

The unit step response in the Laplace domain is
H_s(s) =   a
        ---------
         s^2(s+a)

This can also be written as

H_s(s) =   1        1
        ------- - ------ 
          s^2      s(s+a)

From Laplace Tables,
h_s(t) = t - (1/a)(1 - exp^-at)

Let exp^-at = d

From Z transform tables at a sample interval of Ts

H_s(z) =   z   * (   Ts   -   (1-d)  )
         -----     ------    -------
          z-1       z-1       a(z-d)

H(z) =  (   Ts   -   (1-d)  )
          ------    -------
           z-1       a(z-d)

Expanding this out (errors here??)

H(z) =    (Ts - (1/a) + (d/a))z^-1 + (-dTs + (1/a) - (d/a))z^-2
          ----------------------------------------------------
               1 - (1+d)z^-1 + dz^-2


Using matlab conventions
b0 = 0
b1 = (Ts - (1/a) + (d/a))
b2 = (-dTs + (1/a) - (d/a))
a0 = 1
a1 = -(1+d)
a2 = d

If I then choose fs = 100e3 (Ts=100e-3) and time constant for the charging
circuit as 1e-3 (a=1e3), plug the above numbers and examine the step
response of this filter in matlab, I'd expect to see it reach 0.632 at the
sample matching 1e-3 secs. However, I see it the response rise monotonically
and doesn't even come close to what I expect.

I'd done some work on this earlier and my earlier simulation used these
expressions...which seems to have a response that comes close to what I
expect
b0 = 0
b1 = -(T - 1 + d)
b2 = -(-Td + 1 - d)
a0 = 1
a1 = -(1+d)
a2 = d

Notice that the b1 and b2 are essentially the same but don't have a factor
of 1/a...but also have a sign reversal. I can't seem to justify why this
would come close but my current math doesn't.

I'd appreciate any tips in the right direction

BTW, The last time I used Rick Lyons' book for this process, I didn't get
meaningful answers. I might try that again for this problem and see where it
leads me.

Cheers
Bhaskar











Bhaskar Thiagarajan wrote:
> Hi all > > I know this topic has been discussed at several levels in this group before. > Tim Wescott even worked out a similar scenario with me a few months > back...but either I'm really bad at algaebra or I'm missing something. I'd > appreciate if some of you can help me find the problem > > My goal is to model a simple 'charge' circuit using a digital filter. > In the time domain, I guess you can describe this circuit as > Vout = Vin*(1-exp^(-t/T)), where T is the time constant, Vin is the input > voltage, Vout is output voltage. > > When t=T, you'd expect Vout = 0.632*Vin > > To convert this to a filter, let's start with the time domain response of > this block as > h(t) = 1-exp^(-at), where a = 1/T > > In the Laplace domain, this would be > H(s) = a > --------- > s(s+a) > > The unit step response in the Laplace domain is > H_s(s) = a > --------- > s^2(s+a) > > This can also be written as > > H_s(s) = 1 1 > ------- - ------ > s^2 s(s+a) > > From Laplace Tables, > h_s(t) = t - (1/a)(1 - exp^-at) > > Let exp^-at = d > > From Z transform tables at a sample interval of Ts > > H_s(z) = z * ( Ts - (1-d) ) > ----- ------ ------- > z-1 z-1 a(z-d) > > H(z) = ( Ts - (1-d) ) > ------ ------- > z-1 a(z-d) > > Expanding this out (errors here??) > > H(z) = (Ts - (1/a) + (d/a))z^-1 + (-dTs + (1/a) - (d/a))z^-2 > ---------------------------------------------------- > 1 - (1+d)z^-1 + dz^-2 > > > Using matlab conventions > b0 = 0 > b1 = (Ts - (1/a) + (d/a)) > b2 = (-dTs + (1/a) - (d/a)) > a0 = 1 > a1 = -(1+d) > a2 = d > > If I then choose fs = 100e3 (Ts=100e-3) and time constant for the charging > circuit as 1e-3 (a=1e3), plug the above numbers and examine the step > response of this filter in matlab, I'd expect to see it reach 0.632 at the > sample matching 1e-3 secs. However, I see it the response rise monotonically > and doesn't even come close to what I expect. > > I'd done some work on this earlier and my earlier simulation used these > expressions...which seems to have a response that comes close to what I > expect > b0 = 0 > b1 = -(T - 1 + d) > b2 = -(-Td + 1 - d) > a0 = 1 > a1 = -(1+d) > a2 = d > > Notice that the b1 and b2 are essentially the same but don't have a factor > of 1/a...but also have a sign reversal. I can't seem to justify why this > would come close but my current math doesn't. > > I'd appreciate any tips in the right direction > > BTW, The last time I used Rick Lyons' book for this process, I didn't get > meaningful answers. I might try that again for this problem and see where it > leads me.
You're designing an impulse-invariant filter. They only work as expected at a small fraction of the sample frequency. The matter of the signs depends on the conventions used by the function you use to plot the frequency response. You just have to go with the way it's written. If you write your own, you know. Is it worth the trouble? At least that's what I think. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Bhaskar Thiagarajan wrote:

> Hi all > > I know this topic has been discussed at several levels in this group before. > Tim Wescott even worked out a similar scenario with me a few months > back...but either I'm really bad at algaebra or I'm missing something. I'd > appreciate if some of you can help me find the problem > > My goal is to model a simple 'charge' circuit using a digital filter. > In the time domain, I guess you can describe this circuit as > Vout = Vin*(1-exp^(-t/T)), where T is the time constant, Vin is the input > voltage, Vout is output voltage. > > When t=T, you'd expect Vout = 0.632*Vin > > To convert this to a filter, let's start with the time domain response of > this block as > h(t) = 1-exp^(-at), where a = 1/T > > In the Laplace domain, this would be > H(s) = a > --------- > s(s+a) > > The unit step response in the Laplace domain is > H_s(s) = a > --------- > s^2(s+a) > > This can also be written as > > H_s(s) = 1 1 > ------- - ------ > s^2 s(s+a) > > From Laplace Tables, > h_s(t) = t - (1/a)(1 - exp^-at) > > Let exp^-at = d > > From Z transform tables at a sample interval of Ts > > H_s(z) = z * ( Ts - (1-d) ) > ----- ------ ------- > z-1 z-1 a(z-d) > > H(z) = ( Ts - (1-d) ) > ------ ------- > z-1 a(z-d) > > Expanding this out (errors here??) > > H(z) = (Ts - (1/a) + (d/a))z^-1 + (-dTs + (1/a) - (d/a))z^-2 > ---------------------------------------------------- > 1 - (1+d)z^-1 + dz^-2 > > > Using matlab conventions > b0 = 0 > b1 = (Ts - (1/a) + (d/a)) > b2 = (-dTs + (1/a) - (d/a)) > a0 = 1 > a1 = -(1+d) > a2 = d > > If I then choose fs = 100e3 (Ts=100e-3) and time constant for the charging > circuit as 1e-3 (a=1e3), plug the above numbers and examine the step > response of this filter in matlab, I'd expect to see it reach 0.632 at the > sample matching 1e-3 secs. However, I see it the response rise monotonically > and doesn't even come close to what I expect. > > I'd done some work on this earlier and my earlier simulation used these > expressions...which seems to have a response that comes close to what I > expect > b0 = 0 > b1 = -(T - 1 + d) > b2 = -(-Td + 1 - d) > a0 = 1 > a1 = -(1+d) > a2 = d > > Notice that the b1 and b2 are essentially the same but don't have a factor > of 1/a...but also have a sign reversal. I can't seem to justify why this > would come close but my current math doesn't. > > I'd appreciate any tips in the right direction > > BTW, The last time I used Rick Lyons' book for this process, I didn't get > meaningful answers. I might try that again for this problem and see where it > leads me. > > Cheers > Bhaskar >
Jerry's comments, plus: Your 'simple charge circuit' is probably a first-order lowpass, with a transfer function of a H(s) = ----- s + a The time domain response that you gave, V_o(t) = V_i (1 - exp(a*t)), is correct for the step response of the above filter, but it is _not_ the correct transfer function. Your problem was confusing a signal (the step response) with a transfer function. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Posting from Google? See http://cfaj.freeshell.org/google/ "Applied Control Theory for Embedded Systems" came out in April. See details at http://www.wescottdesign.com/actfes/actfes.html
"Bhaskar Thiagarajan" <bhaskart@deja.com> wrote in message 
news:W9x6g.66569$_S7.29006@newssvr14.news.prodigy.com...

> > My goal is to model a simple 'charge' circuit using a > digital filter. > In the time domain, I guess you can describe this circuit > as > Vout = Vin*(1-exp^(-t/T)), where T is the time constant, > Vin is the input > voltage, Vout is output voltage. > > When t=T, you'd expect Vout = 0.632*Vin >
I suspect you are looking for an "impulse-invariant" transformation. The transformation for a first-order system is fairly simple. From your starting point, let a=(Vout/Vin), and let T = (1/Fs), where Fs is the sampling frequency. From Gold and Rader, "Digital Processing of Signals": a a ------- => ----------------------- s + a 1 - exp(-aT) * z^(-1) The authors go on to say that "System functions of various resonant circuits may be expanded by partial fractions leading to the correspondences ..." and then they go on to show a couple of second-order transformations. Notice that for the continuous filter at s=0, the gain is 1, while for the digital filter at z=1, the gain is not 1, but depends on the relationship between the -3dB frequency in the continuous domain and the sampling frequency.
"Tim Wescott" <tim@seemywebsite.com> wrote in message
news:PLqdncYLToi6ecfZnZ2dnUVZ_smdnZ2d@web-ster.com...
> Bhaskar Thiagarajan wrote: > > > Hi all > > > > I know this topic has been discussed at several levels in this group
before.
> > Tim Wescott even worked out a similar scenario with me a few months > > back...but either I'm really bad at algaebra or I'm missing something.
I'd
> > appreciate if some of you can help me find the problem > > > > My goal is to model a simple 'charge' circuit using a digital filter. > > In the time domain, I guess you can describe this circuit as > > Vout = Vin*(1-exp^(-t/T)), where T is the time constant, Vin is the
input
> > voltage, Vout is output voltage. > > > > When t=T, you'd expect Vout = 0.632*Vin > > > > To convert this to a filter, let's start with the time domain response
of
> > this block as > > h(t) = 1-exp^(-at), where a = 1/T > > > > In the Laplace domain, this would be > > H(s) = a > > --------- > > s(s+a) > > > > The unit step response in the Laplace domain is > > H_s(s) = a > > --------- > > s^2(s+a) > > > > This can also be written as > > > > H_s(s) = 1 1 > > ------- - ------ > > s^2 s(s+a) > > > > From Laplace Tables, > > h_s(t) = t - (1/a)(1 - exp^-at) > > > > Let exp^-at = d > > > > From Z transform tables at a sample interval of Ts > > > > H_s(z) = z * ( Ts - (1-d) ) > > ----- ------ ------- > > z-1 z-1 a(z-d) > > > > H(z) = ( Ts - (1-d) ) > > ------ ------- > > z-1 a(z-d) > > > > Expanding this out (errors here??) > > > > H(z) = (Ts - (1/a) + (d/a))z^-1 + (-dTs + (1/a) - (d/a))z^-2 > > ---------------------------------------------------- > > 1 - (1+d)z^-1 + dz^-2 > > > > > > Using matlab conventions > > b0 = 0 > > b1 = (Ts - (1/a) + (d/a)) > > b2 = (-dTs + (1/a) - (d/a)) > > a0 = 1 > > a1 = -(1+d) > > a2 = d > > > > If I then choose fs = 100e3 (Ts=100e-3) and time constant for the
charging
> > circuit as 1e-3 (a=1e3), plug the above numbers and examine the step > > response of this filter in matlab, I'd expect to see it reach 0.632 at
the
> > sample matching 1e-3 secs. However, I see it the response rise
monotonically
> > and doesn't even come close to what I expect. > > > > I'd done some work on this earlier and my earlier simulation used these > > expressions...which seems to have a response that comes close to what I > > expect > > b0 = 0 > > b1 = -(T - 1 + d) > > b2 = -(-Td + 1 - d) > > a0 = 1 > > a1 = -(1+d) > > a2 = d > > > > Notice that the b1 and b2 are essentially the same but don't have a
factor
> > of 1/a...but also have a sign reversal. I can't seem to justify why this > > would come close but my current math doesn't. > > > > I'd appreciate any tips in the right direction > > > > BTW, The last time I used Rick Lyons' book for this process, I didn't
get
> > meaningful answers. I might try that again for this problem and see
where it
> > leads me. > > > > Cheers > > Bhaskar > > > Jerry's comments, plus: > > Your 'simple charge circuit' is probably a first-order lowpass, with a > transfer function of > > a > H(s) = ----- > s + a > > The time domain response that you gave, > > V_o(t) = V_i (1 - exp(a*t)), > > is correct for the step response of the above filter, but it is _not_ > the correct transfer function. > > Your problem was confusing a signal (the step response) with a transfer > function.
Thanks for setting me straight Tim (and the other responders as well). I knew I was doing something wrong (last time I checked, a first order low pass didn't end up with a complicated 2nd order IIR filter in the digital domain). Cheers Bhaskar