function [N_d,D_d]=cont2disc(N_c,D_c,Ts) //function [N_d,D_d]=cont2disc(N_c,D_c,Ts) // //the function realize the conversion of a continues transfer function (in s): // bms^m + ... + b2s^2 + b1s + b0 // G(s)= -------------------------------- ; m<=n // ans^n + ... + a2s^2 + a1s + a0 //to its //discret form (in z): // g0 + g1z^-1 + g2z^-2 + ... + gks^-k // G(z)= ------------------------------------ // h0 + h1z^-1 + h2z^-2 + ... + hls^-l //using zero order hold. //inputs: //N_c = b0 + b1s + b2s^2 + ... + bms^m ... continues numerator //D_c = a0 + a1s + a2s^2 + ... + ans^n ... continues denominator //Ts ... desired sampling time for discret transfer function //outputs: //N_d = g0 + g1z^-1 + g2z^-2 + ... + gkz^-k ... discret numerator //D_d = h0 + h1z^-1 + h2z^-2 + ... + hlz^-l ... discret denominator // //Note: the coefficients in the polynomials: N_c, D_c //has an order invers with respect to Matlab // //written by: H. Prochazka, I.D. Landau //7th june 2002 sys_c=syslin("c",N_c,D_c); //continues system sys_d=ss2tf(dscr(sys_c,Ts)); //conversion to discret (in z) with 0 order hold sysz=sys_d; //conversion to z^-1 num=coeff(sysz(2))'; den=coeff(sysz(3))'; ln=length(num); ld=length(den); for k=0:ln-1, n(k+1)=num(ln-k);end; for k=0:ld-1, d(k+1)=den(ld-k);end; if lnld, d=[zeros(ln-ld,1) ; d];end; n=poly(n,"z^-1","coeff"); d=poly(d,"z^-1","coeff"); sysz(2)=n; sysz(3)=d; sys_d=sysz; N_d=numer(sys_d); //extraction of discret numerator coefficients D_d=denom(sys_d); //extraction of discret numerator coefficients