{"id":2479,"date":"2013-08-21T07:48:56","date_gmt":"2013-08-21T12:48:56","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/?p=2479"},"modified":"2018-09-11T12:58:52","modified_gmt":"2018-09-11T17:58:52","slug":"a-logic-analyzer-for-matlab-and-simulink","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2013\/08\/21\/a-logic-analyzer-for-matlab-and-simulink\/","title":{"rendered":"A Logic Analyzer for MATLAB and Simulink"},"content":{"rendered":"<p>When I wrote a post about the new features available in MATLAB R2013a, I got a <a href=\"https:\/\/blogs.mathworks.com\/seth\/2013\/03\/11\/some-of-my-favorite-new-features-in-r2013a\/#comment-22035\">request<\/a> to provide details on the new <a title=\"https:\/\/www.mathworks.com\/help\/dsp\/ref\/dsp.logicanalyzerclass.html (link no longer works)\">Logic Analyzer system object<\/a> included in the <a href=\"https:\/\/www.mathworks.com\/products\/dsp-system\/\">DSP System Toolbox<\/a>. <\/p>\r\n\r\n<p>Since I am not an expert in this area, I asked my colleague <a href=\"https:\/\/www.mathworks.com\/products\/signal\/expert-contact.html\">Kirthi Devleker<\/a> to come back as guest blogger and give us an introduction on this long-requested feature.<\/p>\r\n\r\n<p><strong>The Logic Analyzer<\/strong><\/p>\r\n\r\n<p><strong>Guy:<\/strong> Before talking about the DSP System Toolbox Logic Analyzer... what is a logic analyzer?<\/p>\r\n\r\n<p><strong>Kirthi:<\/strong> A logic analyzer is a tool which helps visualize and evaluate digital signals over time. On the market, you can find hardware and software versions. This is very useful when debugging or characterizing digital systems.<\/p>\r\n\r\n<p><strong>Guy:<\/strong> Ok... but what does that look like?<\/p>\r\n\r\n<p><strong>Kirthi:<\/strong> Since we are on a Simulink blog, let's start with a Simulink example. In R2013a, there is no Logic Analyzer block in the Simulink Library browser, but we provide a utility (<tt>analyzeLogicFromSimulink<\/tt>) to display logged data.<\/p>\r\n\r\n<p>Let's use the demo model <a href=\"https:\/\/www.mathworks.com\/help\/comm\/examples\/using-hdl-optimized-crc-library-blocks.html\"><tt>commcrchdl<\/tt><\/a> from the <a href=\"https:\/\/www.mathworks.com\/products\/communications.html\">Communications Toolbox<\/a>.<\/p>\r\n\r\n<p><em>Comment from Seth: What does CRC mean? Answer: <a href=\"http:\/\/en.wikipedia.org\/wiki\/Cyclic_redundancy_check\">http:\/\/en.wikipedia.org\/wiki\/Cyclic_redundancy_check<\/a><\/em><\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/commcrdhdl.png\" alt=\"Example model from Communication Toolbox\" \/><\/p>\r\n\r\n<p>In this example, we want to analyze the relation between many signals, and how they transition over time. Without the Logic Analyzer, you would probably try to observe the signals using a <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/scope.html\">Scope<\/a> block:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/logicOnScope.png\" alt=\"Analyzing signals using a Scope\" \/><\/p>\r\n\r\n<p>As you can see, analyzing the evolution of those 7 signals and their relation over time is not easy. With the Logic Analyzer, the same signals look like:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/logicOnLogicAnalyzer.png\" alt=\"Analyzing signals using Logic Analyzer\" \/><\/p>\r\n\r\n<p><strong>Guy:<\/strong> Wow, the advantage is pretty obvious. Now, can you give us some details on how to get started with the Logic Analyzer?<\/p>\r\n\r\n<p><strong>Getting Started with The Logic Analyzer<\/strong><\/p>\r\n\r\n<p><strong>Kirthi:<\/strong> The first thing to note is that the Logic Analyzer is a <a title=\"https:\/\/www.mathworks.com\/help\/dsp\/define-new-system-objects.html (link no longer works)\">System object<\/a>. As with most system objects, you first need to instantiate it. Then you can programmatically configure the analyzer and add waves using the <a href=\"https:\/\/www.mathworks.com\/help\/dsp\/ref\/dsp.logicanalyzer.addwave.html\">addWave<\/a> method.\r\n\r\n<p>In the following example, we create a Logic Analyzer with 2 input ports and 3 waveforms. The second and third waveforms will be used to display the second input in two different ways.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/code_snippet.png\" alt=\"Example code configuring the logic analyzer\" \/><\/p>\r\n\r\n<p><strong>Guy: <\/strong> Do I need to configure everything programmatically?<\/p>\r\n\r\n<p><strong>Kirthi:<\/strong> No! Everything you can do programmatically can be done using the user interface. Here is an animation illustrating that:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/configuringLogicAnalyzer.gif\" alt=\"Configuring the logic analyzer\" \/><\/p>\r\n\r\n<p>Here is another animation showing more possibilities of the Logic Analyzer like adding dividers, cursors and changing colors:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/analyzeLogicfromSimulink.gif\" alt=\"Configuring the logic analyzer... part 2\" \/><\/p>\r\n\r\n<p><strong>Now it's your turn<\/strong><\/p>\r\n\r\n<p>Try the new Logic Analyzer and let us know what you think by leaving a <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=2479&#comment\">comment here<\/a>.<\/p>\r\n\r\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/analyzeLogicfromSimulink.gif\" onError=\"this.style.display ='none';\" \/><\/div><p>When I wrote a post about the new features available in MATLAB R2013a, I got a request to provide details on the new Logic Analyzer system object included in the DSP System Toolbox. \r\n\r\nSince I am... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2013\/08\/21\/a-logic-analyzer-for-matlab-and-simulink\/\">read more >><\/a><\/p>","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[336],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/2479"}],"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=2479"}],"version-history":[{"count":35,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/2479\/revisions"}],"predecessor-version":[{"id":7955,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/2479\/revisions\/7955"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=2479"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=2479"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=2479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}