iI was given this solution to a problem in my course material.
Problem:
a signal x(t) sampled at 10 sample/sec. consider the first 10 samples of x(t)
x(t) = 0.3 cos(2*pi*t);
using a 8-bit quantiser find the quantisation error.
solution:
(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
There was no explanation on this, can you explain how this was calculated in detail?
For the first two code lines I prefer,
where
Fsis sampling frequency,Lnumber of samples andtshows the time.Note that
xis sinusoidal with frequency ofFx = 1 Hzor we can say that it's periodic withTx = 1 sec.For
8-bitquantization we have256levels. SinceL / Fs = [10 sample] / [10 sample/sec] = 1 secis equal toTx(a whole period ofx) we can work with positive samples.mxis defined because in order to usefloorwe need to scale thex.mxshows the maximum value forxsox / mxwill take values over[-1 1]and128*x/mxover[-128 128]will cover all256levels.So we will quantize it with
floorand scale it back (mx*1/128).e256simply shows the mean error over 10 samples.Note that if
L / Fs < Txthen this quantization won't be the optimum one.Have in mind
The answer that you are given has some problems!
suppose
x = [-1 -.2 0 .7 1];and we want to quantize it with2bits.Will give
q4 = [-1 -0.5 0 0.5 1]which has5levels (instead of2^2 = 4).It might not be a big problem, you can delete the level
x=1and haveq4 = [-1 -0.5 0 0.5 0.5], still the code needs some improvements and of course the error will increase.A simple solution is to add
after definition of
mxso the maximum values ofxwill be quantized in one level lower.The error will increase to
0.0012.