+ Post New Thread
Results 1 to 3 of 3
  1. #1
    Full Member level 4
    Points: 2,304, Level: 11
    Achievements:
    7 years registered

    Join Date
    Aug 2011
    Posts
    193
    Helped
    0 / 0
    Points
    2,304
    Level
    11

    Why this Matlab code not work

    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'.

    •   AltAdvertisement

        
       

  2. #2
    Super Moderator
    Points: 29,619, Level: 41
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,858
    Helped
    1114 / 1114
    Points
    29,619
    Level
    41
    Blog Entries
    9

    Re: Why this Matlab code not work

    You are using the 'x1' variable whth no previous assignment.
    Provide an initial value prior getting in the for...end loop
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



    •   AltAdvertisement

        
       

  3. #3
    Full Member level 4
    Points: 2,304, Level: 11
    Achievements:
    7 years registered

    Join Date
    Aug 2011
    Posts
    193
    Helped
    0 / 0
    Points
    2,304
    Level
    11

    Re: Why this Matlab code not work

    Oh.. silly me. It works



--[[ ]]--