function [Ad, Bd, Cd, Dd] = c2dm(sys, t, ~) %C2D continuous system to discrete time system conversion % Use an arbitrary third argument for FOH approximation matrixes. % by H. Shakouri G. [a, b, c, d] = ssdata(sys); n = size(a,1); m = size(b,2); s = expm([[a,b]*t; zeros(m, n+m)]); Ad = s(1:n, 1:n); Bd = s(1:n,n+1:n+m); Cd = c; Dd = d; if nargin==3 AI = Ad - eye(size(a)); a1 = inv(a); G = a1*AI*b; H = (a1*a1*AI/t-a1)*b; Bd = AI*H+G; Dd = d + c*H; endif if nargout<=1, Ad = ss(Ad, Bd, Cd, Dd); end endfunction