Why this Matlab code not work

Status
Not open for further replies.

garimella

Full Member level 5
Joined
Aug 25, 2011
Messages
260
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
3,276
I have an array(arry(k)) that contains the sampled waveform. All that I am trying to do is to subject the array data to 2nd order IIR HPF and store the result in another array. But I am getting error when running the matlab code. What could be the problem?

Code:
b0=0.9693;
b1=-1.9386;
b2=0.9693;
a1=-1.9381;
a2=0.9390;

for k=1:16
y=b0*arry(k)+b1*x1+b2*x2-a1*y1-a2*y2;
y1=y;
y2=y1;
x2=x1;
x1=arry(k);
filt_arry(k)=y;    
end

error:
Undefined function or variable 'x1'.
 

You are using the 'x1' variable whth no previous assignment.
Provide an initial value prior getting in the for...end loop
 

Oh.. silly me. It works
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…