<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Guy and Seth on Simulink</title>
	
	<link>http://blogs.mathworks.com/seth</link>
	<description>This blog is about Simulink.</description>
	<lastBuildDate>Fri, 10 May 2013 18:51:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/SethOnSimulink" /><feedburner:info uri="sethonsimulink" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>SethOnSimulink</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Sum Block: Round or Rectangular?</title>
		<link>http://feedproxy.google.com/~r/SethOnSimulink/~3/6rzrSylM3j8/</link>
		<comments>http://blogs.mathworks.com/seth/2013/05/10/sum-block-round-or-rectangular/#comments</comments>
		<pubDate>Fri, 10 May 2013 18:51:42 +0000</pubDate>
		<dc:creator>Guy Rouleau</dc:creator>
				<category><![CDATA[Modeling]]></category>
		<category><![CDATA[Signals]]></category>
		<category><![CDATA[Simulink Tips]]></category>
		<category><![CDATA[Formatting]]></category>
		<category><![CDATA[Modeling Guidelines]]></category>
		<category><![CDATA[Sum Block]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/seth/?p=2209</guid>
		<description><![CDATA[Working in technical support, I see a lot of Simulink models from users. I have realized that many users do not know how to, or do not take the time to configure the ports of the Sum block. For example, when I see things like this, it makes my eyes hurt a little: Here are [...]]]></description>
			<content:encoded><![CDATA[<p>Working in technical support, I see a lot of Simulink models from users. I have realized that many users do not know how to, or do not take the time to configure the ports of the <a href="http://www.mathworks.com/help/simulink/slref/add.html">Sum</a> block.</p>

<p>For example, when I see things like this, it makes my eyes hurt a little:</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q2/lookingBad.png" alt="Unusual configurations of the Sum block" /></p>

<p>Here are a few tips to format the Sum block to make your models easier to understand.</p>

<p><strong>Round Sum block</strong></p>

<p>When you drag the Sum block from the Simulink Library Browser, its <strong>Icon Shape</strong> is set to <strong>Round</strong>, and it has one input port on the left and one on the bottom:</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q2/defaultSumBlock.png" alt="Default configuration of the Sum block" /></p>

<p>When the Sum block Icon Shape is set to Round, the ports are spread evenly from top to bottom and the vertical bar "|" can be used to skip one position. For example, if we want to add a port on top of the block, we can modify the list of signs:</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q2/threeSumBlock.png" alt="3 ports configuration of the Sum block" /></p>

<p><strong>Rectangular Sum block</strong></p>

<p>If you change the <strong>Icon Shape</strong> property of the default Sum block to <strong>Rectangular</strong>, the block will look like the following:</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q2/defaultRectangularSumBlock.png" alt="Rectangular configuration of the Sum block" /></p>

<p>Personally, I can not think of a good reason for skipping a port in Rectangular shape. So I almost always remove the "|" when I change the shape to Rectangular.</p>

 <p><img src="http://blogs.mathworks.com/images/seth/2013Q2/RectangularSumBlock.png" alt="Rectangular configuration of the Sum block" /></p>

<p><strong>Sum of Elements</strong></p>

<p>One way I like to use the Sum block is to sum all the elements of a vector or matrix:</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q2/sumOfAllElements.png" alt="Sum of elements configuration of the Sum block" /></p>

<p>For matrices, the Sum block can also be configured to Sum only over one specific dimension:</p>

 <p><img src="http://blogs.mathworks.com/images/seth/2013Q2/sumOfElements.png" alt="Sum of elements configuration of the Sum block" /></p>

<p><strong>Round or Rectangular?</strong></p>

<p>One question remains: <em>When should the Sum block be Round and when should it be Rectangular?</em></p>

<p>There is no absolute rule, but personally I like to use the Rectangular shape when implementing equations that flow from left to right, without obvious feedback. For example:</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q2/rectangularFlow.png" alt="When to use configuration of the Sum block" /></p>

<p>I keep the Round shape for when I want to make it obvious that there is a feedback involved:</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q2/roundForFeedback.png" alt="When to use Round configuration of the Sum block" /></p>

<p><strong>Now it's your turn</strong></p>

<p>Please share with us if you have rules or guidelines on the format of your blocks by leaving a <a href="http://blogs.mathworks.com/seth/?p=2209&#comment">comment here</a>.</p>
<img src="http://feeds.feedburner.com/~r/SethOnSimulink/~4/6rzrSylM3j8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/seth/2013/05/10/sum-block-round-or-rectangular/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://blogs.mathworks.com/seth/2013/05/10/sum-block-round-or-rectangular/</feedburner:origLink></item>
		<item>
		<title>Comparing Runs using Simulation Data Inspector</title>
		<link>http://feedproxy.google.com/~r/SethOnSimulink/~3/WScoAPqzHng/</link>
		<comments>http://blogs.mathworks.com/seth/2013/05/03/comparing-runs-using-simulink-data-inspector/#comments</comments>
		<pubDate>Fri, 03 May 2013 15:34:33 +0000</pubDate>
		<dc:creator>Guy Rouleau</dc:creator>
				<category><![CDATA[Analysis]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Model-Based Design]]></category>
		<category><![CDATA[Signals]]></category>
		<category><![CDATA[Simulink Tips]]></category>
		<category><![CDATA[Numerical Accuracy]]></category>
		<category><![CDATA[SDI]]></category>
		<category><![CDATA[Simulation data Inspector]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/seth/?p=2169</guid>
		<description><![CDATA[Do you use the Simulation Data Inspector? Here is an example where it saved me a lot of debugging time. Simulation Accuracy I recently had to validate system behavior and analyze numerical accuracy of a model. Making small modifications in one part of the model was leading to unexpectedly large differences at the outputs. Since [...]]]></description>
			<content:encoded><![CDATA[<p>Do you use the <a href="http://www.mathworks.com/help/simulink/ug/simulation-data-inspector-overview.html">Simulation Data Inspector</a>? Here is an example where it saved me a lot of debugging time.</p>

<p><strong>Simulation Accuracy</strong></p>

<p>I recently had to <a href="http://www.mathworks.com/help/simulink/validate-system-behavior.html">validate system behavior</a> and analyze numerical accuracy of a model. Making small modifications in one part of the model was leading to unexpectedly large differences at the outputs. Since the model was very large, I thought it would be painful to insert <a href="http://www.mathworks.com/help/simulink/slref/scope.html">Scopes</a> or <a href="http://www.mathworks.com/help/simulink/slref/toworkspace.html">To Workspace</a> blocks in the model to try identifying the source of the problem.</p>

<p>I found out that the Simulation Data Inspector can be very useful to <a href="http://www.mathworks.com/help/simulink/ug/comparison-of-all-logged-signal-data-from-multiple-simulations.html">compare simulation results</a> without adding blocks to your model and without writing any scripts. Let's see how this work!</p>

<p><strong>Logging Signals</strong></p>

<p>The first step is to <a href="http://www.mathworks.com/help/simulink/ug/configuring-a-signal-for-signal-logging.html">configure signals for logging</a>. I like to use the <a href="http://www.mathworks.com/help/simulink/ug/the-model-explorer-overview.html">Model Explorer</a> for that. It is significantly faster than right-clicking on the signal lines one by one. Here are a few tips to configure the Model Explorer with the goal of controlling signal logging.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q2/configure_logging.png" alt="Configuring signals for logging using the model explorer" /></p>

<p>Also, ensure that signal logging is enabled in the model configuration.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q2/enable_logging.png" alt="Enabling logging" /></p>

<p><strong>Record &#038; Inspect Simulation Output</strong></p>

<p>In your model, click on the Record button.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q2/enable_sdi.png" alt="Record &#038; Inspect Simulation Output" /></p>

<p>When the simulation is completed, open the Simulation Data Inspector using the link that pops up.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q2/launching_sdi.png" alt="Launching Simulation Data Inspector" /></p>

<p><strong>Compare Runs</strong></p>

<p>Make some changes to your model and simulate it again. In the Simulation Data Inspector, go to the <strong>Compare Runs</strong> Tab, select your 2 runs and click <strong>Compare</strong>.</p>

<p>Using the absolute tolerance I specified, the Simulation data Inspector helped me to quickly identify where the divergence appear in my model.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q2/compare_runs.png" alt="Comparing Runs in Simulation Data Inspector" /></p>



<p><strong>Now it's your turn</strong></p>

<p>Give a look and the <a href="http://www.mathworks.com/help/simulink/validate-system-behavior.html">Validate System Behavior</a> section of the documentation to learn more about the Simulation Data Inspector and let us know if it helps your workflow by leaving a <a href="http://blogs.mathworks.com/seth/?p=2169&#comment">comment here</a>.






<img src="http://feeds.feedburner.com/~r/SethOnSimulink/~4/WScoAPqzHng" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/seth/2013/05/03/comparing-runs-using-simulink-data-inspector/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<feedburner:origLink>http://blogs.mathworks.com/seth/2013/05/03/comparing-runs-using-simulink-data-inspector/</feedburner:origLink></item>
		<item>
		<title>Zero-Crossing Detection… what are your options?</title>
		<link>http://feedproxy.google.com/~r/SethOnSimulink/~3/SRVn27I06DE/</link>
		<comments>http://blogs.mathworks.com/seth/2013/04/26/zero-crossing-detection-what-are-your-options/#comments</comments>
		<pubDate>Fri, 26 Apr 2013 19:11:15 +0000</pubDate>
		<dc:creator>Guy Rouleau</dc:creator>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Modeling]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Simulink Tips]]></category>
		<category><![CDATA[Zero-Crossing Detection]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/seth/?p=1935</guid>
		<description><![CDATA[When using Simulink variable-step solvers, zero-crossing detection is very useful to capture events accurately. However for some equations, configuring zero-crossing detection can be challenging. Last week I received the following question and example model: In the attached model, I implemented a basic bang-bang controller for a plow. Using a Sign block, I generate a 1 [...]]]></description>
			<content:encoded><![CDATA[<p>When using Simulink variable-step solvers, <a href="http://www.mathworks.com/help/releases/R2012b/simulink/ug/simulating-dynamic-systems.html#f7-9506">zero-crossing detection</a> is very useful to capture events accurately. However for some equations, configuring zero-crossing detection can be challenging.</p>

<p>Last week I received the following question and example model:</p>

<p><em>In the attached model, I implemented a basic bang-bang controller for a plow. Using a <a href="http://www.mathworks.com/help/releases/R2012a/toolbox/simulink/slref/sign.html">Sign</a> block, I generate a 1 for the plow to go up, -1 to go down and 0 to stop. The problem is that the plow never seems to stabilize around zero. Can you help me understand why?</em></p>

<p>Here is an image of the model:</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q1/initialPlowModel.png" alt="Bang Bang Controller for a plow" /></p>

<p><strong>Nonadaptive zero-crossing detection</strong></p>

<p>With the default settings, this model errors out as soon as we try to give a non-zero command with the following error:</p>

<p><font color="red"><tt>At time 1.0000000000236877, simulation hits (1000) consecutive zero crossings. Consecutive zero crossings will slow down the simulation or cause the simulation to hang. To continue the simulation, you may 1) Try using Adaptive zero-crossing detection algorithm or 2) Disable the zero crossing of the blocks shown in the following table. <br />
--------------------------------------------------------------------------------<br />
Number of consecutive zero-crossings : 1000<br />
Zero-crossing signal name : Input<br />
Block type : Signum<br />
Block path : 'myPlowController/Sign'<br />
--------------------------------------------------------------------------------<br />
You can turn off this message by using the MATLAB command: <br />
set_param('myPlowController','MaxConsecutiveZCsMsg','none'); </tt></font></p>

<p>This error is relatively simple to understand by looking at the ideal plant model (an Integrator block) and the switching logic. If the plow position is slightly negative, the controller makes it move upward, leading to a positive error. The controller sees this positive error, makes the plow go down, bringing us back to our original state .</p>

<p>With zero-crossing detection enabled for the <a href="http://www.mathworks.com/help/simulink/slref/sign.html">Sign</a> block, Simulink will detect that we crossed zero and try to reduce its step-size to capture this transition accurately. But here, reducing the step size will not help. The step size can be a small as possible, a small negative error will always lead to a jump on the positive side, and vice-versa.</p>

<p>Let's try the suggestions offered by the error message.  What suggestions? If you didn't read the error message, go back and read it now.</p>

<p><strong>Suggestion 1: Adaptive zero-crossing detection</strong></p>

<p>In the solver section of the model configuration, we can try selecting <a href="http://www.mathworks.com/help/releases/R2012b/simulink/gui/solver-pane.html#bq9z2nq-1">adaptive zero-crossing detection</a>. This will dynamically activate and deactivate zero-crossing bracketing, helping with models that exhibit strong chattering.

<p><img src="http://blogs.mathworks.com/images/seth/2013Q1/adaptiveZC.png" alt="Adaptive zero-crossing detection" /></p>

<p>With this setting the simulation completes, but the variable step solver takes way too many steps when it is not needed, and the position error is too large.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q1/adaptive_results.png" alt="Simulation results with adaptive zero-crossing detection" /></p>

<p>The reason is that the adaptive algorithm encountered multiple consecutive zero-crossings for the Sign block and decided to disable zero-crossing detection for this block. Once this is done, the solver takes larger steps and gives inaccurate results.</p>

<p>Let's try suggestion 2 from the error message.</p>

<p><strong>Suggestion 2: Disabling zero-crossing</strong></p>

<p>The second suggestion from the error message is to disable zero-crossing detection for the problematic block.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q1/disableZC.png" alt="Sign block with disabled ZC" /></p>

<p>In this case, the tracking is significantly better because the solver uses the state of the integrator to limit its step size, but we see a lot of switching happening when the plow desired height is constant.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q1/disabled_zc.png" alt="results with zero-crossing disabled" /></p>

<p>The main problem here is that it is impossible for the Simulink engine to stop exactly on the zero value of the Sign block with this system. With the equations involved, Simulink can take very small steps around zero, but will not stop exactly on it. This not what the Sign block is designed to do.</p>

<p><strong>Possible solutions</strong></p>

<p>If we want a system that can be simulated efficiently using a variable step solver, we have to modify the equations. If we want to keep the plant as it is, we need a controller with a logic that will stop when the error is within a certain range around zero. For example, we could use a Stateflow chart or a block with <a href="http://en.wikipedia.org/wiki/Hysteresis">hysteresis</a> like the <a href="http://www.mathworks.com/help/simulink/slref/relay.html">Relay</a> block:</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q1/controller_with_deadzone.png" alt="Controller with dead zone" /></p>

<p>In this case, the plow stops moving when the command is fixed and the zero-crossing detection helps ensure that the solver takes appropriate steps when needed.

<p><img src="http://blogs.mathworks.com/images/seth/2013Q1/modified_results.png" alt="Results of the Controller with dead zone" /></p>

<p><strong>Now it's your turn</strong></p>

<p>If you have some interesting plowing or zero-crossing stories to share, leave a <a href="http://blogs.mathworks.com/seth/?p=1935&#comment">comment here</a></p>


<img src="http://feeds.feedburner.com/~r/SethOnSimulink/~4/SRVn27I06DE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/seth/2013/04/26/zero-crossing-detection-what-are-your-options/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blogs.mathworks.com/seth/2013/04/26/zero-crossing-detection-what-are-your-options/</feedburner:origLink></item>
		<item>
		<title>Implementing a PID Controller on an Arduino Board</title>
		<link>http://feedproxy.google.com/~r/SethOnSimulink/~3/BK2DfvAWPx0/</link>
		<comments>http://blogs.mathworks.com/seth/2013/04/21/implementing-a-pid-controller-on-an-arduino-board/#comments</comments>
		<pubDate>Sun, 21 Apr 2013 21:49:06 +0000</pubDate>
		<dc:creator>Guy Rouleau</dc:creator>
				<category><![CDATA[Controls]]></category>
		<category><![CDATA[Guest Blogger]]></category>
		<category><![CDATA[Modeling]]></category>
		<category><![CDATA[Rapid Prototyping]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Control Design]]></category>
		<category><![CDATA[System Identification]]></category>
		<category><![CDATA[Target Hardware]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/seth/?p=2141</guid>
		<description><![CDATA[This week my colleague Pravallika is back to continue her motor control story! In my previous post, we saw how to estimate continuous transfer functions with System Identification Toolbox. We estimated the following transfer function for a simple DC Motor using tfest: For this transfer function, we designed the following controller using pidtune: We will [...]]]></description>
			<content:encoded><![CDATA[<p><em>This week my colleague <a href="http://www.mathworks.com/matlabcentral/answers/contributors/2963950-pravallika">Pravallika</a> is back to continue her motor control story!</em></p>

<p><img src="http://blogs.mathworks.com/images/seth/pvinnako_tn_large.jpg" alt="Pravallikota Vinnakota, guest blogger"></p>

<p>In my <a href="http://blogs.mathworks.com/seth/2012/03/28/estimating-continuous-time-transfer-functions-with-system-identification-toolbox/" title="Estimating Continuous-Time Transfer Functions with System Identification Toolbox">previous post</a>, we saw how to estimate continuous transfer functions with <a href="http://www.mathworks.com/products/sysid/">System Identification Toolbox</a>. We estimated the following transfer function for a simple DC Motor using <a href="http://www.mathworks.com/help/ident/ref/tfest.html"><tt>tfest</tt></a>:</p>
<p><img src="http://blogs.mathworks.com/images/seth/2013Q2/theIdentifiedSystem.png" alt="Transfer function identified from a DC Motor"/></p>

<p>For this transfer function, we designed the following controller using <a href="http://www.mathworks.com/help/control/ref/pidtune.html"><tt>pidtune</tt></a>:</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q2/theController.png" alt="Controller generated by pidtune" /></p>

<p>We will now implement the controller on the Arduino Uno and see how the DC motor fares with this controller. To deploy the controller on the hardware, we will use <a href="http://www.mathworks.com/discovery/simulink-target-hardware.html">Simulink’s capability to generate an executable and run it on selected hardware</a>.

<p><strong>Deploying controller to the Arduino board</strong></p>

<p>You probably noticed that the controller shown above is in a continuous form. To use it on our target, the first thing to do is to discretize it using the <a href="http://www.mathworks.com/help/control/ref/c2d.html"><tt>c2d</tt></a> function:</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q2/discreteController.png" alt="Discretizing the controller generated by pidtune" /></p>

<p>Then we grab the <a href="http://www.mathworks.com/help/simulink/slref/pidcontroller.html">PID block</a> from the Simulink Library and configure it.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q2/configuringPID.png" alt="PID block configuration" /></p>

<p>To keep the PID controller’s output within the limits of the hardware, we go to the PID Advanced tab and enable output saturation along with anti-windup protection. 

<p><img src="http://blogs.mathworks.com/images/seth/2013Q2/pidAdvanced.png" alt="Advanced PID block configuration" /></p>

<p>To test the controller on the hardware, we created a Simulink model using blocks from the <a href="http://www.mathworks.com/academia/arduino-software/arduino-simulink.html">Arduino Support Package</a>.</p>

<p>As you can see, we receive the desired motor position from the serial port and compare it to the measured position from the Analog Input. The position error goes through the PID block which generates a voltage to be sent to the motor. We also send the measured position through the serial port.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q2/controllerModel.png" alt="Controller model to be used on the Arduino board" /></p>

<p><strong>Hardware response</strong></p>

<p>We ran the model on the target, sent it some commands and logged the data transmitted through the serial port. Here is what it looks like:</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q2/hardware_results.png" alt="Data logged from our controller" /></p>

<p>So, it does a pretty good job of tracking the reference signal. When we compare the response from the hardware to that of the simulation, we observe that they are very close! The System Identification Toolbox model is quite good.</p>

<p><strong>Now it is your turn</strong></p>

<p>How are you designing controllers when a system is difficult to model? Have you tried the Run on Target Hardware capability in Simulink to run your models on the supported boards? Let us know by leaving a <a href="http://blogs.mathworks.com/seth/?p=2141&#comment">comment here</a>.</p><img src="http://feeds.feedburner.com/~r/SethOnSimulink/~4/BK2DfvAWPx0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/seth/2013/04/21/implementing-a-pid-controller-on-an-arduino-board/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://blogs.mathworks.com/seth/2013/04/21/implementing-a-pid-controller-on-an-arduino-board/</feedburner:origLink></item>
		<item>
		<title>Creating Driver Blocks for Arduino, Lego, and other targets</title>
		<link>http://feedproxy.google.com/~r/SethOnSimulink/~3/YOeyBd4JC6E/</link>
		<comments>http://blogs.mathworks.com/seth/2013/04/12/creating-driver-blocks-for-arduino-lego-and-other-targets/#comments</comments>
		<pubDate>Fri, 12 Apr 2013 08:00:15 +0000</pubDate>
		<dc:creator>Guy Rouleau</dc:creator>
				<category><![CDATA[Code Generation]]></category>
		<category><![CDATA[S-functions]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[LEGO]]></category>
		<category><![CDATA[s-function]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/seth/?p=2078</guid>
		<description><![CDATA[As you may know, it is easy to run Simulink models on a set of supported target hardware. This has been possible since R2012a. Even if we add more targets and support more features for each target with every new release, it is still possible that you will need a driver that is not included [...]]]></description>
			<content:encoded><![CDATA[<p>As you may know, it is easy to <a href="http://www.mathworks.com/discovery/simulink-target-hardware.html">run Simulink models on a set of supported target hardware</a>. This has been possible since R2012a.</p>

<p>Even if we add more targets and support more features for each target with every new release, it is still possible that you will need a driver that is not included in the Simulink support package. If you desperately need a driver for your hardware, you can always build it yourself.</p>

<p>Let's see how this works using an example from a LEGO NXT project I worked on.</p>

<p><strong>The LEGO Light Sensor</strong></p>

<p>The LEGO NXT kit ships with a <a href="http://shop.lego.com/en-US/Light-Sensor-9844">Light Sensor</a> including a red LED that can be turned on or off. In the Simulink support package, you can control the light from a checkbox parameter in the block dialog.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q2/LEGO_light_sensor.png" alt="Dialog of the LEGO Light Sensor driver block" /></p>

<p>For our project, we used this sensor to make a line following robot. To make our algorithm more robust, we thought it would be interesting to turn the light on and off while tracking the line, to actively filter out the ambient light.</p> 

<p><strong>Step 1: Determine the code to be generated for your driver block</strong></p>

<p>In the <a href="http://www.mathworks.com/academia/lego-mindstorms-nxt-software/legomindstorms-simulink.html">LEGO MINDSTORMS NXT Support from Simulink</a>, you can find many small examples showing how the robot can be programmed in C. By default, they are located in <tt>C:\MATLAB\SupportPackages\R2013a\nxtOSEK\samples_c</tt>. In one of those example, I found a function  initializing the robot that looked like:</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q2/LEGO_example_code.png" alt="Example code used to program the NXT brick in C" /></p>

<p>The function <tt>ecrobot_set_light_sensor_active</tt> is exactly what I need to generate from my driver block. I also figured that a corresponding function <tt>ecrobot_set_light_sensor_inactive</tt> exists to turn the light off, and I found that those functions are declared in a file named <tt>ecrobot_interface.h</tt>.</p>

<p><strong>Step 2 - Create an S-Function</strong></p>

<p>Here you have 2 options to create the S-Function</p>

<p><em>Step 2 - Option 1: S-Function Builder Block</em></p>

  <p>My colleague <a href="http://www.mathworks.com/matlabcentral/fileexchange/authors/76178">Giampiero Campa</a> published a very good submission on <a href="http://www.mathworks.com/matlabcentral/">MATLAB Central</a> titled <a href="http://www.mathworks.com/matlabcentral/fileexchange/39354-device-drivers">Device Drivers</a> showing how to use the <a href="http://www.mathworks.com/help/simulink/slref/sfunctionbuilder.html">S-Function Builder</a> block to include the code you found during step 1 in your model.</p>

<p>His submission contains detailed procedures and screen captures to guide you through the process step-by-step. If you are intimidated by writing an S-function, I recommend using his S-Function Builder technique.</p>

<p><em>Step 2 - Option 2: Writing an S-Function and a TLC file</em></p>

<p>If you are like me and want to understand the magic that is happening when you click <strong>build</strong> in the S-Function Builder block, this second option is for you.</p>

<p>First, we need to realize that unless you model the interaction of the sensor/actuator with the environment, in simulation, driver blocks typically do nothing.  All blocks must specify the number of ports and parameters, and their dimensions, even if they do nothing. In my case, I created an s-function with 1 input port of dimension 1 to specify if the light should be on or off. Here is the entire code for my s-function.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q2/lego_light_sfunction.png" alt="S-Function to control the light of the LEGO light sensor" /></p>

<p>To specify the code generated for your block, you need to use the <a href="http://www.mathworks.com/help/ecoder/block-authoring-with-tlc.html">Target Language Compiler</a>.</p>

<p>Concretely, this means that you need to write a TLC file for your block. For that, I recommend starting with examples from <tt><a href="http://www.mathworks.com/help/simulink/sfg/s-function-examples.html">sfundemos</a></tt>.</p>

<p>For this example we need our TLC to do two things: Tell the compiler to include <tt>ecrobot_interface.h</tt>, and call <tt>ecrobot_set_light_sensor_active</tt> and <tt>ecrobot_set_light_sensor_inactive</tt>. Here is what it looks like.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q2/lego_light_tlc.png" alt="TLC file to control the light of the LEGO light sensor" /></p>

<p>Note that I used <tt><a href="http://www.mathworks.com/help/rtw/tlc/block-target-file-methods.html#f37023">BlockTypeSetup</a></tt> to include the header file, and <tt><a href="http://www.mathworks.com/help/rtw/tlc/block-target-file-methods.html#f37160">Outputs</a></tt> to define what the block output method should be.</p>

<p><strong>Now it's your turn</strong></p>

<p>Download this <a href="http://blogs.mathworks.com/images/seth/2013Q2/LEGO_light_sensor.zip">LEGO example</a> or a similar <a href="http://blogs.mathworks.com/images/seth/2013Q2/adruino_example.zip">example for the Arduino target</a> and begin creating your own driver blocks!</p>

<p>If you develop custom drivers for the Simulink Target Hardware, share them on <a href="http://www.mathworks.com/matlabcentral/">MATLAB Central</a> and let us know by leaving a <a href="http://blogs.mathworks.com/seth/?p=2078&#comment">comment here</a>.</p><img src="http://feeds.feedburner.com/~r/SethOnSimulink/~4/YOeyBd4JC6E" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/seth/2013/04/12/creating-driver-blocks-for-arduino-lego-and-other-targets/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://blogs.mathworks.com/seth/2013/04/12/creating-driver-blocks-for-arduino-lego-and-other-targets/</feedburner:origLink></item>
		<item>
		<title>To Latch or not to Latch?</title>
		<link>http://feedproxy.google.com/~r/SethOnSimulink/~3/Jna7_rOpDgU/</link>
		<comments>http://blogs.mathworks.com/seth/2013/04/05/to-latch-or-not-to-latch/#comments</comments>
		<pubDate>Fri, 05 Apr 2013 14:58:03 +0000</pubDate>
		<dc:creator>Guy Rouleau</dc:creator>
				<category><![CDATA[Code Generation]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Signals]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/seth/?p=1955</guid>
		<description><![CDATA[Yesterday I explained to a colleague the effect of the Inport block option Latch input for feedback signals of function-call subsystem outputs . I thought it would be interesting to share here. The Problem In the following model, inside the calib function-call subsystem, the Count signal is connected to a Unit Delay block. When logging [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I explained to a colleague the effect of the Inport block option <a href="http://www.mathworks.com/help/releases/R2012b/simulink/slref/inport.html#brqe18y-28">Latch input for feedback signals of function-call subsystem outputs
</a>. I thought it would be interesting to share here.</p>

<p><strong>The Problem</strong></p>

<p>In the following <a href="http://blogs.mathworks.com/images/seth/2013Q1/Problem_latch.slx">model</a>, inside the <em>calib</em> <a href="http://www.mathworks.com/help/simulink/slref/functioncallsubsystem.html">function-call subsystem</a>, the <em>Count</em> signal is connected to a <a href="http://www.mathworks.com/help/simulink/slref/unitdelay.html">Unit Delay</a> block.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q1/fcnCallLoopModel.png" alt="Model with a Function-Call subsystem involved in a direct feedback loop" /></p>

<p>When logging data, we can see that the input and output of the Unit Delay are identical, as if the signal was not delayed!</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q1/fcnCallOutput.png" alt="Input and output of the Unit Delay are equal" /></p>

<p>Even though this might seem strange, this behavior is expected. Let's see why.</p> 

<p><strong>The simulation loop</strong></p>

<p>To understand what is happening, you first need to be familiar with the order into which the block methods are executed within the simulation loop. To really understand the simulation loop I recommend the following documentation pages:

<ul>
	<li>First, you need to know that the equations for blocks are implemented in multiple <a href="http://www.mathworks.com/help/releases/R2012b/simulink/ug/modeling-dynamic-systems.html#f7-22144">block methods</a>: Outputs, Update, Derivative, etc.</li>
	<li>To get an overview of the order into which those methods are called: <a href="http://www.mathworks.com/help/releases/R2012b/simulink/sfg/how-s-functions-work.html">How S-Functions Work</a></li>
	<li>To get the complete details of all the block methods available: <a href="http://www.mathworks.com/help/releases/R2012b/simulink/sfg/how-the-simulink-engine-interacts-with-c-s-functions.html">Simulink Engine Interaction with C S-Functions</a></li>
</ul>

<p>In our case, we have a model that is fixed-step and discrete, so the simulation loop is very simple and looks like this:</p> 

<p><img src="http://blogs.mathworks.com/images/seth/2013Q1/simulationloop.png" alt="Simulation loop" /></p>

<p> The important thing to understand is that Simulink executes the <strong>Outputs</strong> method of all blocks, and then the <strong>Update</strong> method of all blocks.</p>

<p><strong>The execution order</strong></p>

<p>The second thing we need to know is the order in which blocks are executed. For that, we display the block <a href="http://www.mathworks.com/help/releases/R2012b/simulink/ug/controlling-and-displaying-the-sorted-order.html">sorted order</a>.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q1/sortedOrder.png" alt="Sorted Order" /></p>

<p>When you display the sorted order, you can see red numbers displayed on the block. The first number is the number of the system, so the function-call subsystem in this model is system number 3. The second number is the order of the block in this system. In this case, the Gain is the first (<font color="red"><tt>3:0</tt></font>), Unit Delay the second (<font color="red"><tt>3:1</tt></font>), Counter the third (<font color="red"><tt>3:2</tt></font>), etc.</p>

<p><strong>The effect of the latch</strong></p>

<p>To see the effect of latching, I generated code for this model and added comments to highlight the fact that the feedback loop causes the input signal to change immediately as the output is written:</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q1/fcnCallCode.png" alt="Generated Code without latch" /></p>

<p>Such feedback loops break the assumptions on which the Output-Update logic is built... and can make results difficult to interpret. This is why the Latch is available.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q1/latchInportDialog.png" alt="Inport block dialog" /></p>

<p>With the latch, a copy of the input signal is made at the beginning of the step and this copy is used for the computations:</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q1/fcnCallCodeWithLoop.png" alt="Generated Code with latch" /></p>

<p><strong>Conclusion</strong></p>

<p>In conclusion, we can say that introducing the latch is safer, but costs an additional copy. If you know that your function-call subsystem might be involved in a direct feedback loop, use Inport Latching to avoid surprises.</p>

<p><strong>Now it's you turn</strong></p>

<p>Are you latching the inputs of your function-call subsystems? Let us know the reason why by leaving a <a href="http://blogs.mathworks.com/seth/?p=1955&#comment">comment here</a>.</p><img src="http://feeds.feedburner.com/~r/SethOnSimulink/~4/Jna7_rOpDgU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/seth/2013/04/05/to-latch-or-not-to-latch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blogs.mathworks.com/seth/2013/04/05/to-latch-or-not-to-latch/</feedburner:origLink></item>
		<item>
		<title>New for R2013a: Time Scope with Triggering!</title>
		<link>http://feedproxy.google.com/~r/SethOnSimulink/~3/hURwDXnGoDA/</link>
		<comments>http://blogs.mathworks.com/seth/2013/03/25/new-for-r2013a-time-scope-with-triggering/#comments</comments>
		<pubDate>Mon, 25 Mar 2013 21:07:11 +0000</pubDate>
		<dc:creator>Guy Rouleau</dc:creator>
				<category><![CDATA[Signals]]></category>
		<category><![CDATA[What's new?]]></category>
		<category><![CDATA[DSP]]></category>
		<category><![CDATA[Time Scope]]></category>
		<category><![CDATA[trigger]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/seth/?p=1857</guid>
		<description><![CDATA[Today we are happy to welcome guest blogger Kirthi Devleker to talk about a new trigger functionality added to the Time Scope in R2013a. Did you know that a Trigger functionality is now available with the Time Scope in the DSP System Toolbox (R2013a) ? The Time Scope ships both as a System object and [...]]]></description>
			<content:encoded><![CDATA[<p><em>Today we are happy to welcome guest blogger Kirthi Devleker to talk about a new trigger functionality added to the Time Scope in R2013a.</em></p>

<p>Did you know that a Trigger functionality is now available with the <a href="http://blogs.mathworks.com/seth/2012/04/16/a-scope-for-simulink-and-matlab/" target="_blank">Time Scope</a> in the DSP System Toolbox (R2013a) ? The Time Scope ships both as a System object and also as a Simulink block with the<a href="http://www.mathworks.com/products/dsp-system/"> DSP System Toolbox</a></p>

<p><a href="http://blogs.mathworks.com/images/seth/2013Q1/1.gif"><img title="Before Triggering" src="http://blogs.mathworks.com/images/seth/2013Q1/1.gif" alt="Time Scope without trigger" /></a>    
<a href="http://blogs.mathworks.com/images/seth/2013Q1/2.gif"><img title="After Enabling Trigger" src="http://blogs.mathworks.com/images/seth/2013Q1/2.gif" alt="Time Scope with trigger"/></a></p>

<p>Triggers are ubiquitous on real-world hardware oscilloscopes. They are useful to analyze signals,specifically to stabilize a repetitive waveform and search for a occurrence of a  particular pattern in the signal.</p>

<p><strong>Trigger Modes</strong>:</p>

<p>The Trigger in Time Scope supports 3 different modes of operation for a given trigger type. They are:</p>
<ul>
<li>Auto: In this mode, the Time Scope stabilizes the display if the trigger criteria is met or continues to display the incoming signal.</li>
<li>Normal : The time scope displays the stabilized signal only if the trigger criteria is met otherwise nothing is displayed.</li>
<li>Once: The time scope displays the signal only for the very first time the trigger event is encountered. (Simulation will still keep running)</li>
</ul>

<p>Here is an animation showing those different modes:</p>

<p><a href="http://blogs.mathworks.com/images/seth/2013Q1/showAllTriggers.gif"><img title="Triggering modes available in the time scope" src="http://blogs.mathworks.com/images/seth/2013Q1/showAllTriggers.gif" alt="Triggering modes available in the time scope" /></a></li></p>

<p>Let's look at a few more examples</p>

<p><strong>Edge Triggering</strong></p>

<p>Let's create a simple sine wave and display it on the Time Scope.</p>

<p><a href="http://blogs.mathworks.com/images/seth/2013Q1/mcode.png"><img src="http://blogs.mathworks.com/images/seth/2013Q1/mcode.png" alt="Fs = 44.1e3;
Span = 1e-3
hsin = dsp.SineWave('Amplitude',10,'Frequency',2.2e3,...
    'SampleRate', Fs, 'SamplesPerFrame', 10);
hts = dsp.TimeScope('SampleRate', Fs, 'TimeSpan', Span);

for ii = 1:1e5
    x = step(hsin);
    step(hts,x);
end"/></a></p>

<p>As soon as you click the Trigger button, the triggers panel open allowing you to configure options like level, type, polarity, etc.</p>

<p><a href="http://blogs.mathworks.com/images/seth/2013Q1/triggerDemo.gif"><img  src="http://blogs.mathworks.com/images/seth/2013Q1/triggerDemo.gif" alt="Configuring the trigger"/></a></p>

<p><strong>Runt Triggering</strong></p>

<p>What are Runt signals? Runt signals are the signals which typically cross a voltage threshold level but fail to cross a second threshold before re-crossing the first threshold level. Runt signals are frequently encountered in digital circuits.</p>

<p>For example if we look at the following waveform:</p>

<p><a href="http://blogs.mathworks.com/images/seth/2013Q1/pwm_best.gif"><img src="http://blogs.mathworks.com/images/seth/2013Q1/pwm_best.gif" alt="Noisy PWM signal"/></a></p>

<p>To look for Runt signals, Let us enable the Trigger, set the Trigger Mode to <em>Normal</em>, set the trigger type as <em>Runt</em>, adjust the voltage threshold and then the Time Scope detects and displays the presence of any Runt signals in the incoming data stream.</p>

<p><a href="http://blogs.mathworks.com/images/seth/2013Q1/runt.gif"><img src="http://blogs.mathworks.com/images/seth/2013Q1/runt.gif" alt="Runt Trigger"/></a></p>

<p><strong>Now it's your turn</strong></p>

<p>Go through the <a href="http://www.mathworks.com/help/dsp/ref/timescope.html#btsl04t">trigger documentation</a>, give this a try and let us know what you think by leaving a <a href="http://blogs.mathworks.com/seth/?p=1857&#comment">comment here</a>.</p>
<img src="http://feeds.feedburner.com/~r/SethOnSimulink/~4/hURwDXnGoDA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/seth/2013/03/25/new-for-r2013a-time-scope-with-triggering/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blogs.mathworks.com/seth/2013/03/25/new-for-r2013a-time-scope-with-triggering/</feedburner:origLink></item>
		<item>
		<title>Time to Convert to Variant Subsystems</title>
		<link>http://feedproxy.google.com/~r/SethOnSimulink/~3/7VJkSl73KVY/</link>
		<comments>http://blogs.mathworks.com/seth/2013/03/18/time-to-convert-to-variant-subsystems/#comments</comments>
		<pubDate>Mon, 18 Mar 2013 17:00:05 +0000</pubDate>
		<dc:creator>Guy Rouleau</dc:creator>
				<category><![CDATA[Modeling]]></category>
		<category><![CDATA[What's new?]]></category>
		<category><![CDATA[Configureable Subsystems]]></category>
		<category><![CDATA[Simulink]]></category>
		<category><![CDATA[Updgrade]]></category>
		<category><![CDATA[variant modeling]]></category>
		<category><![CDATA[Variant Subsystems]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/seth/?p=1977</guid>
		<description><![CDATA[If you are a user of Configurable Subsystems, it is time to start thinking about making the switch to Variant Systems. Simulink Variants provide increased functionality over Configurable Subsystems: They exist in two flavors: Model Variants and Subsystem Variants. They can be controlled programmatically via variables in the MATLAB workspace. They are in your model [...]]]></description>
			<content:encoded><![CDATA[<p>If you are a user of <a href="http://www.mathworks.com/help/releases/R2012b/simulink/slref/configurablesubsystem.html">Configurable Subsystems</a>, it is time to start thinking about making the switch to <a href="http://www.mathworks.com/help/releases/R2012b/ecoder/variant-systems.html">Variant Systems</a>.</p>

<p>Simulink Variants provide increased functionality over Configurable Subsystems: 

<ul>
	<li>They exist in two flavors: <a href="http://www.mathworks.com/help/simulink/slref/modelvariants.html">Model Variants</a> and <a href="http://www.mathworks.com/help/simulink/slref/variantsubsystem.html">Subsystem Variants</a>.</li>
	<li>They can be controlled programmatically via variables in the MATLAB workspace.</li>
	<li>They are in your model instead of a Simulink Library which simplifies model development.</li>
</ul>

Once you try the Simulink Variants, I guarantee you will immediately see their advantages and understand why we recommend moving away from Configurable Subsystems.</p> 

<p>Here are some tips to help you migrate.</p>

<p><strong>Upgrade Advisor</strong></p>

<p>In R2012b, the <a href="http://www.mathworks.com/help/releases/R2012b/simulink/ug/consulting-the-model-advisor.html#btiimgy-1">Upgrade Advisor </a> includes a check titled <a href="http://www.mathworks.com/help/releases/R2012b/simulink/slref/simulink-checks_bq6d4aa-1.html#btkt8nb-1">Identify configurable subsystem blocks for converting to variant subsystem blocks</a>.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q1/upgradeAdvisor.png" alt="Upgrade Advisor" /></p>

<p>If you run the check and a configurable subsystem is found, the result will tell you that "These blocks can be upgraded to variant subsystems as they have better programmatic control and code generation capabilities."</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q1/checkResult.png" alt="Upgrade Advisor" /></p>

<p><strong>Context Menu</strong></p>

<p>If you right-click on a configurable subsystem (or any subsystem), you will see a new option to convert the subsystem to a variant.</p>

<p><a href="http://blogs.mathworks.com/images/seth/2013Q1/convertToVariant.png"><img src="http://blogs.mathworks.com/images/seth/2013Q1/convertToVariant_small.png" alt="Upgrade Advisor" /></a></p>

<p>A window will allow you to specify some details needed for the conversion.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q1/configureVariantConversion.png" alt="Converting to Variant" /></p>

<p>and a new model will pop up with your new block converted to a variant subsystem. Notice the different icon in the lower left corner of the block, it indicates that the variant subsystem is configured to <a href="http://www.mathworks.com/help/releases/R2012b/simulink/ug/selecting-the-active-variant.html#bsk8ulq-1">override variant conditions</a> and behaves exactly like the original configurable subsystem.</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q1/newVariant.png" alt="New Variant Subsystem" /></p>

<p><strong>Now it's your turn</strong></p>

<p>Are you ready to move to Variant Subsystems? Let us know by leaving a <a href="http://blogs.mathworks.com/seth/?p=1977&#comment">comment here</a></p><img src="http://feeds.feedburner.com/~r/SethOnSimulink/~4/7VJkSl73KVY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/seth/2013/03/18/time-to-convert-to-variant-subsystems/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://blogs.mathworks.com/seth/2013/03/18/time-to-convert-to-variant-subsystems/</feedburner:origLink></item>
		<item>
		<title>Some of My Favorite New Features in R2013a</title>
		<link>http://feedproxy.google.com/~r/SethOnSimulink/~3/V7ObAhA3NvY/</link>
		<comments>http://blogs.mathworks.com/seth/2013/03/11/some-of-my-favorite-new-features-in-r2013a/#comments</comments>
		<pubDate>Mon, 11 Mar 2013 19:59:05 +0000</pubDate>
		<dc:creator>Guy Rouleau</dc:creator>
				<category><![CDATA[What's new?]]></category>
		<category><![CDATA[R2013a]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/seth/?p=2003</guid>
		<description><![CDATA[MATLAB R2013a is now available for download! At the end of this post, I reveal my favorite feature in R2013a... what will it be? For an overview of the new features, you can watch this release highlight video. If you want to go in to more details, you can consult the What's New page for [...]]]></description>
			<content:encoded><![CDATA[<p>MATLAB R2013a is now available for download!  At the end of this post, I reveal my favorite feature in R2013a... what will it be?</p>

<p><a href="http://www.mathworks.com/products/new_products/latest_features.htm"><img src="http://blogs.mathworks.com/images/seth/2013Q1/R2013aRelease.png" alt="R2013a is live!" /></a></p>

<p>For an overview of the new features, you can watch this <a href="http://www.mathworks.com/products/new_products/latest_features.html">release highlight video</a>.</p>

<p>If you want to go in to more details, you can consult the <strong>What's New</strong> page for individual products. Here is he link for <a href="http://www.mathworks.com/products/simulink/whatsnew.html">What's New in Simulink</a>.</p>

<p>Another good source of information I like to go through is the <a href="http://www.mathworks.com/help/simulink/release-notes.html">release notes</a>.</p>

<p>Here is a list of cool things you will notice for Simulink related products:</p>

<p><strong>Simulink</strong></p>

<ul>
	<li>Reordering of tabs in the Simulink Editor</li>

	<li>Arrays of buses <a href="http://www.mathworks.com/help/simulink/ug/importing-structures-of-matlab-timeseries-objects-for-bus-signals-to-a-root-level-input-port.html#btodj0v">loading </a>and <a href="http://www.mathworks.com/help/simulink/ug/arrays-of-buses-in-models.html#">logging</a></li>

	<li><a href="http://www.mathworks.com/academia/gumstix-overo/">Gumstix Overo Hardware Support</a></li>

	<li><a href="http://www.mathworks.com/academia/raspberry-pi/">Raspberry Pi Hardware Support</a></li>

	<li>Live update for variant systems and commented-out blocks</li>

	<li>Variant systems now accept direct expressions in variant control in addition to variant objects</li>

	<li><a href="http://www.mathworks.com/help/simulink/ug/creating-a-mask-hierarchy.html">
Masking of linked blocks</a></li>

	<li>Several enhancements to <a href="http://www.mathworks.com/help/simulink/multicore-processor-targets-1.html">concurrent execution</a></li>

	<li>Simplified scripting interface for automating Simulink Project tasks</li>

	<li>Added support for <a href="http://www.mathworks.com/help/simulink/ug/types-of-sample-time.html?s#brrdmmw-11">variable sample times</a> in referenced models</li>

	<li>The Sample Time Legend now displays the source of triggered subsystem sample times. </li>
</ul>

<p><strong>DSP System Toolbox</strong></p>
<ul>

	<li><a href="http://www.mathworks.com/help/dsp/ref/spectrumanalyzer.html">Spectrum Analyzer Scope</a></li>
	<li><a href="http://www.mathworks.com/help/dsp/ref/dsp.logicanalyzerclass.html">Logic Analyzer Scope</a></li>
	<li>Triggering and peak finder features for the <a href="http://www.mathworks.com/help/dsp/ref/timescope.html">Time Scope</a></li>

</ul>

<p><strong>Simscape</strong></p>
<ul>
	<li>Vector and matrix physical signals</li>
	<li>New blocks: <a href="http://www.mathworks.com/help/physmod/simscape/ref/randomnumber.html">Random Number</a>, <a href="http://www.mathworks.com/help/physmod/simscape/ref/uniformrandomnumber.html">Uniform Random Number</a>, <a href="http://www.mathworks.com/help/physmod/simscape/ref/perfectinsulator.html">Perfect Insulator</a> for thermal domain</li>



</ul>




<p><strong>SimMechanics</strong></p>

<ul>
	<li>New blocks: <a href="http://www.mathworks.com/help/physmod/sm/ref/commongear.html">Common Gear</a>, <a href="http://www.mathworks.com/help/physmod/sm/ref/rackandpinion.html">Rack and Pinion</a>, <a href="http://www.mathworks.com/help/physmod/sm/ref/pinslotjoint.html">Pin Slot Joint</a>, <a href="http://www.mathworks.com/help/physmod/sm/ref/internalforce.html">Internal Force</a></li>

	<li><a href="http://www.mathworks.com/help/physmod/sm/ug/about-the-simmechanics-xml-import-file.html">Published XML Schema for model import</a>, enabling users to import mechanical models from external applications such as CAD systems</li>


</ul>



<p><strong>SimRF</strong></p>
<ul>
	<li><a href="http://www.mathworks.com/products/simrf/">SimRF</a> has a new <a href="http://www.mathworks.com/help/simrf/release-notes.html">Circuit Envelope solver</a> for fast simulation and model load time</li>
</ul>


<p><strong>Documentation</strong></p>

<p>Finally, I have to admit that some of my favorite improvements in R2013a are the enhancements made to the documentation center:</p>

<ul>
	<li>Highlighting of search results</li>
	<li>Tree view of the documentation</li>
</ul>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q1/doc_tree_view.png" alt="R2013a Documentation Center" /></p>

<p><strong>Now it's your turn</strong></p>

<p>Let us know what is your favorite R2013a feature by leaving a <a href="http://blogs.mathworks.com/seth/?p=2003&#comment">comment here</a>.</p><img src="http://feeds.feedburner.com/~r/SethOnSimulink/~4/V7ObAhA3NvY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/seth/2013/03/11/some-of-my-favorite-new-features-in-r2013a/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://blogs.mathworks.com/seth/2013/03/11/some-of-my-favorite-new-features-in-r2013a/</feedburner:origLink></item>
		<item>
		<title>MATLAB Language in Stateflow</title>
		<link>http://feedproxy.google.com/~r/SethOnSimulink/~3/5qXGtpnp3OM/</link>
		<comments>http://blogs.mathworks.com/seth/2013/02/28/matlab-language-in-stateflow/#comments</comments>
		<pubDate>Thu, 28 Feb 2013 16:22:38 +0000</pubDate>
		<dc:creator>Guy Rouleau</dc:creator>
				<category><![CDATA[Stateflow]]></category>
		<category><![CDATA[What's new?]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/seth/?p=1428</guid>
		<description><![CDATA[Have you noticed a new block in the Stateflow Library since R2012b? The MATLAB Chart block uses MATLAB as the action language for states and transitions in Stateflow. This means that you don't have to create a separate MATLAB Function every time you want to do matrix math in a Stateflow chart. Let's look at [...]]]></description>
			<content:encoded><![CDATA[<p>Have you noticed a new block in the Stateflow Library since R2012b?</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q1/ML_chart_in_library.png" alt="Chart (MATLAB)" /></p>

<p>The <a href="http://www.mathworks.com/help/releases/R2012b/stateflow/ref/matlabchart.html">MATLAB Chart</a> block uses <a href="http://www.mathworks.com/help/releases/R2012b/stateflow/matlab-syntax-for-states-and-transitions.html">MATLAB as the action language for states and transitions in Stateflow</a>.</p>

<p>This means that you don't have to create a separate <a href="http://www.mathworks.com/help/releases/R2012b/stateflow/ug/building-a-model-with-a-matlab-function-in-a-chart.html">MATLAB Function</a> every time you want to do matrix math in a Stateflow chart. Let's look at a few examples of what can be done in a MATLAB Chart.</p>

<p><strong>Matrix Operations</strong></p>

<p>Let's say I define a bus object containing a <tt>3x1</tt> position vector and a <tt>3x3</tt> rotation matrix:</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q1/bus_object_for_sf.png" alt="Bus Object" /></p>

<p>With MATLAB as the action language, I can multiply the bus elements directly in a transition action:</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q1/matrix_multiply_in_sf.png" alt="matrix multiplication in stateflow" /></p>

<p><strong>Access to all MATLAB Coder supported functions</strong></p>

<p>With MATLAB as the action language, you can use any <a href="http://www.mathworks.com/help/releases/R2012b/simulink/ug/functions-supported-for-code-generation--alphabetical-list.html">function supported by MATLAB Coder for code generation</a>. For example, I can use the functions like <a href="http://www.mathworks.com/help/releases/R2012b/matlab/ref/ones.html">ones</a> and <a href="http://www.mathworks.com/help/releases/R2012b/matlab/ref/eig.html">eig</a> in a transition:</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q1/matlabfunctions_in_sf.png" alt="Using MATLAB Functions in transition actions" /></p>

<p><strong>Manipulating Arrays of buses</strong></p>

<p>Let's say I want my chart to generate an array of the bus defined previously, I could write something like:</p>

<p><img src="http://blogs.mathworks.com/images/seth/2013Q1/array_of_buses_in_ML_chart.png" alt="Manipulating arrays of buses in Stateflow" /></p>

<p><strong>Conclusion</strong></p>

<p>Based on my experience, using MATLAB as the action language in Stateflow charts makes it a lot easier to implement the algorithms I need. Since I first tried it, I have not needed to use C as the action language.</p>

<p>Of course, the MATLAB Chart block is not the best choice for all applications. If your application is interfacing with legacy C functions or more naturally expressed in C language, than there is no need to switch. The <a href="http://www.mathworks.com/help/releases/R2012b/stateflow/ref/cchart.html">C chart</a> block that we are all used to still continues to be developed and supported.</p>

<p>If you need help deciding which block to use, I recommend looking at the <a href="http://www.mathworks.com/help/stateflow/ug/differences-between-matlab-and-stateflow-action-language.html">Differences Between MATLAB and C as Action Language Syntax</a> in the Stateflow documentation.</p>

<p><strong>Now it's your turn</strong></p>

<p>Have you tried using MATLAB as the action language in your Stateflow charts? Let us know what you think by leaving a <a href="http://blogs.mathworks.com/seth/?p=1428&#comment">comment here</a>.</p>


<img src="http://feeds.feedburner.com/~r/SethOnSimulink/~4/5qXGtpnp3OM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/seth/2013/02/28/matlab-language-in-stateflow/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://blogs.mathworks.com/seth/2013/02/28/matlab-language-in-stateflow/</feedburner:origLink></item>
	</channel>
</rss>
