0
$\begingroup$

Given the following difference equation

$$y[n]-\left(\dfrac{n}{n+1}\right)y[n-1] = n\cdot x[n]$$

How can we use MATLAB to solve it?

I know if the coefficients are constant we can simply use filter(b, a,x), but not sure how to do it with variable coefficients.

$\endgroup$
3
  • 1
    $\begingroup$ A loop would be a good idea... I mean, you can find $y[n]$ iteratively. $\endgroup$
    – GKH
    Jan 31, 2020 at 5:36
  • $\begingroup$ Thanks, any sample code/algorithm you could recommend? $\endgroup$
    – Morcus
    Jan 31, 2020 at 19:45
  • $\begingroup$ Well, in Octave I would do this: y(1) = -1; x = randn(1,100); for n = 2:100 y(n) = n*x(n) + (n/(n+1))*y(n-1); end $\endgroup$
    – GKH
    Jan 31, 2020 at 21:03

1 Answer 1

1
$\begingroup$

When $n=0$ you may need to know $y[-1]$. The current output $y(n)$ depends on the current input $x(n)$ and previous output $y(n-1)$ scaled.

$\endgroup$
3
  • $\begingroup$ Suppose I know that, How would I go about solving the system. I think that is my question. $\endgroup$
    – Morcus
    Jan 31, 2020 at 19:45
  • $\begingroup$ The input sequence $x[n]$ is known then $y[n]$ can be computed with $$y[n]= n\cdot x[n] + \left(\dfrac{n}{n+1}\right)y[n-1]$$ when $n=0$ use $y[-1]$ if available otherwise $y[-1]=0$ Do you need a MATLAB code example to solve above problem? But, I guess its not that complicated to implement. $\endgroup$
    – jomegaA
    Jan 31, 2020 at 19:51
  • $\begingroup$ Well for $n=0;\, y[0] = 0$ nevertheless. $\endgroup$
    – jomegaA
    Jan 31, 2020 at 19:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.