function z = armasim(phi,theta,n)
% ARMASIM(PHI,THETA,N) generates N observations from the
%   ARMA model specified by PHI, THETA
% It "burns in" with the 1st 200 observations
[p m] = size(phi);
[q m] = size(theta);
n1 = 200+n;
a = normrnd(0,1,n1+q,1);
z = zeros(p,1);
for i=1:n1
   zt = z(i:(i+p-1))'*phi(p:-1:1)+a(i+q)-a(i:(i+q-1))'*theta(q:-1:1);
   z = [ z ; zt ];
end
z = z((201+p):(n1+p));