home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
octa21eb.zip
/
octave
/
SCRIPTS.ZIP
/
scripts.fat
/
control
/
tf2sys.m
< prev
next >
Wrap
Text File
|
1999-04-29
|
4KB
|
119 lines
# Copyright (C) 1996,1998 A. Scottedward Hodel
#
# This file is part of Octave.
#
# Octave is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any
# later version.
#
# Octave is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with Octave; see the file COPYING. If not, write to the Free
# Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
function outsys = tf2sys(num,den,tsam,inname,outname)
#
# sys = tf2sys(num,den{,tsam,inname,outname})
# build system data structure from transfer function format data
# inputs:
# num, den: coefficients of numerator/denominator polynoms
# tsam: sampling interval. default: 0 (continuous time)
# inname, outname: input/output signal names (string variables)
# outputs: sys = system data structure
# Written by R. Bruce Tenison July 29, 1994
# Name changed to TF2SYS July 1995
# updated for new system data structure format July 1996
save_val = implicit_str_to_num_ok;
implicit_str_to_num_ok = 1;
# Test for the correct number of input arguments
if ((nargin < 2) || (nargin > 5))
usage('outsys=tf2sys(num,den[,tsam,inname,outname])');
return
endif
# check input format
if( ! ( (is_vec(num) || is_scal(num)) && ...
(is_vec(den) || is_scal(den))) )
error(['num (',num2str(rows(num)),'x',num2str(columns(num)), ...
') and den (',num2str(rows(den)),'x',num2str(columns(den)), ...
') must be vectors'])
endif
# strip leading zero coefficients
num = tf2sysl(num);
den = tf2sysl(den);
if (length(num) > length(den))
error("# of poles (%d) < # of zeros (%d)",length(den)-1, length(num)-1);
endif
# check sampling interval (if any)
if(nargin <= 2) tsam = 0; # default
elseif (isempty(tsam)) tsam = 0; endif
if ( (! (is_scal(tsam) && (imag(tsam) == 0) )) || (tsam < 0) )
error('tsam must be a positive real scalar')
endif
outsys.num = num;
outsys.den = den;
# Set the system vector: active = 0(tf), updated = [1 0 0];
outsys.sys = [0, 1, 0, 0];
# Set defaults
outsys.tsam = tsam;
outsys.n = length(den)-1;
outsys.nz = 0;
outsys.yd = 0; # assume discrete-time
# check discrete time
if(tsam > 0)
[outsys.n,outsys.nz] = swap(outsys.n, outsys.nz);
outsys.yd = 1;
endif
outsys.inname = sysdefio(1,"u");
outsys.outname = sysdefio(1,"y");
outsys.stname = sysdefst(outsys.n,outsys.nz);
# Set name of input
if (nargin > 3)
# make sure its a list of a single string
if(!isempty(inname))
if(!is_list(inname)) inname = list(inname); endif
if( !is_siglt(inname) )
error("inname must be a string or list of strings");
endif
if(length(inname) > 1)
warning("tf2sys: %d input names provided; first used",length(inname));
inname = inname(1);
endif
outsys = syssetsg(outsys,"in",inname);
endif
endif
# Set name of output
if (nargin > 4)
if(!isempty(outname))
if(!is_list(outname)) outname = list(outname); endif
if(!is_siglt(outname))
error("outname must be a string or a list of strings");
endif
if(length(outname) > 1)
warning("tf2sys: %d output names provided; first used",length(outname));
outname = outname(1);
endif
outsys = syssetsg(outsys,"out",outname);
endif
endif
implicit_str_to_num_ok = save_val;
endfunction