Spring 2024 DSP Lab 8 Version 1.
Namal University, Mianwali
Department of Electrical Engineering
EE 345 (L) – Digital Signal Processing (Lab)
Lab – 8
Quantization of Discrete time Signals using MATLAB
Student Name Student ID
Muhammad Ali NIM-BSEE-2021-34
Instructor: Zulaikha Kiran
Lab Engineer: Faizan Ahmad
Spring 2024 DSP Lab 8 Version 1.3
Introduction
The purpose of this lab is to enable the students to study the effect of quantization on signals
using MATLAB.
Course Learning Outcomes
CLO1: Develop algorithms to perform signal processing techniques on digital signals using
MATLAB and DSP Kit DSK6713
CLO3: Deliver a report/lab notes/presentation/viva, effectively communicating the design and
analysis of the given problem
Equipment
Software
o MATLAB
Instructions
1. This is an individual lab. You will perform the tasks individually and submit a report.
2. Some of these tasks are for practice purposes only while others (marked as ‗Exercise‘)
have to be answered in the report.
3. When asked to display an image/ graph in the exercise, either save it as jpeg or take a
screenshot, in order to insert it in the report.
4. The report should be submitted on the given template, including:
a. Code (copy and pasted, NOT a screenshot)
b. Output values (from command window, can be a screenshot)
c. Output figure/graph (as instructed in 3)
d. Explanation where required
5. The report should be properly formatted, with easy to read code and easy to see figures.
6. Plagiarism or any hint thereof will be dealt with strictly. Any incident where plagiarism is
caught, both (or all) students involved will be given zero marks, regardless of who copied
whom. Multiple such incidents will result in disciplinary action being taken.
Spring 2024 DSP Lab 8 Version 1.3
Background:
Everything stored on a computer is discrete time discrete valued signal. Because computer has
finite number of registers and each register is a finite length register. We take too many samples
to give the ‗effect‘ of continuous time signals. But actually they are discrete time. We also take
very fine resolution of amplitude axis to give the effect of continuous valued signal but due to
finite word length of the computer register, the stored variables are already quantized. This lab
aims to explain the quantization effects in a computer. Regardless of the medium (audio or image),
the digitization of real world analog signal usually involves two stages: sampling, i.e. the
measurement of signal at discretely spaced time intervals, and quantization, i.e. the transformation
of the measurements (amplitudes) into finite-precision numbers (allowed discrete levels), such
that they can be represented in computer memory. Quantization is a matter of representing the
amplitude of individual samples as integers expressed in binary. The fact that integers are used
forces the samples to be measured in a finite number of bits (discrete levels). The range of the
integers possible is determined by the bit depth, the number of bits used per sample. The bit depth
limits the precision with which each sample can be represented.
Within digital hardware, numbers are represented by binary digits known as bits—in fact, the term
bit originated from the words Binary digit. A single bit can be in only one of two possible states:
either a one or a zero. When samples are taken, the amplitude at that moment in time must be
converted to integers in binary representation. The number of bits used to represent each sample,
called the bit depth (bits/sample) or sample size, determines the precision with which the sample
amplitudes can be represented. Each bit in a binary number holds either a 1 or a 0. In digital sound,
bit depth affects how much you have to round off the amplitude of the wave when it is sampled
at various points in time.
The number of different values that can be represented with b-bit is 2bb.The largest decimal
number that can be represented with a b-bit binary number is 2bb−1. For example, the decimal
values that can be represented with an 8-bit binary number range from 0 to 255, so there are 256
different values (levels of ADC). A bit depth of 8 allows 28=256 different discrete levels at which
samples can be approximated or recorded. Eight bits together constitute one byte. A bit depth of
16 allows 216= 65,536 discrete levels, which in turn provides much higher precision than a bit
depth of 8.
Simulink
―Simulink is a block diagram environment used to design systems with multi-domain models,
simulate before moving to hardware, and deploy without writing code‖ (Copied from
https://www.mathworks.com/products/simulink.html )
Scope settings in Simulink
Go to Matlab Home > Simulink to open Simulink window.
In the Simulink window, open View > Library Browser
Search for scope in the Library Browser. Select and add it to your model.
Spring 2024 DSP Lab 8 Version 1.3
Double click on the scope to open its display window. The default window looks like the one
shown below, with one display window (for the single input) and black background. You may
increase the number of inputs to the scope by increasing the number of input ports.
The default colour scheme for plots uses a lot of ink when printed. So change it to white
background and dark curves by going to view > Style
Spring 2024 DSP Lab 8 Version 1.3
**You must use white background and black plot lines while using the scope.
Then open view > Layout to plot all inputs separately.
View > Legend will add the legend to the plots.
Spring 2024 DSP Lab 8 Version 1.3
Exercise 1
Implement the following system on MATLAB simulink
Ensure your signal generator is set to produce a sine wave with an amplitude of 1
and a frequency of 1 rad/sec.
Set the sampling time in your Zero Order Hold block to be 0.1sec.
The encoder applies uniform quantization to the sampled signal to give an output
between 0 and 2n-1 where n is the number of bits.
Ensure that the number of output bits in the encoder and the number of input bits in
the decoder are the same (set to 8 initially for both).
Run the simulation.
Analyse the effect of increasing/ decreasing the sampling frequency (in the zero order hold
block) on the signals.
Analyse the effect of increasing/ decreasing the number of bits in the Encoder and Decoder
blocks.
What is the purpose of the Sum block?
Which blocks are affecting the quantization levels?
Simulink circuit:
Spring 2024 DSP Lab 8 Version 1.3
Results:
Sampling time =0.1sec and bit=8
Display:
Sampling time =0.5 sec and bit=8
Spring 2024 DSP Lab 8 Version 1.3
Sampling time =0.1 sec and bit=14
Display:
Sampling time =0.01sec and bit=4
Display
What is the purpose of sum block?
Spring 2024 DSP Lab 8 Version 1.3
Which blocks are effecting the quantization:
The observation for task1 and answers of Q1, and Q2:
Spring 2024 DSP Lab 8 Version 1.3
Exercise 2
Generate saw-tooth wave for f=10 rad/sec to observe the effects of quantization? What
happens, if frequency and sampling frequency increases and decreases?
Results:
Signal frequency=10Hz,sampling time=0.1sec
Display
Signal frequency=15Hz,sampling time=0.1sec
Display
Spring 2024 DSP Lab 8 Version 1.3
Signal frequency=10Hz,sampling time=0.5sec
Display
Explanation:
Exercise 3
Consider a continues signal S=a*cos(2*pi*f*t), plot this signal using MATLAB where
a=8, f=1Hz, Ts=0.001, and t=0:Ts:2. Take continues signal as a reference and plot the
following signals?
1. Sampled signal of S
2. Quantization Signal of S
Code:
% Parameters
a = 8; % Amplitude
f = 1; % Frequency in Hz
Ts = 0.001; % Sampling period
t = 0:Ts:2; % Time vector from 0 to 2 seconds with a sampling interval of Ts
% Continuous signal
S = a * cos(2 * pi * f * t);
Spring 2024 DSP Lab 8 Version 1.3
% Plot continuous signal
subplot(3, 1, 1);
plot(t, S);
title('Continuous Signal');
xlabel('Time (s)');
ylabel('Amplitude');
% Plot sampled signal
subplot(3, 1, 2);
stem(t, S);
title('Sampled Signal');
xlabel('Time (s)');
ylabel('Amplitude');
% Quantize the sampled signal
quantized_signal = round(S);
% Plot quantized signal
subplot(3, 1, 3);
plot(t, quantized_signal);
title('Quantized Signal');
xlabel('Time (s)');
ylabel('Amplitude');
% Adjust plot layout
%sgtitle('Sampled and Quantized Signals of S');
%set(gcf, 'Position', [100, 100, 800, 600]);
Result:
Spring 2024 DSP Lab 8 Version 1.3
Explanation:
Conclusion:
Evaluation Rubric
• Method of Evaluation: In-lab marking by instructors, Report submitted by students
• Measured Learning Outcomes:
CLO1: Develop algorithms to perform signal processing techniques on digital signals using MATLAB and DSP Kit DSK6713
CLO3: Deliver a report/lab notes/presentation/viva, effectively communicating the design and analysis of the given problem
Excellent Good Satisfactory 6- Unsatisfactory 3- Poor Marks
10 9-7 4 1 0 Obtained
All tasks completed
Tasks Most tasks completed Some tasks completed Most tasks incomplete or All tasks incomplete
correctly. Correct code
(CLO1) correctly. correctly. incorrect. or incorrect.
with proper comments.
Some Output/Figures/Plots
Output Output correctly shown with Most Output/Figures/Plots displayed with proper labels Most of the required Output/Figures/Plots
(CLO1) all Figures/Plots displayed displayed with proper labels OR Most Output/Figures/Plots not not displayed
as required and properly Output/Figures/Plots
displayed
labelled displayed but without proper
labels
Meaningful answers to all Some correct/ Answers not
Answers questions. Answers show the Meaningful answers to most meaningful answers understandable/ not
(CLO1) understanding of the student. questions. with some irrelevant relevant to Not Written any
ones questions Answer
Report submitted with
Report submitted with Some correct/ meaningful
Report proper conclusions drawn Conclusions not based on
proper grammar and conclusions. Some parts of
(CLO3) with good formatting but results. Bad formatting
punctuation with proper the document not properly
some grammar mistakes OR with no proper Report not submitted
conclusions drawn and good formatted or some grammar
proper grammar but not very grammar/punctuation
formatting mistakes
good formatting
Total