{"id":144,"date":"2011-06-28T12:56:17","date_gmt":"2011-06-28T12:56:17","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/2011\/06\/28\/variable-size-signals-and-unit-delay\/"},"modified":"2011-06-28T12:56:17","modified_gmt":"2011-06-28T12:56:17","slug":"variable-size-signals-and-unit-delay","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2011\/06\/28\/variable-size-signals-and-unit-delay\/","title":{"rendered":"Variable-size signals and Unit Delay"},"content":{"rendered":"<p>I received requests recently about variable-size signals and the Unit Delay block.<\/p> \r\n\r\n<p><strong>One question, many answers<\/strong><\/p>\r\n\r\n<p><em>What should a Unit Delay do when the size of a signal changes?<\/em><\/p> \r\n\r\n<p>Unfortunately, there is not only one correct answer to this question. Let's say I have a Unit Delay block and its input signal changes from a size of 3 to a size of 2, what should the output be? When should the dimension of the output change?<\/p>\r\n\r\n<p>Let's look at the options you have.<\/p>\r\n\r\n<strong><p>MathWorks Solution<\/p><\/strong>\r\n\r\n<p>As explained in <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011a\/toolbox\/simulink\/ug\/br65qom-1.html\">Variable-Size Signal Basics<\/a>, blocks supporting variable-size signals can propagate sizes in one of two ways:<\/p>\r\n\r\n<ul>\t\r\n<li>At every step of model execution<\/li>\r\n<li>During initialization of a conditionally executed subsystem<\/li>\r\n<\/ul>\r\n\r\n<p>How do you know into which category a specific block is? A good rule is that, most blocks with states fall in the second category. To ensure consistency and avoid confusion, those blocks are allowed to propage sizes only during the initialization of a conditionally executed system.<\/p>\r\n\r\n<p><strong>Let's look at an example<\/strong><\/p> \r\n\r\n<p>Here I create a variable-size signal by alternating between 3 constants and 2 random numbers. If I want to apply a <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011a\/toolbox\/simulink\/slref\/unitdelay.html\">Unit Delay<\/a> to this signal, I need to place it inside a Conditionally Executed Subsystem and ensure that the subsystem is enabled and disabled every time the dimension change. Here I do that using a <a href=\"https:\/\/www.mathworks.com\/products\/stateflow\/\">Stateflow Chart<\/a>:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2011Q2\/UnitDelayMdl.png\" alt=\"Example model showing how to use the Unit Delay with variable-size signals\"><\/p>\r\n\r\n<p>The result is that every time the dimension changes, the state of the Unit Delay is reset to its initial condition, zero in this example:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2011Q2\/UnitDelayMdl_data.png\" alt=\"Data passing through a Unit Delay with variable-size signals\"><\/p>\r\n\r\n\r\n<p><strong>My Alternative Solution<\/strong><\/p>\r\n\r\n<p>For many reasons, one might need a Unit Delay block who works with variable-size signals, but who does not need to be placed inside a conditionally executed subsystem. To help you getting started with that, I created <a href=\"https:\/\/www.mathworks.com\/support\/solutions\/en\/data\/1-ET7RPB\/index.html\">technical solution 1-ET7RPB<\/a>. I am not going into the details here, but this solution contains the MATLAB and C versions of my alternative version of a Unit Delay block implemented as an S-Function. <\/p>\r\n\r\n<p>To process a signal similar to the previous example, this Unit Delay block does not need to be placed inside a conditionally executed subsystem:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2011Q2\/UnitDelay2.png\" alt=\"Data passing through a Unit Delay with variable-size signals\"><\/p>\r\n\r\n<p>Instead, the dimension of the output changes one time step after the dimension of the input:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2011Q2\/UnitDelay2_data.png\" alt=\"Data passing through the custom Unit Delay with variable-size signals\"><\/p>\r\n\r\n<p>If you are interested, you can download all the files in this example from <a href=\"https:\/\/www.mathworks.com\/support\/solutions\/en\/data\/1-ET7RPB\/index.html\">technical solution 1-ET7RPB<\/a>.<\/p>\r\n\r\n<strong><p>Now it's your turn<\/p><\/strong>\r\n\r\n<p>How do you think a unit delay should behave with variable-size signal? Leave us a <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=144&amp;#comment\">comment here<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>I received requests recently about variable-size signals and the Unit Delay block. \r\n\r\nOne question, many answers\r\n\r\nWhat should a Unit Delay do when the size of a signal changes? \r\n\r\nUnfortunately,... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2011\/06\/28\/variable-size-signals-and-unit-delay\/\">read more >><\/a><\/p>","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[87,11],"tags":[441,206,205],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/144"}],"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=144"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/144\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}