# Steady State of a Difference Equation using MATLAB

I'm given this difference equation, and I'm being asked to plot its response to an input $x[n] = 4\sin^3\left(0.25\pi n+\frac \pi 3\right)u(n)$:

$$y(n) = 0.9051y(n-1)-0.598y(n-2)+0.29y(n-3)-0.1958y(n-4)+0.207x(n)+0.413x(n-2)+0.207x(n-4)$$

Using MATLAB's filter function, I implemented the following code:

num = [1 -0.9051 0.598 -0.29 0.1958];
den = [0.207 0 0.413 0 0.207];
x = 0:75; b1 = sin(0.25*pi*x+pi/3);
for i = 1:length(b1) sincub(i) = b1(i)*b1(i)*b1(i); end
inp = 4*sincub; z = filtic(num, den, [0 0 0 0]);
y = filter(num, den, inp, z);
stem(x, y, 'linewidth', 2);grid on
xlabel('Time-index, n'); ylabel('Amplitude'); title('Response to x(n)');


The plot of the input function is attached and so is the response.

The problem I'm facing is that I'm being asked to find the steady-state value of the output when the output appears rather periodic in nature (if x = 1:100 or 1:200 this will be clearer). Where is the transient response in such an output and what can be the steady state? Or is there something wrong in my code?

Any help would be much appreciated.

• Your numerator is actually your denominator and vice versa. Jun 8, 2017 at 6:13
• @Matt_L. is right. You have your filter coefficient vectors wrong. Switch numerator and denominator. Jun 8, 2017 at 17:10

Given the trig identities you can rewrite your input as $$x(t) = 3\cdot \sin(0.25\cdot \pi \cdot t+ \pi/3) - \sin(0.75\cdot \pi \cdot t+ \pi)$$
So it's just two sine wave going in, so it will be two sine waves coming out. You could potentially calculate the value of the transfer function $\omega = 0.25 \pi$ and $\omega = 0.75 \pi$ and manually calculate the output this way.