home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 4
/
DATAFILE_PDCD4.iso
/
languages
/
rlab1_23a
/
CTB
/
impulse
< prev
next >
Wrap
Text File
|
1995-11-14
|
3KB
|
119 lines
//-----------------------------------------------------------------------------
//
// impulse
//
// Syntax: impulse(a,b,c,d,ntim,iu)
//
// This routine finds the impulse response of a continuous-time
// linear system given by,
// .
// x = Ax + Bu
// y = Cx + Du
//
// Calling the routine as,
//
// impulse(A,B,C,D,NTIM)
//
// plots the time response of the linear system to an impulse
// response applied to each input. The variable NTIM is the number
// of time steps to be taken in the response.
//
// Calling the routine as,
//
// impulse(A,B,C,D,NTIM,IU)
//
// plots the time response of the linear system to an impulse apllied
// to the single input IU.
//
// The routine can also be used to find the impulse response of a polynomial
// transfer function as,
//
// impulse(NUM,DEN,NTIM)
//
// Version JBL 940519
//-----------------------------------------------------------------------------
rfile tfchk
rfile tf2ss
rfile abcdchk
rfile c2d
rfile simdata
rfile timeplot
impulse = function(a,b,c,d,ntim,iu)
{
local(nargs,Adum,num,den,nu,ny,msg,estr,aa,bb,cc,dd,Y,i,j,f,iiu)
// Count number of input arguments
nargs=0;
if (exist(a)) {nargs=nargs+1;}
if (exist(b)) {nargs=nargs+1;}
if (exist(c)) {nargs=nargs+1;}
if (exist(d)) {nargs=nargs+1;}
if (exist(ntim)) {nargs=nargs+1;}
if (exist(iu)) {nargs=nargs+1;}
if ( (nargs <= 2) || (nargs > 6) ) {
error("impulse: Error in number of input arguments.");
}
// Convert to S-S if in TF form
if (nargs < 5) {
Adum=tfchk(a,b);
num=Adum.numc;
den=Adum.denc;
Adum=tf2ss(num,den);
a=Adum.a;
b=Adum.b;
c=Adum.c;
d=Adum.d;
nu=1;
ny=1;
iiu=1;
else
// See if a,b,c, and d are compatible.
msg="";
msg=abcdchk(a,b,c,d);
if (msg != "") {
estr="impulse: "+msg;
error(estr);
}
ny=c.nr;
nu=b.nc;
if (!exist(iu)) {
iiu=-1;
else
iiu=iu;
}
}
// Determine sample frequency
f=50*max(abs(eig(a).val)) / (2*pi);
// Convert continuous model to discrete with 1/f as the sample time
Adum=c2d(a,b,1/f);
aa=Adum.phi;
bb=Adum.gamma;
cc=c;
dd=zeros(ny,nu);
// Simulate the system by calling simdata
Y=simdata(aa,bb,cc,dd,ntim);
// Plot the impulse response
pstart();
if (iiu < 0) {
for (i in 1:ny) {
for (j in 1:nu) {
timeplot(i,j,f,ntim,Y,"Impulse Response");
pause;
}
}
else
for (i in 1:ny) {
timeplot(i,iiu,f,ntim,Y,"Impulse Response");
}
}
};