title: Calculate Quantization error in MATLAB
body: <p>iI was given this solution to a problem in my course material.</p>
  
  <p><strong>Problem:</strong> </p>
  
  <p>a signal <code>x(t)</code> sampled at <code>10 sample/sec</code>. consider the first <code>10 samples</code> of <code>x(t)</code></p>
  
  <pre><code>x(t) = 0.3 cos(2*pi*t);
  </code></pre>
  
  <p>using a 8-bit quantiser find the quantisation error.</p>
  
  <p><strong>solution:</strong></p>
  
  <pre><code>(256 quantisation levels)
  t=1:10;
  x=(0.3)*cos(2*pi*(t-1)/10);
  mx=max(abs(x));
  q256=mx*(1/128)*floor(128*(x/mx));
  stem(q256)
  e256=(1/10)*sum(abs(x-q256))
  Error: e256 = 9.3750e-04
  </code></pre>
  
  <p>There was no explanation on this, can you explain how this was calculated in detail?</p>