{"id":658,"date":"2012-03-28T11:22:56","date_gmt":"2012-03-28T16:22:56","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/?p=658"},"modified":"2012-03-28T11:22:56","modified_gmt":"2012-03-28T16:22:56","slug":"estimating-continuous-time-transfer-functions-with-system-identification-toolbox","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2012\/03\/28\/estimating-continuous-time-transfer-functions-with-system-identification-toolbox\/","title":{"rendered":"Estimating Continuous-Time Transfer Functions with System Identification Toolbox"},"content":{"rendered":"<em><p>Today guest blogger Pravallika describes how she used new features of the <a href=\"https:\/\/www.mathworks.com\/products\/sysid\/\">System Identification Toolbox<\/a> to design a controller for a DC motor<\/p><\/em>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/pvinnako_tn_large.jpg\" alt=\"Pravallikota Vinnakota, guest blogger\" style=\"float: left; margin-right: 1em;\">\r\n\r\nAny controls engineer knows that the key to designing a good controller is having a good plant model. But what do you do if you don\u2019t have the underlying equations?\r\n\r\n<br><br>\r\n\r\nSystem identification can help in that case. In R2012a, the <a href=\"https:\/\/www.mathworks.com\/products\/sysid\/\">System Identification Toolbox<\/a> added support for estimating parameters of a model type that is most intuitive and easiest to work with for controls engineers \u2013 continuous-time transfer functions. You can specify how many poles and zeros you want your transfer function to have, and the toolbox determines locations of poles and zeros automatically. If the system you are trying to model has a delay, the toolbox can automatically determine its value.<\/p>\r\n\r\n<p><strong>The Setup<\/strong><\/p>\r\n\r\n<p>I have been working with the setup shown in the image below. It is very simple; it is a small DC motor connected to an Arduino board.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q2\/ArduinoDUT1.JPG\" alt=\"DC Motor connected to an Arduino board.\"><\/p>\r\n\r\n<p>I applied a voltage to the motor and recorded the resulting motion. I imported this data in MATLAB and <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/ident\/ug\/bqt1uuy.html\">constructed an iddata object<\/a>.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q2\/data_object.png\" alt=\"iddata object\"><\/p>\r\n\r\n<p>Here is what the data look like, using the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/ident\/ref\/plot.html\"> iddata plot<\/a> command.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q2\/experimental_data.png\" alt=\"Experimental data\"><\/p>\r\n\r\n<p><strong>Estimation<\/strong><\/p>\r\n\r\n<p>Let\u2019s begin by estimating the simplest possible transfer function \u2013 first-order, with no zeros. For that, we use the new function <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/ident\/ref\/tfest.html\">tfest<\/a>. \r\n<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q2\/estimation_unig_tfest.png\" alt=\"Estimation\"><\/p>\r\n\r\n<p>After the estimation is completed, we can <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/ident\/ref\/compare.html\">compare<\/a> the output of the model with the measured shaft angle. The comparison shows that the model does a good job in capturing dynamics of the motor.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q2\/comparison1.png\" alt=\"Comparing experimental and identified data\"><\/p>\r\n\r\n<p><strong>Validation<\/strong><\/p>\r\n\r\n<p>To ensure that the estimated transfer function represents motor dynamics, we need to validate this transfer function against an independent data set.<\/p>\r\n\r\n<p>I tried feeding other sets of data acquired experimentally through the identified transfer function and compared the result with the measured shaft angle. Even though the fit is not perfect, the identified transfer function does a pretty good job in capturing system dynamics.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q2\/comparison2.png\" alt=\"Comparing experimental and identified data\"><\/p>\r\n\r\n<p><strong>Using the Estimated Transfer Function<\/strong><\/p>\r\n\r\n<p>Now let's use the identified transfer function model to design a PID controller using <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/control\/ref\/pidtune.html\">pidtune<\/a>.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q2\/pidtune_code.png\" alt=\"Designing a controller using PIDTUNE\"><\/p>\r\n\r\n<p>One notable quality of models obtained with System Identification Toolbox is that they not only contain the information about the \u201cnominal\u201d parameter values, but also carry information about parameter uncertainty.  We can check the effect of this <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/ident\/ug\/bq1sjno.html#bs3z12f-1\">parameter uncertainty<\/a> on the bode plot magnitude of the estimated transfer function.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q2\/confidence_region.png\" alt=\"Displaying confidence region on a Bode plot\"><\/p>\r\n\r\n<p>We can also use the function <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/ident\/ref\/rsample.html\">rsample<\/a> to sample this parameter uncertainty to create an array of transfer functions to test our controller. <\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q2\/pidtune.png\" alt=\"Designing a controller using PIDTUNE\"><\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q2\/final_response.png\" alt=\"Step response of the controlled system\"><\/p>\r\n\r\n<p>The plot above shows the closed-loop step response for the nominal plant as well as the additional ten step responses for the sampled parameter uncertainty. We can see that the PID controller we designed works well in the face of uncertainty in estimated transfer function parameters.\r\n<\/p>\r\n\r\n<p><strong>Estimating Other Model Types<\/strong><\/p>\r\n\r\n<p>In addition to estimating continuous-time transfer functions, System Identification Toolbox lets you estimate continuous-time state-space models and process models (special, low-order transfer functions). You can quickly compare different models and pick the one that is most appropriate for your problem.<\/p>\r\n\r\n\r\n<p><strong>Now it is your turn<\/strong><\/p>\r\n\r\n<p>How do you develop plant models? Try using new capabilities for continuous-time transfer function estimation and let us know what you think by leaving us a <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=658&amp;#comment\">comment here<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Today guest blogger Pravallika describes how she used new features of the System Identification Toolbox to design a controller for a DC motor\r\n\r\n\r\n\r\nAny controls engineer knows that the key to... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2012\/03\/28\/estimating-continuous-time-transfer-functions-with-system-identification-toolbox\/\">read more >><\/a><\/p>","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[115,30,16],"tags":[247,117,261],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/658"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/comments?post=658"}],"version-history":[{"count":27,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/658\/revisions"}],"predecessor-version":[{"id":792,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/658\/revisions\/792"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=658"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=658"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=658"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}