function [G,PV]=trfsd(th,nnu,w,nny)
%TRFSD	Computes a model's frequency function,along with its standard deviation
%
%	G = trfsd(TH)  or  [G,NSP] = trfsd(TH)
%
%	TH: A matrix defining a model, as described in HELP THETA
%	G is returned as the transfer function estimate, and NSP (if specified)
%	as the noise spectrum, corresponding to the model TH. These matrices
%	contain also estimated standard deviations, calculated from the
%	covariance matrix in TH, and are  of the standard frequency function
%	format (see HELP FREQFUNC).If TH describes a time series, G is returned
%	as its spectrum.
%	
%	If the model TH has several inputs, G will be returned as the transfer
%	functions of selected inputs # j1 j2 .. jk by 
%	G = trfsd(TH,[j1 j2 ... jk])  [default is all inputs]. The functions 
%	are computed at 128 equally spaced frequency-values between 0(excluded)
%	and pi/T, where T is the sampling interval specified by TH. The func-
%	tions can be computed at arbitrary frequencies w (a row vector, gene-
%	rated e.g. by LOGSPACE) by G = th2ff(TH,ku,w). The transfer function
%	can be plotted by BODEPLOT. bodeplot(trfsd(TH),sd) is a possible 
%	construction. If the model TH has several outputs, G will be returned
%	as the frequency function at selected outputs ky (a row vector) by
%	G=trf(TH,ku,w,ky); (Default is all outputs).

%	L. Ljung 7-7-87, 3-25-89
%	Copyright (c) 1986-95 by the MathWorks, Inc.
%	$Revision: 1.2 $  $Date: 1995/01/24 00:54:03 $
 
T=gett(th);

% *** Set up default values ***
if nargin<4, nny=[];end
if nargin<3, w=[];end
if nargin<2 , nnu=[];end
if T>0,wdef=pi*[1:128]/128/T;
else wdef=logspace(log10(pi/abs(T)/100),log10(10*pi/abs(T)),128);end

if isempty(w),w=wdef;end
if length(w)==1, if w<0, w=wdef;end,end
if isempty(nnu),nnu=1:th(1,3);end
if nargout==1, G=th2ff(th,nnu,w,nny);else [G,PV]=th2ff(th,nnu,w,nny);end
