Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

symbolic s domain to z domain conversion

1,511 views
Skip to first unread message

oma amo

unread,
Apr 2, 2008, 6:47:02 PM4/2/08
to
Hi everybody,

I have a complicated continuous time transfer function (in
s-domain) with symbolic coefficients. How can I convert it
into discrete-time using Matlab? The c2d function does not
work with symbolic coefficients.

Thanks a lot,

Mine

Nasser Abbasi

unread,
Apr 2, 2008, 11:58:05 PM4/2/08
to

"oma amo" <minno...@hotmail.com> wrote in message
news:ft12d6$fcg$1...@fred.mathworks.com...

I have a small note on this, may be it will help a little for your problem.
see note #18 on the page below

http://12000.org/my_notes/mma_matlab_control/howto.htm

Basically, you have to do it 'by hand' sort of. Using ilaplace function.

Here is a copy of the code from the above page

% convert say G(s) = 1/(s^2+ a*s + b) to G(z)
% using sample time T = 0.01
% Nasser Abbasi

clear all
syms t positive
syms n positive
syms a positive
syms b positive
syms T positive
syms s z

sys1 = 1/(s^2+a*s+b);
sys2 = (1/s)*sys1;
xa1 = simple(ilaplace(sys1));
xa2 = simple(ilaplace(sys2));
xn = simple(subs(xa2,t,n*T));
tfz = simple((1-z^(-1))*ztrans(xn));

fprintf('----> This is G(z) in syms ----> \n');
%pretty(tfz); % uncomment to see all the glory too long to show

% now use subs to plug in values for our symbols

tfz=simple(subs(tfz,T,0.01)); %sample time, change as needed
tfz=simple(subs(tfz,a,10));
tfz=simple(subs(tfz,b,20));
tfz=vpa(tfz,6);
format short;

fprintf('Here is the G(z) in syms after subs ====>\n');
pretty(simple(tfz));

% now do the same using Matlab c2d and compare output
clear all
s=tf('s');
a=10; b=20; T=0.01;
sys = 1/(s^2+a*s+b);
format short
fprintf('This is G(z) from Matlab c2d\n');
c2d(sys,T,'zoh')

------- end code -----

Matlab output:


----> This is G(z) in syms ---->
Here is the G(z) in syms after subs ====>

0.0000484000000 z + 0.0000466250000
-----------------------------------
2
z - 1.90293 z + 0.904837

This is G(z) from Matlab c2d

Transfer function:
4.837e-005 z + 4.678e-005
-------------------------
z^2 - 1.903 z + 0.9048

Sampling time: 0.01
>>


Nasser


Joerg J. Buchholz

unread,
Apr 14, 2008, 3:35:49 PM4/14/08
to
A few years ago I wrote a function that might be of some help:


function G_tf = sym2tf (G_sym)

%SYM2TF Symbolic transfer function matrix to numerical transfer
function matrix.
%
% SYM2TF (G_SYM) returns the normalized numerical transfer function
matrix
% representation of the symbolic transfer function matrix G_SYM.
%
% Example:
%
% sym2tf ([s/(s+1), (s+2)/(2*s+1)])
%
% returns
%
% Transfer function from input 1 to output:
% s
% -----
% s + 1
%
% Transfer function from input 2 to output:
% 0.5 s + 1
% ---------
% s + 0.5
%

% Copyright Joerg J. Buchholz, Hochschule Bremen, buchholz@hs-
bremen.de

% Determine the numbers of rows and columns of the symbolic transfer
function matrix
[n_rows, n_cols] = size (G_sym);

% Disassemble every single symbolic transfer function into numerator
and denominator
[num_sym, den_sym] = numden (G_sym);

% Loop over all rows
for i_row = 1 : n_rows

% Loop over all columns
for i_col = 1 : n_cols

% Transform the symbolic numerator of the current transfer
function
% to numerical (coefficients of the polynomial)
num_tf{i_row, i_col} = sym2poly (num_sym(i_row, i_col));

% Transform the symbolic denominator of the current transfer
function
% to numerical (coefficients of the polynomial)
den_tf{i_row, i_col} = sym2poly (den_sym(i_row, i_col));

% Normalize, so that leading denominator coefficient equals 1
num_tf{i_row, i_col} = num_tf{i_row, i_col}/den_tf{i_row,
i_col}(1);
den_tf{i_row, i_col} = den_tf{i_row, i_col}/den_tf{i_row,
i_col}(1);

end

end

% Assemble the numerical transfer function matrix
G_tf = tf (num_tf, den_tf);

0 new messages