# Quantization error in sampling

Consider the analog signal, $$x(t) = 2\cos(3000\pi t)+3\sin(4000\pi t)+7\cos(6000\pi t)$$ If the sampling rate is 8000 samples per second and quantized at 8 bits, find:

1. Discrete values at any two points
2. Quantization error at those points

I have been trying to solve this with no success so far. How can I solve this?
So far what I have done is convert $x(t)$ which is continuous time signal to $x[n]$ which is discrete time signal.

$$x[n]= 2\cos\left(\frac{3\pi}{8}n\right)+3\sin\left(\frac{3\pi} {2}n\right)+7\cos\left(\frac{3\pi}{4} n\right)$$ where $n$ is integer. By any two points what I mean is for any two values of $n$. For example, suppose I calculate $x[n]$ for $n=1$ and $n=2$. How do I find quantization error at those points?

• Can I please ask you to edit the question with the steps you have been taking so far to tackle this problem? Or at least, the general idea of how do you think you should go about answering these questions? For the quantisation part of the question, what is the wordlength?
– A_A
Sep 8 '16 at 8:09
• Can you also make it more clear what exactly you mean by "any two points"
– msm
Sep 8 '16 at 9:00
• Did you make a choice regarding the quantization scheme? There can be slight variations Sep 8 '16 at 9:20
• Is the sampling rate 8000 or 80000? You say it's 80k, but in the last equation it looks like it's 8k. Regarding your question on quantization error: the first step is to quantize $x(n)$.
– MBaz
Sep 8 '16 at 11:19
• You need to define the quantization range for your 8 bits. 8 bits gives you 256 levels - usually this is divided as -127 to 128, but what analog values do these correspond to is the range -20 to 20 or -1000 to 1000 or something different. Sep 8 '16 at 11:58

From your question it is unclear what is the dynamic range exactly, or is it needed to normalize the signal or not? Anyway, I assumed it to be normalized (since somehow this happens in ADCs). To quantize the normalized signal, you can use the following equation : $$x_q[n]=\frac{\bigg\lfloor\left(\frac{x[n]}{\textrm{Dynamic Range}}\right)\cdot2^\textrm{Number of Bits}\bigg\rfloor}{2^{\textrm{Number of Bits}-1}}$$ where, $$\textrm{Dynamic Range}$$ here is $$2$$, $$\textrm{Number of Bits}$$ is $$8$$.

Quantization error in each sample would simply be the difference of the original signal and the quantized version of it.

$$Q_e=x[n]-x_q[n]$$

I can't provide the complete solution, however the following code gives you the idea of application of above discussions.

fs=8000;
Ts=1/fs;
f1=1500;
f2=2000;
f3=3000;
t=(0:512)*Ts;
x=2*cos(2*pi*f1*t+13124)+3*sin(2*pi*f2*t+pi/8)+7*cos(2*pi*f3*t);
x=x./max(abs(x)); %Normalization

Range=2; % Dynamic Range ; from -1 to 1 I assume
Q=8; %Number of Bits

Quantized_Signal=floor(x./Range*2^Q)./2^(Q-1);