0% found this document useful (0 votes)
52 views

Lab II DCS

This document describes uniform pulse code modulation (PCM) using MATLAB. It discusses quantizing a sampled signal using uniform quantization levels. Three case studies are presented: 1) Quantizing a sinusoidal signal with 8 levels, 2) Comparing quantizing a sinusoid with 8 and 16 levels, and 3) Quantizing Gaussian random variables with 64 levels. Key outputs include quantized signal values, codewords, and signal-to-quantization noise ratio (SQNR).
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Lab II DCS

This document describes uniform pulse code modulation (PCM) using MATLAB. It discusses quantizing a sampled signal using uniform quantization levels. Three case studies are presented: 1) Quantizing a sinusoidal signal with 8 levels, 2) Comparing quantizing a sinusoid with 8 and 16 levels, and 3) Quantizing Gaussian random variables with 64 levels. Key outputs include quantized signal values, codewords, and signal-to-quantization noise ratio (SQNR).
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Master (TSE & ETC)

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:

- To study the quantization process of PCM schemes 2


- To synthesize the coding process of PCM schemes
- To compare and analyze uniform and non-uniform quantization schemes

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)

q(i).*ones(1,length(find((q(i)-delta/2 <= m_quan) & ...


(m_quan <= q(i)+delta/2))));
idx_quan(find(m_quan==q(i)))=(i-
1).*ones(1,length(find(m_quan==q(i))));
end
m_quan;
idx_quan;
m_quan = m_quan * m_max; % Release normalization for quantized values.
R =ceil(log2(L)); % Define no. of bits per codeword.
code = de2bi(idx_quan', R, 'left-msb'); % Generate codewords.
sqnr = 20 * log10(norm(m_samp)/norm(m_samp - m_quan)); % Estimate SQNR.

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)

plot (t,m, '-b','linewidth', 2)


hold on
stem (t_samp,m_samp, '--ro','linewidth', 2)
hold on

legend('original signal','sampled signal');


axis([0 2*pi -15 15])

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.

Case study II:


This example generates a sinusoidal signal with amplitude =1. Using uniform quantization,
the samples sequence is quantized using 8 and 16 quantization levels. Its plots the original
signal and the quantized signal on the same axes.

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.

Case study III:


Master (TSE & ETC)

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

You might also like