function thn=sett(th,T);
%SETT	Sets the sampling interval in TH-structures and frequency functions.
%	THN = sett(TH,T)  or GN = sett(G,T)
%
%	TH:  The original model in THETA-format
%	T:   The sampling interval
%	THN: The new model in THETA-format, with sampling interval T 
%	or
%	G:   The original frequency function
%	GN:  The frequency function with frequencies scaled according to
%	     the desired sampling interval
%	For frequency functions SETT works only for functions generated by 
%	(see also) SPA, ETFE, TH2FF, or TRF, with a default choice of 
%	frequencies. See also FREQFUNC.

%	L. Ljung 10-2-90
%       Revised 21-4-91
%	Copyright (c) 1986-95 by the MathWorks, Inc.
%	$Revision: 1.4 $  $Date: 1995/05/16 09:01:05 $

if nargin<2
   disp('Usage: THN = SETT(TH,T)')
   return
end

[nr,nc]=size(th);thn=th;
if nr==129
	test=rem(th(1,:),1000); tt=test(1);
	if floor(tt)==tt & tt>=100 & tt<=119 %Then we have freqfunc case
	freqind=find(test>=100);
	spind=find(test==0);sdind=find(test==50);frspind=find(test==100);
	Tcurrent=(ones(1,length(freqind))*pi)./th(129,freqind);
	Tspc=(ones(1,length(frspind))*pi)./th(129,frspind);
	thn(2:129,freqind)=thn(2:129,freqind).*(ones(128,1)*Tcurrent)/T;
	if ~isempty(spind)
	  thn(2:129,spind)=thn(2:129,spind)./(ones(128,1)*Tspc)*T;
	end
	if ~isempty(sdind)
	  thn(2:129,sdind)=thn(2:129,sdind)./(ones(128,1)*Tspc)*T;
	end
end,else
if isthss(th),if any(th(2,8)==[1 5]),thn(1,2)=-abs(T);else thn(1,2)=T;end,
else
thn(1,2)=T;
end
end
