function [p,q] = covar(a,b,c,d,w)
%COVAR  Covariance of LTI model response to white noise inputs.
%
%   P = COVAR(SYS,W) computes the output response covariance P = E[yy'] 
%   when the LTI model SYS is driven by Gaussian white noise inputs w. 
%   The noise intensity W is defined by
%
%      E[w(t)w(tau)'] = W delta(t-tau)  (delta(t) = Dirac delta)
%
%   in continuous time, and by
%
%      E[w(k)w(n)'] = W delta(k,n)  (delta(k,n) = Kronecker delta)
%
%   in discrete time.
%
%   [P,Q] = COVAR(SYS,W) also returns the state covariance Q = E[xx'] when 
%   SYS is a state-space model.
%
%   If SYS is an array of LTI models with size [NY NU S1 ... Sp], the array 
%   P has size [NY NY S1 ... Sp] and
%      P(:,:,k1,...,kp) = COVAR(SYS(:,:,k1,...,kp)) .
%
%   Note: Unstable systems have infinite state and output covariances, and
%   continuous-time systems with nonzero feedthrough have infinite output 
%   covariance.
%
%   See also LYAPCHOL, DLYAPCHOL, LTI.

% Old help
%COVAR  Covariance response of continuous system to white noise.
%   [P,Q] = COVAR(A,B,C,D,W) computes the covariance response of the 
%   continuous state-space system (A,B,C,D) to Gaussian white noise
%   inputs with intensity W,
%
%       E[w(t)w(tau)'] = W delta(t-tau) 
%
%   where delta(t) is the dirac delta.  P and Q are the output and 
%   state covariance responses:
%
%       P = E[yy'];  Q = E[xx'];
%
%   P = COVAR(NUM,DEN,W) computes the output covariance response of 
%   the polynomial transfer function system.  W is the intensity of 
%   the input noise.
%
%   Warning: Unstable systems or systems with a non-zero D matrix have
%   infinite covariance response.
%
%   See also: DCOVAR,LYAP and DLYAP.

%   Clay M. Thompson  7-3-90
%       Revised by Wes Wang 8-5-92
%   Copyright 1986-2009 The MathWorks, Inc.

narginchk(3,5);
if ~((nargin==3)||(nargin==5)), error('Wrong number of input arguments.'); end

% --- Determine which syntax is being used ---
if (nargin == 3) 
  % T.F. syntax
  [num,den] = tfchk(a,b);
  [p,q] = covar(tf(num,den),c);

else
  % State-space syntax
  [msg,a,b,c,d]=abcdchk(a,b,c,d); error(msg);
  [p,q] = covar(ss(a,b,c,d),w);

end

% end covar


