%
% Generate coloured noises
%
%         y = noise( n, a, c )
%
% where  y = column vector of noise
%        n = number of points
%        a = coefficients for lagged output
%        c = coefficients for lagged white noise
%
% Bob Newell, Feb 1996
%
%----------------------------------------------------
%
function y = noise( n, a, c )
% 
%----------------------------------------------------
% white noise
nw = length( c );
ny = length( a );
w = randn( n+nw+ny, 1 );
% coloured noise
y = zeros( n+ny, 1 );
for k = ny+1:ny+n,
  for i = 1:ny,
    y(k) = y(k) + a(i) * y(k-i);
  end;
  y(k) = y(k) + w(k);
  for i = 1:nw,
    y(k) = y(k) + c(i) * w(k-i);
  end;
end;
% truncate starting points
y = y(ny+1:ny+n);
return;
%---------------------------------------------------
% the end
