From: darren on
I am trying to design in matlab a feedback circuit, however I am struggling with this concept. I have placed my code below for a 2 coefficient IIR filter. The issue is that I get this error:
??? Attempted to access y(2); index out of bounds because numel(y)=1.

Error in ==> Feed_Back_2_Coefficients at 7
y(n)=b(1)*y(n-1) + b(2)*y(n) + a(1)*x(n)+ a(2)*x(n-1)

Could someone please help me as I am going round in circles.

clear all
x = 1;
y = 0;
a=[0.6,0.4]
b=[0,-0.1]
for n=2:4;
y(n)=b(1)*y(n-1) + b(2)*y(n) + a(1)*x(n)+ a(2)*x(n-1)
end
figure(2);stem(y).
From: Jeremy on
"darren " <darrenabrown(a)msn.com> wrote in message <hq7iop$djg$1(a)fred.mathworks.com>...
> I am trying to design in matlab a feedback circuit, however I am struggling with this concept. I have placed my code below for a 2 coefficient IIR filter. The issue is that I get this error:
> ??? Attempted to access y(2); index out of bounds because numel(y)=1.
>
> Error in ==> Feed_Back_2_Coefficients at 7
> y(n)=b(1)*y(n-1) + b(2)*y(n) + a(1)*x(n)+ a(2)*x(n-1)
>
> Could someone please help me as I am going round in circles.
>
> clear all
> x = 1;
> y = 0;
> a=[0.6,0.4]
> b=[0,-0.1]
> for n=2:4;
> y(n)=b(1)*y(n-1) + b(2)*y(n) + a(1)*x(n)+ a(2)*x(n-1)
> end
> figure(2);stem(y).

You're trying to access y(2) when solving for y(2). Even if it got past that, it would hit x(2) and you would have the same error, because you have no value for x(2). This is an implicit problem and you're going to need to solve using a numerical method i believe. Past that, i can't help because i don't know how to solve an implicit equation when two variables are unkown.