Lab II DCS
Lab II DCS
Lab2
Pulse Code Modulation (PCM)
Objectives
In this lab experiment, the MATLAB software will be used to understand and simulate
the basic concepts and mechanisms of uniform and nonuniform PCM quantizes. The
main objective of this lab study is:
Uniform Quantization
• Function: uniform_pcm
This function, given next, takes as its input a sequence of sampled values (m_samp)
and the number of desired quantization levels (L) and finds the quantized sequence
(m_quan), the encoded sequence (code), and the resulting SQNR (sqnr) in dB. It is
used in uniform quantization and it is also used with other functions in nonuniform
quantization.
Copy and paste this MATLAB function into an m-file and save it as uniform_pcm.m
function [sqnr,m_quan,code]=uniform_pcm(m_samp,L)
global q
%UNIFORM_PCM uniform PCM encoding of a sequence
% [sqnr,m_quan,code]= uniform_pcm(m_samp,L)
% m_samp = input sampled sequence.
% L = number of quantization levels (even).
% sqnr = output SQNR (in dB). %
% idx_quan = index of quantized output.
% m_quan = quantized output before encoding.
% code = the encoded output.
m_max = max(abs(m_samp)); % Find the maximum value of m_samp.
m_quan = m_samp/m_max; % Normalizing m_samp.
idx_quan = m_quan; % Quantization index.
delta = 2/L; % Quantization step.
q = delta.*[0:L-1]; % Define quantization regions.
q = q-((L-1)/2)*delta; % Centralize all quantization levels
% around the x-axis.
for i=1:L
m_quan(find((q(i)-delta/2 <= m_quan) & (m_quan <= q(i)+delta/2)))=...
Master (TSE & ETC)
Case study I:
This example is just an illustrative with low sampling frequency. It is used to allow you
to investigate easily on the resulting outputs. Two figures will be generated; the first
one shows the original input signal and its samples whereas the second shows the
normalized signal with quantized values. In addition, the SQRN and the encoded
quantized samples (code-words) are returned. Remember that this mid-rise uniform
quantization where the number of quantization levels has to be even (e.g. 8 as in this
example).
Copy and paste this MATLAB script into an m-file and save it as uniform_ex1.m
% MATLAB script for Illustrative Example uniform_ex1.m
clc;
clear;
close all
% echo on
global q
t = [0:pi/100:2*pi];
m = 10 * sin(t);
t_samp = [0:pi/4 :2*pi];
m_samp = 10 * sin(t_samp)
figure(1)
L=8;
[sqnr,m_quan,code]=uniform_pcm(m_samp,L)
figure(2)
plot (t,m/max(m),'-b','linewidth', 2)
hold on
stem (t_samp,m_samp/max(m), '--ro','linewidth',2)
hold on
for i=1:L
plot (t,q(i)* ones(1,length(t)),'--g');
hold on
end
legend('normalized original signal','normalized sampled signal');
axis([0 2*pi -1.5 1.5])
echo off
Questions:
1- Write down the samples of the signal, their quantized values, and their code-
words.
2- Show the waveforms of the second figure generated on a full page. Define the
quantization regions, indicate the quantization levels, indicate the amplitudes of
Master (TSE & ETC)
the quantized samples, and show how quantized samples have been successfully
mapped to the corresponding quantization levels.
3- On your sketch above, show the assigned cod-words to each quantization level
and show that the code words obtained are correct.
Copy and paste this Matlab script into an m-file and save it as uniform_ex2.m
Questions:
1- Determine the sampling frequency used in this example.
2- Record the SQRN obtained in the two cases where the number of quantization
levels, L is 8 and 16. Compare the values obtained. Justify your answer.
3- View the Matlab figure generated in full screen and observe the nature of the
two quantization signals. Relate your observation to the SQRN values obtained
above.
This example generates a sequence of length 500 of zero mean, unit variance Gaussian
random variables. It calls the uniform_pcm function to evaluate the SQRN with 64
quantization levels. In addition, it displays the first 5 samples, their corresponding
quantized values, and the corresponding code-words.
Copy and paste this Matlab script into an m-file and save it as uniform_ex3.m
% MATLAB script for Illustrative Example uniform_ex3.m
Clc;
Clear;
Close all
M_samp=rand(1,500);
L=64;
[sqnr,m_quan,code]=uniform_pcm(m_samp,L) ;
Pause % Press a key to see the SQRN.
Sqrn
Pause % Press a key to see the first five input values.
M_samp