0% found this document useful (0 votes)
77 views16 pages

Lab 03 & 04

This laboratory session covered analog to digital conversion through quantization and coding. Key concepts covered include: 1. Quantization is the process of converting a continuous range of values into a finite number of discrete values. This allows analog signals to be stored digitally. 2. Quantization was demonstrated by plotting original, quantized, and error signals for different input waveforms. The error signal takes on characteristics of the input waveform. 3. Time shifting, reversal, and scaling operations on signals were demonstrated by plotting various manipulated versions of example signals and explaining the underlying operations.

Uploaded by

Marwa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views16 pages

Lab 03 & 04

This laboratory session covered analog to digital conversion through quantization and coding. Key concepts covered include: 1. Quantization is the process of converting a continuous range of values into a finite number of discrete values. This allows analog signals to be stored digitally. 2. Quantization was demonstrated by plotting original, quantized, and error signals for different input waveforms. The error signal takes on characteristics of the input waveform. 3. Time shifting, reversal, and scaling operations on signals were demonstrated by plotting various manipulated versions of example signals and explaining the underlying operations.

Uploaded by

Marwa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Laboratory Session No.

03

Objective:
An Introduction to Analog to Digital Conversion (Quantization and Coding).

Post Lab Exercises:


Question 1:
What do you mean by the term quantization? Discuss it briefly.
Answer:
Quantization is the process of converting a continuous range of values into a finite range of
discrete values. Analog signal has continuous time which is discretized through sampling.
After this step a DTCV (Discrete Time Continuous Value) signal is converted into a DTDV
(Discrete Time Discrete Value) signal by Quantization.
Storing an analog or CTCV signal on computer needs infinite number of memory locations with
each memory location should have an infinite length/infinite word size.
If we do not quantize the signal then the amplitude can take values form 0 to infinity.Suppose we
want to store such data and we also use binary digits to represent these signals , then we would
require a large set of numbers,and memory space to store them. that is why we quantize the
amplitude by making finite levels and then approximating the amplitude in these levels. if we
increase the levels the approximation becomes closer to the real signal but this has an effect on
the memory also .

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');

b=3; % Number of bits.


N=120; % Number of samples in final signal.
n=0:(N-1); %Index

% Choose the input type.


choice = questdlg('Choose input','Input',...
'Sine','Sawtooth','Random','Random');

fprintf('Bits = %g, levels = %g, signal = %s.\n', b, 2^b, choice);

% Create the input data sequence.


switch choice
case 'Sine'
x=sin(2*pi*n/N);
case 'Sawtooth'
x=sawtooth(2*pi*n/N);
case 'Random'
x=randn(1,N); % Random data
x=x/max(abs(x)); % Scale to +/- 1
end

% Signal is restricted to between -1 and +1.


x(x>=+1)=(1-eps); % Make signal from -1 to just less than 1.
x(x<-1)=-1;

% Quantize a signal to "b" bits.


xq=floor((x+1)*2^(b-1)); % Signal is one of 2^n int values (0 to 2^n-1)
xq=xq/(2^(b-1)); % Signal is from 0 to 2 (quantized)
xq=xq-(2^(b)-1)/2^(b); % Shift signal down (rounding)

xe=x-xq; % Quantization error

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

FIGURE 2:WHEN THE INPUT IS SAWTOOTH WAVE


FIGURE 3:WHEN THE INPUT IS RANDOM WAVE

DISCUSSION ON OUTPUT 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

Effective number of bits (ENOB) is a measure of the dynamic range of an analog-to-digital


converter (ADC), digital-to-analog converter, or their associated circuitry. The resolution of an
ADC is specified by the number of bits used to represent the analog value. Ideally, a 12-bit ADC
will have an effective number of bits of almost 12. However, real signals have noise, and real
circuits are imperfect and introduce additional noise and distortion. Those imperfections reduce
the number of bits of accuracy in the ADC. The ENOB describes the effective resolution of the
system in bits. An ADC may have 12-bit resolution, but the effective number of bits when used
in a system may be 9.5.
Laboratory Session No. 04

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 ]

Using Matlab plot the following signals.

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) :

FIGURE 1:Graph Of x(n)


x(n-3):
x(n-3)=[0 0 0 1 1 2 3 -1 -1 2 5 6 ] ; Time shifting(Delay)

FIGURE 2:Graph Of x(n-3)


x(n+1):
x(n+1)=[ 1 1 2 3 -1 -1 2 5 6 ] ; Time shifting(Advance)

FIGURE 3:Graph Of x(n+1)


x(-n)
x(-n)=[6 5 2 -1 -1 3 2 1 1 ]; Flipping/Folding

FIGURE 4:Graph Of x(-n)

x(2n)
x(2n)=[1 2 -1 2 6 ] ; Time scaling(Down sampling)

FIGURE 5:Graph Of x(2n)


x(n/3)
x(n/3)=[1 0 0 1 0 0 2 0 0 3 0 0 -1 0 0 -1 0 0 2 0 0 5 0 0 6 0 0 ]; Time scaling(Up sampling)

FIGURE 6:Graph Of x(n/3)

x(-n+1)
x(-n+1)=[6 5 2 -1 -1 3 2 1 1]; Time Shifting(Advance) and Flipping

FIGURE 7:Graph Of x(-n+1)


x(-n-1)
x(-n-1)=[6 5 2 -1 -1 3 2 1 1 0]; Time Shifting(Delay) and Flipping

FIGURE 8:Graph Of x(-n-1)

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]

using Matlab plot the following signals.

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.

(Attach codes at the end of this lab)

Answer:
x(n) :

FIGURE 9:Graph Of x(n)

x(n+2) :
x(n+2)=[-2 2 1 -1 3 2 2 -3 -1 5 0 1] ; Time shifting(Advance)

FIGURE 10:Graph Of x(n+2)


x(-n+2) :
x(-n+2)=[1 0 5 -1 -3 2 2 3 -1 1 2 -2] ; Flipping and Time shifting(Advance)

FIGURE 11:Graph Of x(-n+2)

x(2n) :
x(2n)=[-2 1 3 2 -1 0] ; Time scaling(Down sampling)

FIGURE 12:Graph Of x(2n)


x(2n+3) :
x(2n+3)=[2 -1 2 -3 5 1] ; Time scaling(Down sampling) and Time shifting(Advance)

FIGURE 13:Graph Of x(2n+3)

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

for c = 1:round(length(n_s)) % selecting positive index samples

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)');

You might also like