{"id":137,"date":"2011-04-15T20:57:11","date_gmt":"2011-04-15T20:57:11","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/2011\/04\/15\/introducing-the-system-toolboxes\/"},"modified":"2011-04-15T20:57:11","modified_gmt":"2011-04-15T20:57:11","slug":"introducing-the-system-toolboxes","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2011\/04\/15\/introducing-the-system-toolboxes\/","title":{"rendered":"Introducing the System Toolboxes"},"content":{"rendered":"<p>This week I am teaming up with my colleague Ken Karnofsky to introduce another big change in MATLAB R2011a.<\/p>\r\n\r\n<p><strong>Guy:<\/strong>  So Ken, what is this big change?<\/p>\r\n\r\n<p><strong>Ken:<\/strong> In MATLAB R2011a, not only the code generation products changed. The products for designing signal processing algorithms have also been reorganized. Here is a visual summary what\u2019s happening:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2011Q2\/SystemToolboxes.png\" alt=\"Changes in product names in MATLAB R2010a\"><\/p>\r\n\r\n<p><strong>Guy:<\/strong> What is a System Toolbox?<\/p>\r\n\r\n<p><strong>Ken:<\/strong> Last year, we introduced a new technology in several blocksets called <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011a\/toolbox\/dsp\/gs\/br4nxx9-1.html\">System objects<\/a>. System objects are pre-defined algorithms for MATLAB with functionality that had previously been available only to Simulink users, such as fast stream processing, implicit state handling, design options such as fixed-point, and code generation support. <\/p>\r\n\r\n<p>With the System Toolboxes, you can design signal processing algorithms suitable for fast simulation, real-time prototyping, and embedded implementation. Any MATLAB algorithm that you design for code generation, including the use of System objects, is reusable in Simulink using the new <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011a\/toolbox\/simulink\/slref\/matlabfunction.html\">MATLAB function block<\/a>.<\/p>\r\n\r\n<p><strong>Guy: <\/strong> That sounds pretty cool. Let's see how we can identify a system using an LMS adaptive filter, and implement it in 3 different ways:<\/p>\r\n\r\n<p><strong>MATLAB script<\/strong><\/p>\r\n\r\n<p>In this example, I create a <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011a\/toolbox\/dsp\/ref\/dsp.lmsfilterclass.html\">dsp.LMSFilter<\/a> object and a <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011a\/toolbox\/dsp\/ref\/dsp.digitalfilterclass.html\">dsp.DigitalFilter<\/a> object. Then I use the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011a\/toolbox\/dsp\/gs\/bsmo23q.html#bsmpb0_-1\">step<\/a> method to process data using the algorithm defined by each objects. Executing step 10 times in a loop is similar to running a Simulink model for 10 time steps.<\/p>\r\n\r\n<style type=\"text\/css\">\r\n\r\npre.codeinput {\r\n  background: #EEEEEE;\r\n  padding: 10px;\r\n}\r\n\r\nspan.keyword {color: #0000FF}\r\nspan.comment {color: #228B22}\r\nspan.string {color: #A020F0}\r\nspan.untermstring {color: #B20000}\r\nspan.syscmd {color: #B28C00}\r\n  <\/style>\r\n<p>\r\n<pre class=\"codeinput\">\r\n<span class=\"comment\">% Create adaptive filter object<\/span>\r\nhlms = dsp.LMSFilter(11, <span class=\"string\">'StepSize'<\/span>, 0.01);\r\n<span class=\"comment\">% Create system to be identified... an FIR filter.<\/span>\r\nhfilt = dsp.DigitalFilter(<span class=\"string\">'TransferFunction'<\/span>, <span class=\"string\">'FIR (all zeros)'<\/span>, <span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'Numerator'<\/span>, fir1(10, .25));\r\n\r\n<span class=\"comment\">% Run 10 iterations of filter adaptation<\/span>\r\n<span class=\"keyword\">for<\/span> i = 1:10\r\n    <span class=\"comment\">% Input to the system<\/span>\r\n    x = randn(100,1);\r\n    <span class=\"comment\">% We measure some output to the system, including noise<\/span>\r\n    d = step(hfilt, x) + 0.01*randn(100,1);\r\n    <span class=\"comment\">% Now let's run our adaptive filter<\/span>\r\n    [y,~,w] = step(hlms, x, d);\r\n    <span class=\"comment\">% compare the measured and identified outputs<\/span>\r\n    diff(i) = sqrt(sum((y-d).^2));\r\n<span class=\"keyword\">end<\/span>\r\n<\/pre>\r\n<\/p>\r\n<br>\r\n\r\n<p>After writing this script, I can see <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011a\/toolbox\/dsp\/gs\/bsmo23q.html#bsmpb0h-1\">advantages of using System objects<\/a>.  After I initialize the object, all I have to do is call the step method in a loop to process data. The implementation of the step method is very efficient because it does not include the same overhead normally required for MATLAB functional programming.<\/p>\r\n\r\n<p>If your goal is to target an embedded processor, you can use <a href=\"https:\/\/blogs.mathworks.com\/seth\/2011\/04\/08\/welcome-to-the-coders\/\">MATLAB Coder<\/a> and generate C code directly from this algorithm. If you want to integrate this algorithm into a Simulink model...<\/p>\r\n\r\n<strong><p>MATLAB Function Block<\/p><\/strong>\r\n\r\n<p>With the MATLAB Function block and System objects, it is easy to bring an algorithm created in MATLAB into Simulink. To implement the same adaptive filter example, I made the following model:<\/p>\r\n\r\n  <p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2011Q2\/matlabFcnBlock.png\" alt=\"Adaptive LMS filter implemented using System objects in MATLAB Function Block\"><\/p>\r\n\r\n<p>Then I define the FIR Filter and Adaptive Filter in the MATLAB Function block. I initialize the System objects on the first time step of the model and declare them as <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011a\/techdoc\/\/ref\/persistent.html\">persistent<\/a> so they can keep their states between each time step. <\/p>\r\n\r\n  <p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2011Q2\/MATLABFcnBlockCode.png\" alt=\"Adaptive LMS filter implemented using System objects in MATLAB Function Block\"><\/p>\r\n\r\n<p>Of course it is possible to combine many System objects inside one MATLAB Function block and create more complex components.<\/p>\r\n\r\n<strong><p>Simulink blocks<\/p><\/strong>\r\n\r\n<p>For users who prefer just connecting blocks without typing code, don't worry! The System Toolboxes include ready to use Simulink libraries. The blocks in the Simulink libraries use the same System objects under the hood. For this example, here is how my model looks implemented using blocks from the DSP System Toolbox:<\/p>\r\n\r\n  <p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2011Q2\/SimulinkBlocks.png\" alt=\"Adaptive LMS filter implemented using Simulink blocks\"><\/p>\r\n\r\n<p><strong>Now it\u2019s your turn<\/strong><\/p>\r\n\r\n<p>Are you going to try the new System objects in your MATLAB code?  Are you using MATLAB algorithms in your Simulink models? Let us know by leaving a <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=137&#comment\">comment here<\/a>.<\/p>\r\n\r\n\r\n","protected":false},"excerpt":{"rendered":"<p>This week I am teaming up with my colleague Ken Karnofsky to introduce another big change in MATLAB R2011a.\r\n\r\nGuy:  So Ken, what is this big change?\r\n\r\nKen: In MATLAB R2011a, not only the code... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2011\/04\/15\/introducing-the-system-toolboxes\/\">read more >><\/a><\/p>","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[21,73,16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/137"}],"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=137"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/137\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}