Difference Equation in Matlab

Thread Starter

mad12

Joined Oct 9, 2008
11
Hello everyone,

I have a few Matlab problems for my class that I could use some help on. The problem is the following:
Use MATLAB to recursively determine and plot the system output y[n] for 0 <= n <= 30 if the system is described by the difference equation

y[n] = 0.1y[n-1]+0.72y[n-2]+5x[n].

The initial conditions are y[-1] = 1 and y[-2] = -1, and the input is x[n] =d[n] (i.e., the unit impulse). Present the stem plot with labeled horizontal and vertical axes (i.e., n and y[n] respectively). Based on the stem plot, what can you conclude concerning the stability of the system?
Searching around it seemed to me like Matlab could not calculate the y[0] value because it didnt like the 0 index. I havent done Matlab in a while so I'm not sure if that is the case or not. To overcome this, I calculated the y[1] and y[2] values and used these in a for loop. My Matlab m file looked like this:

Rich (BB code):
n=[1:30];
y(1) = 6.16;
y(2) = 8.77;
for m=3:30;
    y(m)=0.1*y(m-1)+.72*y(m-2)+5;
end
stem(n,y,'o')
When I ran this it gave me the attached output. I also noticed it didnt give me the value at 0 as well. I was wondering if someone could help me figure out how to implement this recursively in Matlab, assuming what I have in incorrect. Thanks!
 

Attachments

Last edited:

Thread Starter

mad12

Joined Oct 9, 2008
11
Never mind I figured it out. If anybody is wondering what the solution is, I just had to hand calculate the first 2 y values, and then used these initial values to solve it recursively. My code looked like:

Rich (BB code):
n=[1:30];
y(1) = 4.38;
y(2) = 1.158;
for m=3:30;
    y(m)=0.1*y(m-1)+.72*y(m-2);
end
stem(n,y,'o')
xlabel('n')
ylabel('x[n]')
 
Top