Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Analog to IIR equations

Status
Not open for further replies.

bubulescu

Member level 3
Joined
Sep 10, 2009
Messages
65
Helped
12
Reputation
24
Reaction score
12
Trophy points
1,288
Activity points
1,897
Hello

I am trying to get to a general solution for transforming H(s) to H(z), in terms of V(out)=f( V(in) ), I am using wxMaxima as a help and LTspice for implementation. Here's what I did:

\[ H(s) = \frac{a_{2} s^{2} + a_{1} s + a_{0}}{b_{2} s^{2} + b_{1} s + b_{0}} \]
\[ Z = \frac{1-z^{-1}}{1+z^{-1}} \]
\[ \omega_{D} = tan \left( \pi \frac{f_{p}}{f_{0}} \right) \]

Here's what wxMaxima gave me as a result for H(Z/wD), after simplification (b2=1):

\[ H(z) = \frac{ \left( a_{0} \omega_{D}^{2} - a_{1} \omega_{D} + a_{2} \right) z^{-2}
+ 2 \left( a_{0} \omega_{D}^{2} - a_{2} \right) z^{-1} + \left( a_{0} \omega_{D}^{2} + a_{1} \omega_{D} + a_{2} \right) }
{ \left( b_{0} \omega_{D}^{2} - b_{1} \omega_{D} + 1 \right) z^{-2}
+ 2 \left( b_{0} \omega_{D}^{2} - 1 \right) z^{-1} + \left( b_{0} \omega_{D}^{2} + b_{1} \omega_{D} + 1 \right) } \]

Which is the known general Z bilinear transform:

\[ H(z) = \frac{ A_{2} z^{-2} + A_{1} z^{-1} + A_{0} } { - B_{2} z^{-2} - B_{1} z^{-1} + 1 } \]

From this, V(out) can be expressed as:

\[ V(out) = \frac{1}{B_{0}}\left( A_{2} z_{in}^{-2} + A_{1} z_{in}^{-1} + A_{0} v(in) + B_{2} z_{out}^{-2} + B_{1} z_{out}^{-1} \right) \]

where z_in and z_out are the delays of the V(in) and V(out). This can be easily implemented in LTspice using a behavioural source with the function delay(x,y) (= delay x by y) where x can be either V(in) or V(out), and that's how I implemented it, but I am getting strange results, not at all what I would expect. For example, here's a comparison of an 8th order analog Butterworth filter -- V(out) -- and its IIR counterpart -- V(outD) -- as they appear after simulation for fp=1Hz and f0=7Hz (random value):
Screenshot1.png

The functions are implemented exactly as you see them above. Since I don't expect LTspice to give wrong results, my question is: is there something wrong in my calculations? If yes, can someone please correct me? This is no homework, exam, etc, it's meant to be an IIR filter I am doing in LTspice.


Anticipated thanks,
Vlad
 

perhaps you forgot a factor "2" in the transform from s to z:

s = 2•(1-\[{ z}^{-1 }\])/(1+\[{ z}^{-1 }\])
 

Hello

And thank you for the reply. I'm afraid that is not it, since I am already using prewarping and then replacing "s" with the "Z/wD" from above.
 

Well, I found the culprit, it was my hand which put ** instead of *, making it a raise to power operation instead of a simple multiplication. Good, it worked, but only for an order of 2, prowdly shown below:
Screenshot1.png

The green waveform -- V(outD) -- is (obviously) the digital output, while the red one is the reference, 2nd order Butterworth. This is achieved by having the following equation passed on to the behavioural source:

H(z) = ( A0*v(in) + A1*dx(ts) + A2*dx(2*ts) - B1*dy(ts) - B2*dy(2*ts) ) / B0

where dx(), dy() are the delays of the v(in) -- x -- or the v(out) -- y -- signals by the sampling time ts. Let's say that, for a second order equation, it's H(1), for a 4th order, H(2), and so on. So, if I wanted a 4th order filter, then I would have to pass H(1)*H(2), but look what happens if I do that:
Screenshot2.png

The above is for a 4th order Butterworth, the red trace being the reference. I thought it's because when multiplying the delays, it doesn't act as on paper, z-1 -> z-2, since this is done analogic, so a different approach was needed.

At first, I thought I'd do this with only one behavioural source which will have as many H(x) as needed, but now it's obvious there should be one for each 2nd order and the second source would have the first one's output as input, and so on. I'm having difficulties for odd orders, but now I'm on the right track, so to speak. I'll mark this as solved and end with a screenshot of a working 4th order Butterworth:
Screenshot3.png
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top