Sunteți pe pagina 1din 38

FACULTY OF ENGINEERING

MULTIMEDIA UNIVERSITY

LAB SHEET

ETM 3136
Digital Communications
Trimester 1 (2010/2011)

DTL1: Pulse Code Modulation (PCM)

Important Notes:

Students MUST read this lab sheet before attending the lab. Oral assessment could be
conducted on-the-spot.

The lab report is to be submitted within two weeks of working days.

Ayman, Chuah, May 2010


1
Experiment DTL1: Pulse Code Modulation (PCM)

OBJECTIVES:

To study the quantization process of PCM schemes

To synthesize the coding process of PCM schemes

To compare and analyze uniform and non-uniform quantization schemes

BASIC CONCEPTS

DEFINITION: Pulse code modulation (PCM) is essentially an analog-to-digital conversion


(ADC) process where the information contained in the instantaneous samples of an analog
signal is represented by digital codewords in a serial bit stream. This can be accomplished by
representing the signal in discrete form in both time and amplitude domain.

A PCM signal is generated at the transmitter by carrying out three basic operations: sampling,
quantizing, and encoding. The pulse code modulation (PCM) process samples an input analog
signal, quantizes the sampled signal, and codes the quantized signal into binary-coded digits.
A functional block diagram of a PCM transmitter is shown in Figure 1.

Figure 1: Block diagram of a PCM transmitter.

2.1 Sampling:

It is the process of obtaining an instantaneous value of the input analog signal amplitude at
regular intervals. The signal m(t) entering the sampler is band-limited to B Hz. Usually there
exists a filter with bandwidth B Hz prior to the sampler to cutoff the out-of-band components.
The sampling rate must be sufficiently large so that the analog signal can be reconstructed
from its samples ms(n) with sufficient accuracy. The input analog signal is sampled at a rate
higher than the Nyquist rate to allow for some guard-band. Thus, the

sampling frequency, fs, can be restricted by

fs ≥ 2B
(1)
The sampling period is Ts second/sample and it is related to the sampling frequency by

fs = 1/ Ts
(2)

2
2.2 Quantization:

It is the process of converting the voltage level of the sampled amplitude to the voltage value
of the nearest standard level, or quantization level. At the end of this stage, the signal mq(n)
will be represented discretely in both time and amplitude. The quantizers can be classified as
uniform quantizers or nonuniform quantizers. In uniform quantization, the quantization
regions are chosen to have equal length where as in nonuniform quantization, regions of
variable length are used. The two techniques are further described as follows:

Uniform Quantization:

Assumed that the range of the input samples is [-mmax, +mmax]. In uniform quantization, all
quantization regions except the first and last ones are of equal length, which is denoted by ,
and the number of quantization levels L is an integer power of 2. From this, the length of

the quantization region is given by


2m
= max

(3)
The quantization levels are chosen to be the
therefore, the quantization error at the n sample L midpoints of the
th

is quantization regions
and given by
Mid-rise Origin point lies in the middle of a
Uniform rising edge.
e(n) = m(t) – mq(n) Quantizer •
(4) Used with odd number of
Table 1: Types of
where t = nTs and e(n) has a quantization levels,
uniform quantizer
•
uniform probability density characteristics
Used with even number of
function on the interval (- quantization levels,
/2, + /2]. •
Two types of uniform Mid-tread Uniform Origin point lies e.g. L = 7 as above.
Quantizer in the middle of
quantizer characteristics are a tread.
shown in Table 1. • e.g. L = 8 as above.
3
Figure 2 shows a midrise uniform quantizer of 8 levels, q1, q2, …, q8. The input analog signal
m(t) is firstly sampled at nTs time intervals to generate the samples signal ms(t) (not shown in
the figure). The samples are then quantized to the nearest quantization level to construct the
quantized signal mq(n). The 6 samples of the signal, from left to right, will be mapped to q2,
q3, q5, q6, q6, q7 because the amplitude of these samples fall into the Reg2, Reg3, Reg5, Reg6,
Reg6, Reg7, respectively.

Figure 2: An example of quantized samples using 8-level midrise uniform quantizer.

Nonuniform Quantization:

As long as the amplitude statistics of the input signal are close to the uniform distribution (all
amplitudes have about equal chances to appear), uniform PCM works fine. However, in
coding of certain signals such as speech, the input signal amplitude distribution is far from
being uniformly distribution. For a speech waveform, in particular, there exists higher
probability of smaller amplitudes and lower probabilities for larger amplitudes. Therefore, it
makes sense to design a quantizer with more quantization levels at lower amplitudes and less
quantization levels at larger amplitudes. The resulting quantizer will be a nonuniform
quantizer having variable spacing between the quantization levels.

In nonuniform quantization, the sampled signal is first passed through a nonlinear element
that compresses the large amplitudes (reduces the dynamic range of the signal) and then
perform a uniform quantization on the output.

Two types of compressors are used in nonuniform quantizers; the µ-law and the A-law
nonlinearities. The input-output relation of the µ-law compressor is defined by
4

log(1 +μ x ) μ
y = f ( x) = sgn ( x )
μ
(5)
where |x| ≤ 1 , and its inverse is

(1 +μ ) −1
x=
y
sgn (y)
(6)

The standard PCM


system in the U.S. and
Canada employs a µ-
law compressor with
µ = 255. This relation
is displayed in Figure
3 with different µ
output
values (µ = no 0.2
compression).

0.8

mu = 0

y=
-0.2

mu = 10
1+ln( A)

y=

-0.4

(7)

f (x) = sgn(x)
1+ln(A | x |)

-0.6

≤| x |≤1.

-0.8

1+ln( A)

A
A

1+ln(A)
and it inverse is
expressed as

| y | (1+ln( A))
,
|
y |<

5
2.3 Encoding:

It is the process of representing a particular quantization level of the analog signal with a
binary codeword. After quantization, the quantized levels are encoded using R bits for each
quantization level. The encoding scheme that is usually employed is natural binary coding
(NBC), meaning that the lowest quantization level is mapped into a sequence of all 0’s and the
highest level is mapped into a level of all 1’s. In Figure 2 above, R = log2(L) = log2(8) = 3 bits
per codeword were used.

PCM SYSTEM PERFORMANCE:

Performance Metrics:

PCM Transmission Bandwidth:

The transmission bandwidth of a serial binary PCM (BPCM) waveform depends on the bit rate
and the waveform pulse shape used to represent the data. The bit rate Rb is given by

Rb = R fs
(9)

Because an input analog signal band-limited to B Hz, requires a minimum fs ≥ 2B samples per
second (Nyquist theorem), we require a total of Rb = 2RB bits per second. Since we can
transmit error-free at most two pieces of information per second per Hz bandwidth (realizable
using Nyquist pulse shape), thus we require a minimum PCM transmission bandwidth of
= 20log q
BPCM = R B

PCM Signal-to-Quantization-Noise Ratio: (


1
0
The signal-to-quantization-ratio (SQNR) in dB )
E(m −m )2
is expressed as follows
norm(m −m )
SQNR dB

σ2
2
σ

E(m2 )

norm(m)

(
= 10log
e
1
m
= 10log q 1
)
6
3.2 Performance Tradeoffs

From equation 10, and for reasonable large values of R, the bandwidth of the serial PCM signal
will be significantly larger than the bandwidth of the original analog signal it represents. Thus,
increasing the number of quantization levels will lead to the negative effect of increasing the
transmission bandwidth. However, this increased number of quantization levels will result in the
positive effect of reducing the quantization error in equation 11 and thus, improving the SQNR.
Therefore, there exists a tradeoff between BCM transmission bandwidth (cost) and the SQNR
(quality).

4. EXPERIMENT SOFTWARE

4.1 Introductory Information

In this lab experiment, the MATLAB software will be used to understand and simulate the basic
concepts and mechanisms of uniform and nonuniform PCM quantizers. MATLAB is an
interactive matrix based system for scientific and engineering numeric computation and
visualization. Its strength lies in the fact that complex numerical problems can be solved easily
and in fraction of the time required with a programming language such as Fortran or C. it is also
powerful in the sense that by using its relatively simple programming capabilities, MATLAB
can be easily extended to create new commands and functions.

Getting familiar with related MATLAB Commands and Functions

Open and start the MATLAB program by double-clicking the MATLAB icon.

In the MATLAB COMMAND WINDOW, learn about the following commands using the
MATLAB help. Explain briefly the functionality of each command and also perform two
arbitrary corresponding examples to enhance your familiarity.

>> help randn

>>
>>

>> help abs

>>
>>

>> help max


>>
>>

7
>> help length

>>
>>

>> help ones

>>
>>

>> help fix

>>
>>

>> help find

>>
>>

>> help norm

>>
>>

>> help echo

>>
>>
>> help pause

>>
>>

>> help sort

>>
>>

>> help global

>>
>>

>> help de2bi

>>
>>

8
SIMULATION OF PCM OPERATIONS USING MATLAB

Setup of PCM MATLAB Functions and Scripts into MATLAB Environment

In this experiment, there are 7 MATLAB scripts; uniform_ex1.m, uniform_ex2.m,


uniform_ex3.m, uniform_ex4.m, uniform_ex5.m, nonuniform_ex4.m, and finally
nonuniform_ex5.m. The first five scripts are based on mid-rise uniform quantization (even
number of quantization levels) whereas the last two examples are based on a µ-law
nonuniform quantization. These 7 MATLAB scripts (examples) use another 5 MATLAB
functions; uniform_pcm.m, mulaw_pcm.m, mulaw.m, invmulaw.m, and signum.m. Figure
4 shows a roadmap that describes the interrelationships between the individual MATLAB
scripts and functions. For instance, when running the nonuniform_ex5.m script, this script
will call the mulaw.m function which will then call the functions unifro_pcm.m, mulaw.m,
and invlulaw.m where the last two functions invokes the signum.m function implicitly.

Figure 4: Roadmap showing the interrelationships between MATLAB scripts and functions.
To setup the experiment, follow the following steps:

Go to MATLAB CURRENT DIRECTROY WINDOW and create a folder and name it as


DTL1_PCM.
9
Copy and paste all the MATLAB scripts and functions below into individual new m-files and
save them into the DTL1_PCM folder. By the end of this step, your DTL1_PCM should
contain a total of 12 m-files.

You only need to run the 7 MATLAB scripts whereas the other 5 MATLAB functions will be
called automatically by corresponding scripts as shown in Figure 4. To run a script, double-
click its m-file and then click on the Run button and follow the requested commands in the
COMMAND WINDOW (if any).
Proceed to section 4.3.2 to start exercising the examples provided. Please analyze the codes
carefully and understand the effect of executing each individual line. This is a crucial task as it
will help you to easily modify a code for a given problem.

PCM MATLAB-BASED FUNCTIONS

Please STUDY the following functions carefully!

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 as shown in
Figure 4.

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).
%
m_quan
= quantized output before encoding.
%
idx_quan
= index of quantized output.
%
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)))=...
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
1
0
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.

Function: mulaw_pcm

This function is the equivalent of the m-file uniform_pcm.m when using a µ-law PCM
scheme. It takes as its input a sequence of sampled values (m_samp) and the number of
desired quantization levels (L), and the compression constant µ and finds the quantized
sequence (m_quan), the encoded sequence (code), and the resulting SQNR (sqnr) in dB.

Copy and paste this MATLAB function into an m-file and save it as mulaw_pcm.m

function [sqnr,m_quan,code]=mulaw_pcm(m_samp,L,mu)

%MULAW_PCM mu-law PCM encoding of a sequence


[SQNR,A_QUAN,CODE]=MULAw_PCM(m_samp,L,MU).

m_samp = input sequence.


L = number of quantization levels (even).
%
sqnr
= output SQNR (in dB).
%
m_quan
= quantized output before encoding.
%
code
= the encoded output.

Call the mulaw function: [y,m_max]=mulaw(m_samp,mu);

Call the uniform_pcm function: [sqnr,y_quan,code]=uniform_pcm(y,L);

Call the invmulaw function:


x = invmulaw(y_quan,mu);

m_quan = m_max*x;
sqnr = 20*log10(norm(m_samp)/norm(m_samp - m_quan));

Function: mulaw

This function realizes the µ-law nonlinearity used in nonuniform quantization. The inputs to
this function are the sampled sequence and µ and it produces the compressed output y and the
maximum value of the samples sequence m_max.
Copy and paste this MATLAB function into an m-file and save it as mulaw.m

function [y,m_max]=mulaw(m_samp,mu)
%MULAW mu-law nonlinearity for nonuniform PCM
Y = MULAW(M_SAMP,MU).

M_SAMP = input vector.

m_max = max(abs(m_samp));
y =(log(1+mu*abs(m_samp/m_max))./log(1+mu)).*signum(m_samp);

11
Function: invmulaw

This function is the inverse of the µ-law; the inputs are the compressed sequence y and µ and
the output is the decompressed one x.

Copy and paste this MATLAB function into an m-file and save it as invmulaw.m

function x = invmulaw(y,mu)
%INVMULAW The inverse of mu-law nonlinearity

%X=INVMULAW(Y,MU) Y=normalized output of the mu-law nonlinearity.

x=(((1+mu).^(abs(y))-1)./mu).*signum(y);

Function: signum

This function is used to realize the sign function which is often called the signum function in
mathematics. The output of this function is -1 if the current input value is negative, 0 if the
current input value is also 0, and +1 if the input is positive. This function is used by the
mulaw.m and invmulaw.m m-files.

Copy and paste this MATLAB function into an m-file and save it as signum.m

function y = signum(x)
%SIGNUM finds the signum of a vector.
Y=SIGNUM(X)
X=input vector

y=x;

y(find(x>0))=ones(size(find(x>0))); y(find(x<0))=-ones(size(find(x<0)));
y(find(x==0))=zeros(size(find(x==0)));

4.3.3 PCM MATLAB-BASED SCRIPTS (EXAMPLES)

Please RUN the following scripts and answer the corresponding questions!

4.3.3.1 Uniform Quantization:

EXAMPLE (uniform_ex1):

This example is just an illustrative example with very 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 one shows the
normalized signal with its quantized values. In addition, the SQNR and the encoded quantized
samples (codewords) are returned. Remember that this is mid-rise uniform quantization where

12
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=16; [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:

Write down the samples of the signal, their quantized values, and their codewords.

Show the waveforms of the second figure generated on a full page. Define the quantization
regions, indicate the quantization levels, indicate the amplitudes of the quantized samples, and
show how the quantized samples have been successfully mapped to the corresponding
quantization levels.

On your sketch above, show the assigned codewords to each quantization level and show that
the codewords obtained are correct.

EXAMPLE (uniform_ex2):

This example generates a sinusoidal signal with amplitude =1. Using uniform quantization,
the samples sequence is quantized using 8 and 16 quantization levels. It plots the original
signal and the quantized signal on the same axes.
1
3
Copy and paste this MATLAB script into an m-file and save it as uniform_ex2.m

% MATLAB script for Illustrative Example uniform_ex2.m clc;clear;close all


echo on

t_samp = [0:0.01:10]; m_samp = sin(t_samp);

[sqnr_8L,m_quan_8L,code_8L]=uniform_pcm(m_samp,8);
[sqnr_16L,m_quan_16L,code_16L]=uniform_pcm(m_samp,16);

pause % Press a key to see the SQNR for L = 8.


sqnr_8L

pause % Press a key to see the SQNR for L = 16.


sqnr_16L

pause % Press a key to see the plot of the signal and its

% quantized versions. t = t_samp; m = m_samp;


plot(t,m,'-',t,m_quan_8L,'-.',t,m_quan_16L,'-',t,zeros(1,length(t)), ...

'linewidth', 2)
legend('Original','Quantized (L=8)','Quantized (L=16)','Location', ...
'SouthEast');

pause % Press a key to see the first 5 samples, corresponding quanited


% values, and corresponding codewords with 8 quantization levels
m(1:5)
m_quan_8L(1:5)

code_8L(1:5,:)
%
pause % Press a key to see the first 5 samples, corresponding quanited
% values, and corresponding codewords with 16 quantization levels
m(1:5)
m_quan_16L(1:5)
code_16L(1:5,:)
echo off

Questions:

Determine the sampling frequency used in this example.

Record the SQNR obtained in the two cases where the number of quantization levels, L, is 8
and 16. Compare the values obtained. Justify your answer.

View the MATLAB figure generated in full screen and observe the nature of the two
quantization signals. Relate your observation to the SQNR values obtained above.

EXAMPLE (uniform_ex3):

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 SQNR with 64
quantization levels. In addition, it displays the first 5 samples, their corresponding quantized
values, and the corresponding codewords.
14
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


echo on

m_samp = randn(1,500);

L = 64;
[sqnr,m_quan,code]=uniform_pcm(m_samp,L);

pause % Press a key to see the SQNR.


sqnr

pause % Press a key to see the first five input values.


m_samp(1:5)
pause % Press a key to see the first five quantized values.

m_quan(1:5)
pause % Press a key to see the first five codewords.

code(1:5,:) echo off

Questions:

Record the first 5 samples obtained, their corresponding quantized values, and the
corresponding codewords.
How many bits per codeword is used? Why is it so?

Show the PCM transmission bandwidth versus the SQNR tradeoff discussed in section 3.2 by
increasing the number of quantization levels to 128 (you need to estimate the PCM bandwidth
and SQNR for the two cases).

EXAMPLE (uniform_ex4):

In this example, the quantization error, defined as the difference between the input value and
the quantized value. Also, it plots the quantized output values as a function of the input value.
This is done with the number of quantization levels set to 16, 64, and 128. Uniform
quantization is used.

Copy and paste this MATLAB script into an m-file and save it as uniform_ex4.m

MATLAB script for Illustrative Example uniform_ex4.m clc;clear;close all


echo on

no_samp = 500;
L = [16 64 128];

for i=1:length(L)
randn('state',0)
m_samp= randn(1,no_samp);
[sqnr,m_quan,code]=uniform_pcm(m_samp,L(i));
%----------------------------------------------------------------------
L(i)
%----------------------------------------------------------------------
pause % Press a key to see the SQNR.
sqnr
% pause % Press a key to see the first five input values.

1
5
m_samp(1:5)
pause % Press a key to see the first five quantized values.

m_quan(1:5)
pause % Press a key to see the first five codewords.

code(1:5,:)

Plot the quantization error for each sample. q_error = m_samp - m_quan;
figure; plot ([1:no_samp],q_error)

Plot the quantized value as a function of the input value.


[Y,Index]=sort(m_samp);
figure; plot(Y,m_quan(Index))

end echo off

Questions:

Record the SQNR values obtained with the number of quantization levels set to 16, 64, and
128 and show the figures obtained.

On the figures of quantization error in each sample, compare between the natures of the
curves for the 3 cases with different number of quantization levels.
Observe the changes between the 3 figures of input-output relationships. How can you relate
this to the SQNR values recorded above?

EXAMPLE (uniform_ex5):

In this example, a non-stationary sequence of length 500 consists of two parts. The first 20
samples are generated according to a Gaussian random variable with zero mean and variance
400 (σ = 20), and the next 480 samples are drawn according to a Gaussian random variable
with mean and variance 1. Uniform quantization is used.

Copy and paste this MATLAB script into an m-file and save it as uniform_ex5.m

MATLAB script for Illustrative Example uniform_ex5.m clc;clear;close all


echo on

no_samp = 500;
L = [16 64 128];

for i=1:length(L) randn('state',0)

m_samp= [20*randn(1,no_samp-480) randn(1,no_samp-20)];


[sqnr,m_quan,code]=uniform_pcm(m_samp,L(i));
%----------------------------------------------------------------------

L(i)
%----------------------------------------------------------------------

pause % Press a key to see the SQNR. sqnr

pause % Press a key to see the first five input values.


m_samp(1:5)
pause % Press a key to see the first five quantized values.
m_quan(1:5)
pause % Press a key to see the first five codewords.
1
6
code(1:5,:)

Plot the quantization error for each sample. q_error = m_samp - m_quan;
figure; plot ([1:no_samp],q_error)

Plot the quantized value as a function of the input value.


[Y,Index]=sort(m_samp);
figure; plot(Y,m_quan(Index))

end echo off

Questions:

Record the SQNR values obtained with the number of quantization levels set to 16, 64, and
128 and show the figures obtained.

Explain how is the sort(m_samp) command in the script above functioning?

What is the effect of the randn('state',0)command?

4.3.3.2 Nonuniform Quantization:

EXAMPLE (nonuniform_ex4):

This example is similar to the preceding uniform_ex4.m example above except that a µ-law
nonuniform quantization is used here.

Copy and paste this MATLAB script into an m-file and save it as nonuniform_ex4.m

MATLAB script for Illustrative Example nonuniform_ex4.m clc;clear;close all


echo on

no_samp = 500;
L
=
[16 64 128];
mu
=
255;

for i=1:length(L) randn('state',0) m_samp=randn(1,no_samp);

[sqnr,m_quan,code]=mulaw_pcm(m_samp,L(i),mu);
%----------------------------------------------------------------------

L(i)
%----------------------------------------------------------------------

pause % Press a key to see the SQNR. sqnr


pause % Press a key to see the first five input values.
m_samp(1:5)
pause % Press a key to see the first five quantized values.
m_quan(1:5)
pause % Press a key to see the first five codewords.
code(1:5,:)

Plot the quantization error for each sample. q_error = m_samp - m_quan;
figure; plot ([1:no_samp],q_error)

Plot the quantized value as a function of the input value.

1
7
[Y,Index]=sort(m_samp); figure; plot(Y,m_quan(Index))

end echo off

Questions:

Record the SQNR values obtained with the number of quantization levels set to 16, 64, and
128 and show the figures obtained.
What is the effect of the command “figure” in the line;

figure; plot ([1:no_samp],q_error)

Explain briefly the execution flow of this script and show why the uniform_pcm.m m-file is
still used and invoked by the mulaw_pcm.m m-file.

EXAMPLE (nonuniform_ex5):

This example is similar to the preceding uniform_ex5.m example above except that µ-law
nonuniform quantization is used here.

Copy and paste this MATLAB script into an m-file and save it as nonuniform_ex5.m

MATLAB script for Illustrative Example nonuniform_ex5.m clc;clear;close all


echo on

no_samp = 500;
L
=
[16 64 128];
mu
=
255;

for i=1:length(L) randn('state',0)

m_samp= [20*randn(1,no_samp-480) randn(1,no_samp-20)];


[sqnr,m_quan,code]=mulaw_pcm(m_samp,L(i),mu);
%----------------------------------------------------------------------

L(i)
%----------------------------------------------------------------------

pause % Press a key to see the SQNR. sqnr


pause % Press a key to see the first five input values.
m_samp(1:5)
pause % Press a key to see the first five quantized values.
m_quan(1:5)
pause % Press a key to see the first five codewords.
code(1:5,:)

Plot the quantization error for each sample. q_error = m_samp - m_quan;

figure; plot ([1:no_samp],q_error)

Plot the quantized value as a function of the input value.


[Y,Index]=sort(m_samp);

figure; plot(Y,m_quan(Index))
end echo off

1
8
Questions:

Record the SQNR values obtained with the number of quantization levels set to 16, 64, and
128 and show the figures obtained.

Tabulate the SQNR values at different number of quantization levels (16, 64, and 128)
obtained from the scripts uniform_ex4.m, uniform_ex5.m, nonuniform_ex4.m, and
nonuniform_ex5.m.

Compare between the SQNR values obtained from the four scripts as tabulated above. Show
which quantization scheme, uniform or nonuniform, is superior to the other one and how this
superiority is sensitive to the dynamic range of the input sequence? Justify your answer.

PCM MATLAB-BASED EXERCISES

PROBLEM (1):

Construct a MATLAB script for a mid-tread uniform quantizer (odd number of quantization
2
levels) that can digitize the analog signal m(t) = t sin(t), -10 sec ≤ t ≤ 10 sec with a sampling
duration of 1 sec and 7 quantization levels. Show the signal samples, their quantized values,
and the corresponding codewords. Plot the original and quantized signals and then verify
graphically the correctness of the codewords obtained. Then, vary the odd number of
quantization levels and plot the corresponding SQNR values as a function of the number of
i
bits per codeword. Consider that the number of quantization levels is L = 2 -1, where i = 3, 4,
… , 8.

PROBLEM (2):

Develop two functions for an A-law compressor and its inverse and test their correct
functionality as they are supposed to compensate each other for an arbitrary input sequence.
Repeat the two examples for nonuniform_ex4.m and nonuniform_ex5.m using A-law and its
inverse functions and then tabulate and compare the SQNR values obtained for 3 different
quantization levels. Discuss the PCM performance in the two cases and its sensitivity to the
dynamic range of the input sequence.

REFERENCES

J. G. Proakis, M. Salehi, and G. Bauch, 2004, “Contemporary Communication Systems using


MATLAB”, Thomoson.

J. G. Proakis and M. Salehi, 2002, “Communication Systems Engineering”, Prentice Hall.

L. W. Couch, 2007, “Digital and Analog Communication Systems”, Prentice Hall.

M. Rice, 2009, “ Digital Communications: A Discrete-Time Approach”, Prentice Hall.

B. P. Lathi, 1998, “Modern Digital & Analog Communication Systems”, Oxford.

19

S-ar putea să vă placă și