1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 2// Copyright (C) 2012 - INRIA - Serge Steer 3// 4// Copyright (C) 2012 - 2016 - Scilab Enterprises 5// 6// This file is hereby licensed under the terms of the GNU GPL v2.0, 7// pursuant to article 5.3.4 of the CeCILL v.2.1. 8// This file was originally licensed under the terms of the CeCILL v2.1, 9// and continues to be available under such terms. 10// For more information, see the COPYING file which you should have received 11// along with this program. 12function [S,Sn]=arma2ss(Ar) 13 //Ar : an armax data structure 14 //S : a discrete state space data structure (syslin) the regular input to 15 // output transfer 16 //Sn : a discrete state space data structure (syslin) the noise input to 17 // output transfer 18 if typeof(Ar)<>"ar" then 19 error(msprintf(_("%s : Wrong type for input argument #%d: An armax system expected.\n"),"arma2ss",1)) 20 end 21 a=Ar.a; 22 b=Ar.b; 23 d=Ar.d; 24 nu=Ar.nu; 25 sig=Ar.sig; 26 [ma,na]=size(a); 27 nb=size(b,2); 28 nd=size(d,2); 29 30 a1=a(:,ma+1:$) //a(:,1:ma) supposed to be the identity 31 if a1==[] then a1=zeros(ma,ma);na=2*ma;end 32 33 //the input to output transfer 34 A=[-a1, b(:,nu+1:$)]; 35 N=size(A,2); 36 A=[A 37 eye(na-2*ma,N)]; 38 B=[b(:,1:nu); 39 zeros(na-2*ma,nu)] 40 41 M=size(A,1) 42 if nb-nu>0 then 43 A=[A 44 zeros(nu,N) 45 zeros(N-M-nu,na-ma) eye(N-M-nu,nb-nu)] 46 B=[B 47 eye(nu,nu) 48 zeros(N-M-nu,nu)] 49 end 50 C=eye(ma,N) 51 S=syslin("d",A,B,C) 52 53 //the noise to output transfer 54 A=[-a1, d(:,ma+1:$)]; 55 N=size(A,2); 56 A=[A 57 eye(na-2*ma,N)]; 58 M=size(A,1) 59 B=[d(:,1:ma) 60 zeros(na-2*ma,ma)] 61 if nd-ma>0 then 62 A=[A 63 zeros(ma,N) 64 zeros(N-M-ma,na-ma) eye(N-M-ma,nd-ma)] 65 B=[B 66 eye(ma,ma) 67 zeros(N-M-ma,ma)] 68 end 69 70 C=eye(ma,N) 71 Sn=syslin("d",A,B*sig,C) 72endfunction 73