Lab 03 & 04
Lab 03 & 04
03
Objective:
An Introduction to Analog to Digital Conversion (Quantization and Coding).
Question 2:
Execute the quantization code , understand it , plot and comment on the output plot?
Answer:
QUANTIZATION CODE
% This script creates a signal, and then quantizes it to a specified number
% of bits. It then calculates the quantization error.
% see if you run the script.
fprintf('\Lab # 03,Quantization\n');
stem(x,'b');
hold on;
stem(xq,'r');
hold on;
stem(xe,'g');
legend('exact','quantized','error','Location','Southeast')
title(sprintf('Signal, Quantized signal and Error for %g bits, %g
quantization levels',b,2^b));
hold off
FIGURE 1:WHEN THE INPUT IS SINE WAVE
The plot obtained shows three waves in red,blue and green.The blue one is our analog
wave,the red one is its quantized form and 8 quantization levels can be seen clearly.and
the geen wave represents the quantization error between the original analog and the
quantized wave.
Looking at the above results,we can deduce that the error signal for a sinusoidal wave is a
mixture of sawtooth wave and sine wave.We obtained sine wave at the peak of
Sinusoidal wave,while the rest of the part contributes to sawtooth wave.
Likewise,the error wave of a straight line makes a sawtooth wave which is smooth.
While the error wave of a random wave generated by matlab has an error wave which is
random and no exact pattern can be observed.
One factor which is common in all three error waves is the amplitude which is half of the
sampling step and it can be seen through all the corresponding output waves.
So the maximum value of error can be 50% of the sampling step in the original analog.
Question 3:
Discuss the specifications of Arduino Uno ADC like number of bits, number of quantization
levels, etc. Also, calculate the default Arduino Uno ADC resolution.
Link: https://store.arduino.cc/usa/arduino-uno-rev3
Answer:
Arduino is an open-source platform used for building electronics projects. Arduino consists of
both a physical programmable circuit board (often referred to as a microcontroller) and a piece
of software, or IDE (Integrated Development Environment) that runs on your computer, used to
write and upload computer code to the physical board. Arduino Uno is an analog to digital
converter. It has 14 digital input/output pins & 6 analog input pins.
Arduino Uno has an 8-bit processor.So the quantization levels are:
Bits=b=8
Quantization levels=l=2b=28=256 unique combinations
Operating Voltage=5V
Xmax−Xmin 5−0 5
Default Resolution=∆= = 256−1 = 255 =0.019 volts/levels
𝑙evels−1
Question 4:
A 12-bit ADC has input values in the range of 0 – 1 V. Calculate the resolution of ADC.
Answer:
Bits=b=12
Quantization levels=l=2b=212=4096 unique combinations
Maximum Voltage=1V
Xmax−Xmin 1−0 1
Resolution=∆= = 4096−1 = 4095 =0.244 m volts/levels
𝑙evels−1
Question 5:
What do you mean by the term SQNR and ENOB? Discuss it briefly.
Answer
SQNR
SQNR short for signal to quantization noise ratio, is a measure of the quality of the quantization,
or digital conversion of an analog signal. The SNQR reflects the relationship between the
maximum nominal signal strength and the quantization error(also known as quantization noise)
introduced in the analog to digital conversion.This can be seen through figure 1.
FIGURE 1: NOISE SIGNAL DURING CONVERSION
ENOB
Objective:
An Introduction to Time shifting, Reversal and scaling.
Post Lab Exercises:
Question 1:
Let x(n)=[1 1 2 3 -1 -1 2 5 6 ]
a) x(n-3)
b) x(n+1)
c) x(-n)
d) x(2n)
e) x(n/3)
f) x(-n+1)
g) x(-n-1)
also show every step and mention operations i.e. time shifting, time scaling etc.
Answer:
x(n) :
x(2n)
x(2n)=[1 2 -1 2 6 ] ; Time scaling(Down sampling)
x(-n+1)
x(-n+1)=[6 5 2 -1 -1 3 2 1 1]; Time Shifting(Advance) and Flipping
CODE
x=[1 1 2 3 -1 -1 2 5 6 ];
n=0:1:8;
figure
stem(n,x); %plotting original signal,x(n)
title('x(n)');
xlabel('n');
ylabel('Amplitude');
%ylim(-2,2);
figure
stem(n+3,x); %x(n-3)
title('x(n-3)');
xlabel('n');
ylabel('Amplitude');
figure
stem(n-1,x); %x(n+1)
title('x(n+1)');
xlabel('n');
ylabel('Amplitude');
n1=0:1:4;
y1=downsample(x,2);
figure
stem(n1,y1);
title('x(2n)');
xlabel('n');
ylabel('Amplitude');
y2=upsample(x,3);
n2=0:1:26;
figure
stem(n2,y2);
title('x(n/3)');
xlabel('n');
ylabel('Amplitude');
y3=flip(x);
nf=(0:length(x)-1)-(length(x)-1);
figure
stem(nf,y3); %folding
title('x(-n)');
xlabel('n');
ylabel('Amplitude');
figure
stem(nf+1,y3); %x(-n+1)
title('x(-n+1)');
xlabel('n');
ylabel('Amplitude');
figure
stem(nf-1,y3); %x(-n-1)
title('x(-n-1)');
xlabel('n');
ylabel('Amplitude');
Question 2:
let x(n)= [-2 2 1 -1 3 2 +2 -3 -1 5 0 1]
a) x(n+2)
b) x(-n+2)
c) x(2n)
d) x(2n+3)
also show every step and mention operations i.e. time shifting, time scaling etc.
Answer:
x(n) :
x(n+2) :
x(n+2)=[-2 2 1 -1 3 2 2 -3 -1 5 0 1] ; Time shifting(Advance)
x(2n) :
x(2n)=[-2 1 3 2 -1 0] ; Time scaling(Down sampling)
CODE
x= [-2 2 1 -1 3 2 2 -3 -1 5 0 1]; % input sequence
org_x = 5;
nx = [0 : length(x)-1]- org_x + 1;
figure
stem(nx,x);
title('x(n)');
xlabel('n');
ylabel('amplitide');
n1=-4:2:6;
y1=downsample(x,2);
figure
stem(n1,y1);
title('x(2n)');
xlabel('n');
ylabel('Amplitude');
k=3;
org_n_s=org_x+k;
n_s=nx-k;
subplot(2,1,1);
stem(nx,x);
subplot(2,1,2);
stem(n_s,x);
title('x(n+3)');
%%
b=org_n_s
a=1;
y=[];
t_s_f=2; % time scaling factor
for c = 1:round(length(n_s)) % selecting negative index samples
b=b-t_s_f;
if b>=1
y(a)=x(b);
a=a+1;
else
end
end
ny_s=-(length(y))
y=flip(y); % flipping y to make it according to index
b=org_n_s
if b<=length(x)
y(a)=x(b);
a=a+1;
b=b+t_s_f;
else
end
end
ny_e=length(y)+ny_s-1;
figure
subplot(3,1,1);
stem(nx,x);
subplot(3,1,2);
stem(n_s,x);
title('x(n+3)');
subplot(3,1,3);
ny=[ny_s:ny_e];
stem(ny,y);
title('x(2n+3)');