Finding the closed form of a recursive LTI system

Click For Summary
SUMMARY

The forum discussion focuses on finding the closed form of the impulse response for the recursive linear time-invariant (LTI) system defined by the equation y[n] = 7y[n-1] - 12y[n-2] + x[n]. The user successfully derived the closed form y[n] = 4*4^n - 3*3^n using Python code for calculating the outputs and residuals. However, they encountered oscillating ratios of residuals when n exceeds 127, which they attributed to numerical precision issues in Python when handling large integers. The discussion also touches on the discrepancies between the theoretical model and the implemented code.

PREREQUISITES
  • Understanding of linear difference equations and their solutions.
  • Familiarity with Python programming, particularly recursion and memoization.
  • Knowledge of Z-Transforms and partial fraction decomposition.
  • Concept of impulse response in linear systems.
NEXT STEPS
  • Study the application of Z-Transforms in solving difference equations.
  • Learn about numerical stability and precision in Python, especially with large integers.
  • Explore the concept of impulse response in more detail, particularly in LTI systems.
  • Investigate the use of Python libraries for symbolic mathematics, such as SymPy, for solving equations analytically.
USEFUL FOR

Students and professionals in electrical engineering, control systems, and applied mathematics who are working with recursive systems and impulse responses. Additionally, Python developers interested in numerical methods and algorithm optimization will find this discussion beneficial.

kostoglotov
Messages
231
Reaction score
6

Homework Statement



Find the closed form of the impulse response of the system y[n] = 7y[n-1]-12y[n-2]+x[n] using the peel away and guess method. Ie, by using Python code to find the geometric ratios and amplitudes of the outputs as n grows large, then calculate residuals, and find the geometric ratios and amplitudes of the residuals, and so on.

Homework Equations

The Attempt at a Solution


[/B]
This is the code:

Code:
memo = {}
def f(n):
     if n <= 0: return 1.0
     if n == 1: return 7.0
     if n in memo: return memo[n]
     memo[n] = 7*f(n-1) - 12*f(n-2)
    return memo[n]
# residual
def g(n):
    return f(n) - 4*4**n

for i in range(1,500):
    print i, ": ", f(i)
    # this closed form found from transfer function
    print i, ": ", 4*4**i - 3*3**i

I was able to find an exact matching closed form for the system from performing partial fraction decomposition on the transfer function H(z) and then doing inverse Z-Transform on that...but I did this as a last resort.

My problem was that when I check the ratio of the residuals, when n gets above 127, the ratios of the residuals don't stabilize, they oscillate.

This code:

Code:
for i in range(1,500):
    print i, ": ", g(i)/g(i-1)

produces this output at large n:

CTukJxO.png


imgur link: https://i.imgur.com/CTukJxO.png

I spent a long time trying to reconcile this in a closed form. As you can see, this pattern goes 4*1.05^{-1}, 4*1.05^0, 4*1.05^1, 4*1.05^0,.... This seemed very messy.

Of course, the real closed form is simple enough when figured out from the transfer function, it's y[n]= 4*4^n - 3*3^n.

And below n = 127, the ratio of the residuals seems to want to settle around 3, so guessing 3 at that point would be fine.

Why are the residuals oscillating like that? Why doesn't it affect or appear in the actual closed form? How would one go about making a judgement on which value for the geometric ratio of the residuals to guess? If I had kept going with the later oscillating ratios of the residuals, wouldn't I have to introduce imaginary numbers?
 
Physics news on Phys.org
kostoglotov said:

Homework Statement



Find the closed form of the impulse response of the system y[n] = 7y[n-1]-12y[n-2]+x[n] using the peel away and guess method. Ie, by using Python code to find the geometric ratios and amplitudes of the outputs as n grows large, then calculate residuals, and find the geometric ratios and amplitudes of the residuals, and so on.

I'm unfamiliar with the "signals and systems" approach to difference equations. From glancing at the notes

https://ocw.mit.edu/courses/electri...tems-fall-2011/readings/MIT6_003F11_chap2.pdf

https://ocw.mit.edu/courses/electri...tems-fall-2011/readings/MIT6_003F11_chap4.pdf

you are working exercise 23 of chapter 4.

If I assume ##x[n] = 0## and consider the problem as a homogeneous linear recurrence relation with constant coefficients (https://en.wikipedia.org/wiki/Recur...currence_relations_with_constant_coefficients )

Then we have the difference equation ## a[n] = 7 a[n-1] - 12 a[n-2] ##
This has characteristic polynomial ## p(t) = t^2 - 7t + 12 = (t-4)(t-3) ##
Which gives the general solution ## a[n] = k_14^n + k_23^n ##

So I don't understand how the ## 4^i - 3^i## in your code reconciles with the your initial condition ## f[1] = 7 ##, which, in my notation would be ##a[1] = 7 ##. To get ##a[1] = 7##, I would use ## k_1 = k_2 = 1## instead of ##k_1 = 1, k_2 = -1 ##.
 
kostoglotov said:

Homework Statement



Find the closed form of the impulse response of the system y[n] = 7y[n-1]-12y[n-2]+x[n] using the peel away and guess method. Ie, by using Python code to find the geometric ratios and amplitudes of the outputs as n grows large, then calculate residuals, and find the geometric ratios and amplitudes of the residuals, and so on.
Above, your equation is ##y[n] = 7y[n-1]-12y[n-2]+x[n]##, but your code below uses ##y[n] = 7y[n-1]-12y[n-2]##; i.e., no x[n] term. Why do you have this descrepancy?
kostoglotov said:

Homework Equations

The Attempt at a Solution


[/B]
This is the code:

Code:
memo = {}
def f(n):
     if n <= 0: return 1.0
     if n == 1: return 7.0
     if n in memo: return memo[n]
     memo[n] = 7*f(n-1) - 12*f(n-2)
    return memo[n]
# residual
def g(n):
    return f(n) - 4*4**n

for i in range(1,500):
    print i, ": ", f(i)
    # this closed form found from transfer function
    print i, ": ", 4*4**i - 3*3**i

I was able to find an exact matching closed form for the system from performing partial fraction decomposition on the transfer function H(z) and then doing inverse Z-Transform on that...but I did this as a last resort.

My problem was that when I check the ratio of the residuals, when n gets above 127, the ratios of the residuals don't stabilize, they oscillate.

This code:

Code:
for i in range(1,500):
    print i, ": ", g(i)/g(i-1)

produces this output at large n:

CTukJxO.png


imgur link: https://i.imgur.com/CTukJxO.png

I spent a long time trying to reconcile this in a closed form. As you can see, this pattern goes 4*1.05^{-1}, 4*1.05^0, 4*1.05^1, 4*1.05^0,.... This seemed very messy.

Of course, the real closed form is simple enough when figured out from the transfer function, it's y[n]= 4*4^n - 3*3^n.

And below n = 127, the ratio of the residuals seems to want to settle around 3, so guessing 3 at that point would be fine.

Why are the residuals oscillating like that? Why doesn't it affect or appear in the actual closed form? How would one go about making a judgement on which value for the geometric ratio of the residuals to guess? If I had kept going with the later oscillating ratios of the residuals, wouldn't I have to introduce imaginary numbers?
I believe the numbers you are seeing result from doing arithmetic on very large numbers, too large for the computer to represent exactly.
For example, when i = 46, f(i) is approx. 1.98 X 10^28, and 4 * 4 ^ 46 is a 29-digit number. For larger i, the values get even larger. From about i = 121, the ratio of the residuals are probably at the limit of the computer's ability to do precise division, which, I believe, leads to the oscillation that you're seeing.
 
  • Like
Likes   Reactions: kostoglotov
If Mark44 is correct, you might try setting your initial conditions to 1 and 7 rather than 1.0 and 7.0. Python has a built in big integer class that I think it will use if you do that.
 
  • Like
Likes   Reactions: kostoglotov
Mark44 said:
Above, your equation is ##y[n] = 7y[n-1]-12y[n-2]+x[n]##, but your code below uses ##y[n] = 7y[n-1]-12y[n-2]##; i.e., no x[n] term. Why do you have this descrepancy?

The x[n] is there as an impulse at time 0 and 1, at t = 0 the impulse is 1 and t = 1 the impulse is 7.

Code:
if n <= 0: return 1.0
if n == 1: return 7.0
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
2
Views
5K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K