From sources-request at octave dot org Sun Jan 1 14:15:24 2006 Subject: Addon to OCST - Matlab c2d "FOH" method - Part II From: =?iso-8859-1?Q?Olof_T=E5ngrot?= To: Date: Sun, 1 Jan 2006 13:30:26 -0600 This is a multi-part message in MIME format. ------=_NextPart_000_0013_01C60F11.91A220A0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 8bit Hi there. This is the second post about the same subject containing impovements. Control theory command c2d in Octave and Matlab has similar features. Though the triangle hold equvivalence (or first order hold) is not availible in the Octave version. The appended code originates from the M-files found at http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectType=file&objectId=2163 (tri.m). The code applies to the book Digital Control of Dynamic Systems [DCDS] by Franklin et. al, 2nd and 3rd edition. My first post used a function name that did not match the file name. That has been fixed. Nor did the code in my first post work with a MIMO system and I don't belive the original code did so either. Although the analysis in [DCDS] (2nd ed) only covers a single input system I have tried to extend the result to a multiple input system where v and w is not scalars but colon vectors instead. The changes effects sampling time 1/T and gamma1 and gamma2 that also must match the dimension of the system input. Also different matrix zeros needed to give the big matrix the correct dimensions has been altered. I have verified the new tringle hold eqvivalent implementation with both a SISO system and a MISO system (using the step simulation and comparing with a simulation of the continous system). All inputs in the MISO system has been verified. I also appended the orignal tri.m for reference (slightly modified to have a function name that matches the file name). Olof Tångrot ------=_NextPart_000_0013_01C60F11.91A220A0 Content-Type: application/octet-stream; name="trieq_original.m" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="trieq_original.m" function [f,g,h,j] =3D trieq_original(a,b,c,d,T)=0A= % [F,G,H,J] =3D trieq(A,B,C,D,T) computes the triangle=0A= % equivalent of the continuous system A B C D at=0A= % sampling period T=0A= [n,n] =3D size(a);=0A= [ny,nx] =3D size(c);=0A= cc =3D zeros(ny,nx);=0A= [nx,nu] =3D size(b);=0A= bb =3D zeros(nx,nu);=0A= aa =3D [a b bb ; cc 0 1/T; cc 0 0];=0A= pp =3D expm(aa*T);=0A= f =3D pp(1:n,1:n);=0A= g1 =3D pp(1:n,n+1);=0A= g2 =3D pp(1:n,n+2);=0A= g =3D g1 + f*g2 - g2;=0A= h =3D c;=0A= j =3D d + c*g2;=0A= ------=_NextPart_000_0013_01C60F11.91A220A0 Content-Type: application/octet-stream; name="trieq.M" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="trieq.M" function dsys =3D trieq(SYS,T)=0A= ## dsys =3D trieq(sys,T) computes the discrete time =0A= ## triangle hold equivalent of purely contiouns system=0A= ## SYS at sampling period T.=0A= ##=0A= ## The triangle hold equvialent is described in =0A= ## Digital Control of Dynamic Systems, Franklin et. al, 2nd edtion, =0A= ## page 151-155.=0A= ##=0A= if(!(0 =3D=3D is_digital(SYS)))=0A= error("trieq: system is not purely contionous") % Mayby this = restriction could be removed.=0A= else=0A= [a,b,c,d,tsam,n,nz,stname,inname,outname,yd] =3D sys2ss(SYS);=0A= stnamed =3D strappend(stname,"_d");=0A= [n,n] =3D size(a);=0A= [ny,nx] =3D size(c);=0A= [nx,nu] =3D size(b);=0A= cc =3D zeros(nu,nx);=0A= bb =3D zeros(nx,nu);=0A= ccc =3D zeros(nu, nu);=0A= tt =3D 1/T* eye(nu, nu);=0A= aa =3D [a b bb ; cc ccc tt; cc ccc ccc]; % Create big matrix=0A= pp =3D expm(aa*T);=0A= f =3D pp(1:n,1:n);=0A= gamma1 =3D pp(1:n,n+1:n+nu);=0A= gamma2 =3D pp(1:n,n+nu+1:n+2*nu);=0A= g =3D gamma1 + f*gamma2 - gamma2;=0A= h =3D c;=0A= j =3D d + c*gamma2;=0A= dsys =3D ss(f,g,h,j,T,0,rows(f),stnamed,inname,outname);=0A= endif=0A= ------=_NextPart_000_0013_01C60F11.91A220A0--