{"id":5521,"date":"2023-02-26T19:22:32","date_gmt":"2023-02-26T19:22:32","guid":{"rendered":"https:\/\/www.goodacademic.com\/blog\/questions\/use-matlab-for-answering-the-first-two-questions-attach-and-identify-the-code-used-for-each-part\/"},"modified":"2023-02-26T19:22:32","modified_gmt":"2023-02-26T19:22:32","slug":"use-matlab-for-answering-the-first-two-questions-attach-and-identify-the-code-used-for-each-part","status":"publish","type":"questions","link":"https:\/\/www.goodacademic.com\/blog\/questions\/use-matlab-for-answering-the-first-two-questions-attach-and-identify-the-code-used-for-each-part\/","title":{"rendered":"Use MATLAB for answering the first two questions Attach and identify the code used for each part"},"content":{"rendered":"<div class=\"col-sm-12 messageContent\">\n <b>Learning Goal: <\/b>I&#8217;m working on a electrical engineering question and need the explanation and answer to help me learn.<\/p>\n<p>function X = quantize( s, bit, rmode, lmode )<\/p>\n<p>%QUANTIZE simulated fixed-point arithmetic<\/p>\n<p>%&#8212;&#8212;-<\/p>\n<p>% Usage: X = quantize( S, BIT, RMODE, LMODE )<\/p>\n<p>%<\/p>\n<p>% returns the input signal S reduced to a word-length<\/p>\n<p>% of BIT bits and limited to the range [-1,1). The type of<\/p>\n<p>% word-length reduction and limitation may be chosen with<\/p>\n<p>% RMODE: &#8217;round&#8217; rounding to nearest level<\/p>\n<p>% &#8216;trunc&#8217; 2&#8217;s complement truncation<\/p>\n<p>% &#8216;magn&#8217; magnitude truncation<\/p>\n<p>% LMODE: &#8216;sat&#8217; saturation limiter<\/p>\n<p>% &#8216;overfl&#8217; 2&#8217;s complement overflow<\/p>\n<p>% &#8216;triang&#8217; triangle limiter<\/p>\n<p>% &#8216;none&#8217; no limiter<\/p>\n<p>if nargin ~= 4<\/p>\n<p>vq = quantize(v,3,round,sat);<\/p>\n<p>error(&#8216;usage: quantize( S, BIT, RMODE, LMODE ).&#8217;);<\/p>\n<p>end<\/p>\n<p>if bit &lt;= 0 || abs(rem(bit,1)) &gt; eps<\/p>\n<p>error(&#8216;wordlength must be positive integer.&#8217;);<\/p>\n<p>end<\/p>\n<p>Plus1 = 2^(bit-1);<\/p>\n<p>X = s * Plus1;<\/p>\n<p>if strcmp(rmode, &#8217;round&#8217;); X = round(X);<\/p>\n<p>elseif strcmp(rmode, &#8216;trunc&#8217;); X = floor(X);<\/p>\n<p>elseif strcmp(rmode, &#8216;ceil&#8217;); X = ceil(X);<\/p>\n<p>elseif strcmp(rmode, &#8216;magn&#8217;); X = fix(X);<\/p>\n<p>else error(&#8216;unknown wordlength reduction spec.&#8217;);<\/p>\n<p>end<\/p>\n<p>if strcmp(lmode, &#8216;sat&#8217;)<\/p>\n<p>X = min(Plus1 &#8211; 1,X);<\/p>\n<p>X = max(-Plus1,X);<\/p>\n<p>elseif strcmp(lmode, &#8216;overfl&#8217;)<\/p>\n<p>X = X + Plus1 * ( 1 &#8211; 2*floor((min(min(X),0))\/2\/Plus1) );<\/p>\n<p>X = rem(X,2*Plus1) &#8211; Plus1;<\/p>\n<p>elseif strcmp(lmode, &#8216;triang&#8217;)<\/p>\n<p>X = X + Plus1 * ( 1 &#8211; 2*floor((min(min(X),0))\/2\/Plus1) );<\/p>\n<p>X = rem(X,4*Plus1) &#8211; Plus1;<\/p>\n<p>f = find(X &gt; Plus1);<\/p>\n<p>X(f) = 2*Plus1 &#8211; X(f);<\/p>\n<p>f = find(X == Plus1);<\/p>\n<p>X(f) = X(f) &#8211; 1;<\/p>\n<p>elseif strcmp(lmode, &#8216;none&#8217;) % limiter switched off<\/p>\n<p>else error(&#8216;unknown limiter spec.&#8217;);<\/p>\n<p>end<\/p>\n<p>X = X \/ Plus1;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Learning Goal: I&#8217;m working on a electrical engineering question and need the explanation and answer to help me learn. function X = quantize( s, bit, rmode, lmode ) %QUANTIZE simulated fixed-point arithmetic %&#8212;&#8212;- % Usage: X = quantize( S, BIT, RMODE, LMODE ) % % returns the input signal S reduced to a word-length % [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":[],"disciplines":[704],"paper_types":[],"tagged":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/questions\/5521"}],"collection":[{"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/questions"}],"about":[{"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/types\/questions"}],"author":[{"embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/comments?post=5521"}],"version-history":[{"count":0,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/questions\/5521\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/media?parent=5521"}],"wp:term":[{"taxonomy":"disciplines","embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/disciplines?post=5521"},{"taxonomy":"paper_types","embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/paper_types?post=5521"},{"taxonomy":"tagged","embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/tagged?post=5521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}