How to build a discrete model of my continous model. The command c2d does not work properly.

6 views (last 30 days)
Hi,
i need help at the conversion from a continuous model to a discrete form with the c2d command. I have a 60th order continuous transfer function which describes a mechanical model. For simulations in simulink i and want to use a discrete form of it.
Unfortunately the result of the c2d command differs strongly from the bode diagram of the original form (see attached pictures). I have tried all methods of the c2d-command without success. I assume there might be a numerical issue, because some of the coefficients (of the original tf) are very huge. Is someone out there who can help me :)
I would be very grateful for an example how to transfer the model into a discrete form. Thank you for your support!
To make it easier for you helpers i put the code directly into this post. So you can copy it directly without the need to download additional files.
num = [0 0.0109927448859302 3.99448177501850 109517.592486183 37649448.3297623 507611867137.250 164838549869325 1.45602535690666e+18 4.45881503809445e+20 2.90035083415998e+24 8.36041014603243e+26 4.26790523383173e+30 1.15569783404456e+33 4.81826502150825e+36 1.22295666280531e+39 4.27845058605768e+42 1.01539760485039e+45 3.03938186177652e+48 6.72647987429533e+50 1.74778155081593e+54 3.59612247521501e+56 8.20078794125948e+59 1.56346079593921e+62 3.15574619755332e+65 5.55367163321311e+67 9.98668712242453e+70 1.61548609147541e+73 2.60096532030733e+76 3.84889746257468e+78 5.56890076412877e+81 7.49763777876622e+83 9.77459134207665e+86 1.18988212041540e+89 1.40004341630049e+92 1.52999912233273e+94 1.62606485296444e+97 1.58210557703146e+99 1.51876715174348e+102 1.30296737344856e+104 1.12896104397887e+107 8.44300479163441e+108 6.59354200483496e+111 4.23987957489757e+113 2.97831644029417e+116 1.61935716620884e+118 1.02056128827901e+121 4.59433801637339e+122 2.58996115354035e+125 9.39264473695559e+126 4.72081548229835e+129 1.32761017997142e+131 5.92985806058965e+133 1.21955706185081e+135 4.82591650333776e+137 6.53675774784677e+138 2.28520008656776e+141 1.59942579434838e+142 4.92935182857493e+144 4.93641526749852e+144 1.34409420480861e+147 2.29227106147305e+133];
den = [1 370.263955149734 10046214.1163391 3521824165.73777 46983215434669.3 1.55712711040320e+16 1.36069375081261e+20 4.25659491601838e+22 2.73862539719748e+26 8.07225305323028e+28 4.07494720576437e+32 1.12956341470129e+35 4.65569456428359e+38 1.21110749550192e+41 4.18753577989324e+44 1.01989293621356e+47 3.01620740808921e+50 6.86017031860269e+52 1.76048222329015e+56 3.72853584744324e+58 8.39418194818009e+61 1.65017547779661e+64 3.28674574561815e+67 5.97598679808093e+69 1.05987254824076e+73 1.77518647761284e+75 2.81734716413742e+78 4.32722451099141e+80 6.16811900808935e+83 8.64312729787564e+85 1.10940180060664e+89 1.40999353485659e+91 1.63241782537416e+94 1.86921793202717e+96 1.95359139835591e+99 1.99986712397735e+101 1.88704196973634e+104 1.71144761109558e+106 1.45721168144069e+109 1.15844783506811e+111 8.89107686850098e+113 6.11633652831429e+115 4.22514277263861e+118 2.47562014649315e+120 1.53643864600351e+123 7.51534256603831e+124 4.18177325474872e+127 1.66297724028395e+129 8.27716813141826e+131 2.57876359985128e+133 1.14513572297659e+136 2.64141469207809e+137 1.04301772387348e+140 1.61407312523668e+141 5.64022929561847e+143 4.71923594864417e+144 1.44844295315995e+147 2.81630622346565e+147 7.52320360199863e+149 4.66283030891243e+149 1.09870911608763e+152];
Ts = 1/2048;
% Continuous System
sysc = tf(num,den);
bode(sysc);
% Discrete System
sysd = c2d(sysc,Ts);
figure;
bode(sysd);
frequency response of the continuous system
frequency response of the synthesized discrete form.
  4 Comments
Mischa Kim
Mischa Kim on 29 Apr 2014
I recommend going a step further and changing the question title, as well, since most contributors will skip this post just for the non-English title.

Sign in to comment.

Accepted Answer

Arkadiy Turevskiy
Arkadiy Turevskiy on 29 Apr 2014
Edited: Arkadiy Turevskiy on 29 Apr 2014
Transfer function representation of an LTI system is not the best representation for doing calculations. For more on that please see this example .
Specifically, for your problem, convert sysc to a state space representation, do c2d conversion on that state-space system.
sysc_ss=ss(sysc);
sysd_ss=c2d(sysc_ss,Ts);;
P = bodeoptions; %
P.PhaseWrapping = 'on'; % turn phase wrapping on
bodeplot(sysc,sysd_ss,P);
legend('cont. tf', 'discrete ss')
This looks much better :)
There are a couple of additional things to try:
If you want to match the frequency response, the best discretization method to use is Tustin .
Also, the plot above shows that it would be nice to improve accuracy in the frequency range from 100 rad/s to 1,000 rad/s. This can be done using prescale command.
So, further improving the code:
sysd_ss=c2d(sysc_ss,Ts,'Tustin');
sysd_ss_p=prescale(sysd_ss,{100 1000});
figure;
bodeplot(sysc,sysd_ss_p,P);
legend('cont. tf', 'discrete ss with Tustin and scaling')
  2 Comments
Arkadiy Turevskiy
Arkadiy Turevskiy on 29 Apr 2014
You can try improving thing further by using pre-wapring with Tustin.
sysc_ss=ss(sysc);
opt = c2dOptions('Method', 'tustin', 'PrewarpFrequency', 500);
sysd_ss=c2d(sysc_ss,Ts,opt);
sysd_ss_p=prescale(sysd_ss,{100 1000});
bodeplot(sysc,sysd_ss_p,P);
You can then play with the prewarping frequency value to see which one gives you the best fit.
Roman Kraus
Roman Kraus on 30 Apr 2014
Hello Arkadiy,
thank you a lot for your answer which seems to be exactly what I needed! A first simple test with matlab and with simulink gave me very promising results.
Originally the tf-model results from a state-space model, created by ss2tf. I tried to create a discrete ss model with ss(A,B,C,D,Ts) without good results (it seemed the ss-representation was still a continuous one, the ss-help gives some explanation), so i tried to simplify the system by building a transfer function. Now I know i should stay at the state-space form and should convert it with c2d.
Thank you for your investment in time and the helpful code.
Kind regards from Frankfurt,
Roman

Sign in to comment.

More Answers (0)

Categories

Find more on Dynamic System Models in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!