close all; figure
t = 0:0.0001:2;
% generate some nice looking signal then scale to +/- 1
x = 2*cos(2*pi*t)+1.5*cos(4*pi*t+2)+1*cos(5*pi*t)+0.5*cos(10*pi*t);
x = 2*(x - min(x))/(max(x)-min(x)) - 1;
% quantization
n = 2; % bits
xq = floor((1-1e-12)*(x+1).*2.^(n-1));
xq = xq / (2^(n-1));
xq = xq - (2^n - 1) / 2^n;
% error signal
qerr = x - xq;
% plot
subplot(211); plot(t,x,'b',t,xq,'r'); title('Original and Quantized Signal');
subplot(212); plot(t,qerr,'b'); title('Quantization Error');
Licensing
Public domainPublic domainfalsefalse
I, the copyright holder of this work, release this work into the public domain. This applies worldwide. In some countries this may not be legally possible; if so: I grant anyone the right to use this work for any purpose, without any conditions, unless such conditions are required by law.
{{Information |Description=Plot of a quantized signal and it's error |Source=self-made |Date=23 February 2008 |Author= Atropos235 |Permission= |other_versions= }} ==Source Code== <pre><nowiki> close all; figure t = 0:0.0001:2; % gen
File usage
No pages on the English Wikipedia use this file (pages on other projects are not listed).