{"id":4593,"date":"2013-05-24T09:00:03","date_gmt":"2013-05-24T13:00:03","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=4593"},"modified":"2018-01-08T15:48:02","modified_gmt":"2018-01-08T20:48:02","slug":"delta-sigma-toolbox","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2013\/05\/24\/delta-sigma-toolbox\/","title":{"rendered":"Delta Sigma Toolbox"},"content":{"rendered":"\r\n<div class=\"content\"><p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/29096\">Idin<\/a>'s pick for this week is the <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/19-delta-sigma-toolbox\">Delta Sigma Toolbox<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/735\">Richard Schreier<\/a>.<\/p><p><a href=\"http:\/\/en.wikipedia.org\/wiki\/Delta-sigma_modulation\">Delta-Sigma<\/a> (or sigma-delta) modulators are commonly found in electronic components such as analog-to-digital and digital-to-analog converters (ADCs and DACs), and increasingly in [fractional-N] frequency synthesizers (PLLs), and switch-mode power supplies.  Generally speaking, a delta-sigma modulator produces a highly over-sampled binary signal at its output (0\/1) which can be low-pass filtered to reproduce the input signal. Figure 1 below shows an example input &amp; output signal. To read more about delta-sigma modulators, go <a href=\"http:\/\/en.wikipedia.org\/wiki\/Delta-sigma_modulation\">here<\/a>, <a href=\"http:\/\/skywired.net\/blog\/2011\/05\/introducing-the-delta-sigma-modulator\/\">here<\/a>, and <a href=\"\">here<\/a>. Richard&#8217;s textbook is also a good resource: \"Understanding Delta-Sigma Data Converters\" by Schreier and Temes (ISBN 0-471-46585-2).<\/p><p>There is a large body of literature dedicated to analysis and design of delta-sigma modulators, and the Delta Sigma Toolbox provides a great tool for analyzing these components in MATLAB. The toolbox contains a fairly complete list of well documented functions to construct, analyze, and simulate delta-sigma modulators of arbitrary order. The full documentation for the toolbox is provided in DSToolbox.pdf (part of the download).<\/p><p>To start using the toolbox, I highly recommend studying the provided example and demo files (<tt>dsdemo1-8.m<\/tt> and <tt>dsexample1-4.m<\/tt>). I like dsdemo2.m as a starting tutorial.  It begins by creating a noise transfer function (NTF), and then simulates the modulator with an example sinusoidal input:<\/p><pre class=\"language-matlab\">OSR = 32;\r\nH = synthesizeNTF(5,OSR,1);\r\nN = 8192;\r\nfB = ceil(N\/(2*OSR)); ftest=floor(2\/3*fB);\r\nu = 0.5*sin(2*pi*ftest\/N*[0:N-1]);  <span class=\"comment\">% half-scale sine-wave input<\/span>\r\nv = simulateDSM(u,H);\r\n<\/pre><p>The time domain output shows the sinusoidal input (red) and the binary output (green).<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/idin\/potw_deltasigma\/sigma_delta_fig1.png\" alt=\"\"> <\/p><p>The spectrum of the output can also be easily computed using MATLAB's FFT function:<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/idin\/potw_deltasigma\/sigma_delta_fig2.png\" alt=\"\"> <\/p><p>This figure looks like the superposition of two signals: the spike at ftest\/N (0.0104 in this case) which represents the input sinusoid, and some high frequency \"noise\". The high-pass noise is in fact one of the desirable properties of delta-sigma converters; these converters shift the quantization noise to high frequencies, i.e., away from our signal\/carrier of interest. It should be self-evident from Figure 2 that a simple low-pass filter of this output signal would yield the original sinusoidal input.<\/p><p>The next few lines in dsdemo2.m compute the SNR on the output signal, and also use Delta Sigma Toolbox functions to compute and display the expected (theoretical) response of the modulator (shown in pink blow).<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/idin\/potw_deltasigma\/sigma_delta_fig3.png\" alt=\"\"> <\/p><p>The next section of the code computes the expected and simulated signal-to-quantization-noise ( <a href=\"http:\/\/en.wikipedia.org\/wiki\/Signal-to-quantization-noise_ratio\">SQNR<\/a>), which is a figure of merit when analyzing analog-to-digital converters.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/idin\/potw_deltasigma\/sigma_delta_fig4.png\" alt=\"\"> <\/p><p>The remainder of this demo essentially repeats the same process, but for a band-pass signal. That is, instead of using a low frequency sinusoid as the input, it uses a carrier signal, which makes our output spectrum look as in Figure 5 (the carrier here is at Fs\/8 or 0.125 on the normalized frequency axis).<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/idin\/potw_deltasigma\/sigma_delta_fig5.png\" alt=\"\"> <\/p><p>I encourage you to download the toolbox and run through the demos.  Even if you do not use the toolbox for any simulations of your own, these demos can serve as a great learning tool (along with freely available online resources mentioned above).<\/p><p><b>Other MathWorks resources:<\/b><\/p><p>If you are interested in delta-sigma modulators (and other mixed-signal components), consider downloading the <a >Mixed-Signal Library for Simulink<\/a>. Also, take a look at the MathWorks <a href=\"https:\/\/www.mathworks.com\/solutions\/mixed-signal-systems\/index.html\">Mixed-Signal page<\/a>, particularly the ADC section.<\/p><p><b>Delta-Sigma Toolbox Usage notes:<\/b><\/p><div><ul><li>A few C files are provided in the Toolbox that the user needs to compile to MEX (e.g., simulateDSM.c). This is generally done as:<\/li><\/ul><\/div><pre class=\"language-matlab\">mex <span class=\"string\">simulateDSM.c<\/span>\r\n<\/pre><p>But as noted in the comments on File Exchange, this fails on some systems. Simply defining the <tt><i>_STDC<\/i>_<\/tt> symbol should resolve the issue:<\/p><pre class=\"language-matlab\">mex <span class=\"string\">simulateDSM.c<\/span> <span class=\"string\">&#8211;D__STDC__<\/span>\r\n<\/pre><p>Note that you will need a C compiler for this step. Run <tt>mex &#8211;setup<\/tt> at the MATLAB command prompt to setup your C compiler.<\/p><div><ul><li>If you plan on using the Delta Sigma Toolbox frequently, you should probably add the toolbox folder to your MATLAB path:<\/li><\/ul><\/div><pre class=\"language-matlab\">addpath(<span class=\"string\">'&lt;your_intall_path&gt;\\delsig'<\/span>)\r\nsavepath\r\n<\/pre><p><b>Suggestions for improvements<\/b><\/p><div><ul><li>A great addition to the provided example\/demo files would be the use of <a title=\"https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/run-sections-of-programs.html (link no longer works)\">sections<\/a>, and perhaps the <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/publish.html\">publish<\/a> feature to include a full write-up and description for each file.<\/li><li>Providing an Install script would be great (to take care of MATLAB path and compiling MEX files).<\/li><\/ul><\/div><p><b>Comments<\/b><\/p><p>As always, your thoughts and comments <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=4593#respond\">here<\/a> are greatly appreciated.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_b26f6b48768c46f4b1666410109bae1d() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='b26f6b48768c46f4b1666410109bae1d ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' b26f6b48768c46f4b1666410109bae1d';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        copyright = 'Copyright 2013 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_b26f6b48768c46f4b1666410109bae1d()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2013a<br><\/p><p class=\"footer\"><br>\r\n      Published with MATLAB&reg; R2013a<br><\/p><\/div><!--\r\nb26f6b48768c46f4b1666410109bae1d ##### SOURCE BEGIN #####\r\n%%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/29096\r\n% Idin>'s pick for this week is the\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/19-delta-sigma-toolbox\r\n% Delta Sigma Toolbox> by\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/735 Richard\r\n% Schreier>.\r\n%\r\n% <http:\/\/en.wikipedia.org\/wiki\/Delta-sigma_modulation Delta-Sigma> (or\r\n% sigma-delta) modulators are commonly found in electronic components such\r\n% as analog-to-digital and digital-to-analog converters (ADCs and DACs),\r\n% and increasingly in [fractional-N] frequency synthesizers (PLLs), and\r\n% switch-mode power supplies.  Generally speaking, a delta-sigma modulator\r\n% produces a highly over-sampled binary signal at its output (0\/1) which\r\n% can be low-pass filtered to reproduce the input signal. Figure 1 below\r\n% shows an example input & output signal. To read more about delta-sigma\r\n% modulators, go <http:\/\/en.wikipedia.org\/wiki\/Delta-sigma_modulation\r\n% here>,\r\n% <http:\/\/skywired.net\/blog\/2011\/05\/introducing-the-delta-sigma-modulator\/\r\n% here>, and\r\n% <\r\n% here>. Richard\u00e2\u20ac\u2122s textbook is also a good resource: \"Understanding\r\n% Delta-Sigma Data Converters\" by Schreier and Temes (ISBN 0-471-46585-2).\r\n%\r\n% There is a large body of literature dedicated to analysis and design of\r\n% delta-sigma modulators, and the Delta Sigma Toolbox provides a great tool\r\n% for analyzing these components in MATLAB. The toolbox contains a fairly\r\n% complete list of well documented functions to construct, analyze, and\r\n% simulate delta-sigma modulators of arbitrary order. The full\r\n% documentation for the toolbox is provided in DSToolbox.pdf (part of the\r\n% download).\r\n%\r\n% To start using the toolbox, I highly recommend studying the provided\r\n% example and demo files (|dsdemo1-8.m| and |dsexample1-4.m|). I like\r\n% dsdemo2.m as a starting tutorial.  It begins by creating a noise transfer\r\n% function (NTF), and then simulates the modulator with an example\r\n% sinusoidal input:\r\n%\r\n%   OSR = 32;\r\n%   H = synthesizeNTF(5,OSR,1);\r\n%   N = 8192;\r\n%   fB = ceil(N\/(2*OSR)); ftest=floor(2\/3*fB);\r\n%   u = 0.5*sin(2*pi*ftest\/N*[0:N-1]);  % half-scale sine-wave input\r\n%   v = simulateDSM(u,H); \r\n% \r\n% The time domain output shows the sinusoidal input (red) and the binary\r\n% output (green).\r\n%\r\n% <<sigma_delta_fig1.png>>\r\n%  \r\n% The spectrum of the output can also be easily computed using MATLAB's FFT\r\n% function:\r\n%\r\n% <<sigma_delta_fig2.png>>\r\n%\r\n% This figure looks like the superposition of two signals: the spike at\r\n% ftest\/N (0.0104 in this case) which represents the input sinusoid, and\r\n% some high frequency \"noise\". The high-pass noise is in fact one of the\r\n% desirable properties of delta-sigma converters; these converters shift\r\n% the quantization noise to high frequencies, i.e., away from our\r\n% signal\/carrier of interest. It should be self-evident from Figure 2 that\r\n% a simple low-pass filter of this output signal would yield the original\r\n% sinusoidal input.\r\n%\r\n% The next few lines in dsdemo2.m compute the SNR on the output signal, and\r\n% also use Delta Sigma Toolbox functions to compute and display the\r\n% expected (theoretical) response of the modulator (shown in pink blow).\r\n%\r\n% <<sigma_delta_fig3.png>>\r\n%\r\n% The next section of the code computes the expected and simulated\r\n% signal-to-quantization-noise (\r\n% <http:\/\/en.wikipedia.org\/wiki\/Signal-to-quantization-noise_ratio SQNR>), which\r\n% is a figure of merit when analyzing analog-to-digital converters.\r\n%\r\n% <<sigma_delta_fig4.png>>\r\n%\r\n% The remainder of this demo essentially repeats the same process, but for\r\n% a band-pass signal. That is, instead of using a low frequency sinusoid\r\n% as the input, it uses a carrier signal, which makes our output spectrum\r\n% look as in Figure 5 (the carrier here is at Fs\/8 or 0.125 on the\r\n% normalized frequency axis).\r\n%\r\n% <<sigma_delta_fig5.png>>\r\n%\r\n% I encourage you to download the toolbox and run through the demos.  Even\r\n% if you do not use the toolbox for any simulations of your own, these\r\n% demos can serve as a great learning tool (along with freely available\r\n% online resources mentioned above).\r\n%\r\n% *Other MathWorks resources:*\r\n%\r\n% If you are interested in delta-sigma modulators (and other mixed-signal\r\n% components), consider downloading the\r\n% <http:\/\/ Mixed-Signal\r\n% Library for Simulink>. Also, take a look at the MathWorks\r\n% <https:\/\/www.mathworks.com\/solutions\/mixed-signal-systems\/index.html Mixed-Signal\r\n% page>, particularly the ADC section.\r\n%\r\n% *Delta-Sigma Toolbox Usage notes:*\r\n%\r\n% * A few C files are provided in the Toolbox that the user needs to\r\n% compile to MEX (e.g., simulateDSM.c). This is generally done as:\r\n%\r\n%   mex simulateDSM.c\r\n%\r\n% But as noted in the comments on File Exchange, this fails\r\n% on some systems. Simply defining the |__STDC__| symbol should resolve the\r\n% issue:\r\n%\r\n%   mex simulateDSM.c \u00e2\u20ac\u201cD__STDC__\r\n%\r\n% Note that you will need a C compiler for this step. Run |mex \u00e2\u20ac\u201csetup| at\r\n% the MATLAB command prompt to setup your C compiler.\r\n%\r\n% * If you plan on using the Delta Sigma Toolbox\r\n% frequently, you should probably add the toolbox folder to your MATLAB\r\n% path:\r\n%\r\n%   addpath('<your_intall_path>\\delsig')\r\n%   savepath\r\n%\r\n% *Suggestions for improvements*\r\n%\r\n% * A great addition to the provided example\/demo files would be the use of\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/run-sections-of-programs.html\r\n% sections>, and perhaps the\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/publish.html publish> feature\r\n% to include a full write-up and description for each file.\r\n% * Providing an Install script would be great (to take care of MATLAB path\r\n% and compiling MEX files).\r\n%\r\n% *Comments*\r\n%\r\n% As always, your thoughts and comments\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=4593#respond here> are greatly\r\n% appreciated.\r\n\r\n##### SOURCE END ##### b26f6b48768c46f4b1666410109bae1d\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/idin\/potw_deltasigma\/sigma_delta_fig1.png\" onError=\"this.style.display ='none';\" \/><\/div><p>\r\nIdin's pick for this week is the Delta Sigma Toolbox by Richard Schreier.Delta-Sigma (or sigma-delta) modulators are commonly found in electronic components such as analog-to-digital and... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2013\/05\/24\/delta-sigma-toolbox\/\">read more >><\/a><\/p>","protected":false},"author":36,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4593"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/36"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=4593"}],"version-history":[{"count":7,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4593\/revisions"}],"predecessor-version":[{"id":9322,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4593\/revisions\/9322"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=4593"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=4593"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=4593"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}