1
votes

In MATLAB, If I've some signal x let say

x = rand(1,1000)

and I want to generate y by filtering x using Autoregressive (AR) filter of order M. How can I find y(n)? as autoregressive filter needs past values of output for calculation, but I don't have any past output yet. I only have input samples x.

In Moving average (MA) filter I can generate y(n) easily because it only needs past inputs which I can provide easily because we have x, as follows

for n=1:1000
  sum=0;
  for k=1:M+1
    if (n-k+1>0)
      sum = sum + (1/M)*x(n-k+1); % MA depends on current & previous input 
    end
  end
  y(n)=sum;
end

Can anyone please help me to generate the same for the Autoregressive filter?

1

1 Answers

1
votes

In the moving average filter you show you are essentially able to compute the output by using the assumption that past input samples before the first provided value in x(1) were zeros.

Similarly, for an autoregressive filter you may compute the output by making the assumption that past outputs before the first computed value y(1) are zeros:

for n=1:1000

  % Add feedforward section for ARMA filter
  % ... for an AR filter this is just sum=x(n)
  sum = x(n);

  % Feedback section      
  for k=2:M+1   % normalized AR (assuming a(1) equals 1) 
    if (n-k+1>0)
      sum = sum + a(k)*y(n-k+1);
    end
  end
  y(n) = sum;
end

More generally, you can also compute the output by seeding the filter with some previous known initial-conditions (though in your particular case you indicate that those initial-conditions aren't known).