19
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. 1 Ayman, Chuah, May 2010

LAB SHEET - Faculty of Engineeringfoe.mmu.edu.my/lab/lab sheet/Tri1 2010-2011/Delta/ETM... · 2010-05-27 · Trimester 1 (2010/2011) DTL1: Pulse Code Modulation (PCM) ... Block diagram

  • Upload
    ngocong

  • View
    221

  • Download
    0

Embed Size (px)

Citation preview

Page 1: LAB SHEET - Faculty of Engineeringfoe.mmu.edu.my/lab/lab sheet/Tri1 2010-2011/Delta/ETM... · 2010-05-27 · Trimester 1 (2010/2011) DTL1: Pulse Code Modulation (PCM) ... Block diagram

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.

1Ayman, Chuah, May 2010

Page 2: LAB SHEET - Faculty of Engineeringfoe.mmu.edu.my/lab/lab sheet/Tri1 2010-2011/Delta/ETM... · 2010-05-27 · Trimester 1 (2010/2011) DTL1: Pulse Code Modulation (PCM) ... Block diagram

Experiment DTL1: Pulse Code Modulation (PCM) 1. OBJECTIVES:

1. To study the quantization process of PCM schemes 2. To synthesize the coding process of PCM schemes 3. To compare and analyze uniform and non-uniform quantization schemes

2. 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

Page 3: LAB SHEET - Faculty of Engineeringfoe.mmu.edu.my/lab/lab sheet/Tri1 2010-2011/Delta/ETM... · 2010-05-27 · Trimester 1 (2010/2011) DTL1: Pulse Code Modulation (PCM) ... Block diagram

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:

2.2.1 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

max2Δ = mL

(3)

The quantization levels are chosen to be the midpoints of the quantization regions and therefore, the quantization error at the nth sample is given by

e(n) = m(t) – mq(n) (4)

where t = nTs and e(n) has a uniform probability density function on the interval (-Δ/2, +Δ/2]. Two types of uniform quantizer characteristics are shown in Table 1.

Table 1: Types of uniform quantizer characteristics Mid-tread Uniform Quantizer Mid-rise Uniform Quantizer

• Origin point lies in the middle of a tread. • Origin point lies in the middle of a rising edge. • Used with odd number of quantization levels,

e.g. L = 7 as above. • Used with even number of quantization levels,

e.g. L = 8 as above.

3

Page 4: LAB SHEET - Faculty of Engineeringfoe.mmu.edu.my/lab/lab sheet/Tri1 2010-2011/Delta/ETM... · 2010-05-27 · Trimester 1 (2010/2011) DTL1: Pulse Code Modulation (PCM) ... Block diagram

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.

2.2.2 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

Page 5: LAB SHEET - Faculty of Engineeringfoe.mmu.edu.my/lab/lab sheet/Tri1 2010-2011/Delta/ETM... · 2010-05-27 · Trimester 1 (2010/2011) DTL1: Pulse Code Modulation (PCM) ... Block diagram

( )log(1 )( ) sgn

xy f x x

+μ= =

μ (5)

where |x| ≤ 1 , and its inverse is

( ) ( )1 1sgn

y

x 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 µ values (µ = no compression).

-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

x = input

y =

outp

ut

mu = 0mu = 10mu = 50mu = 255

Figure 3: µ-law input-output relation with different µ values.

A-law quantizers (in practice A = 87.6 is used), the input-output relation is defined by

In

1| |1 ln(

( ) sgn( )1 ln(

1 ln(

A xA

y f x xA x

⎧⎪ +⎪= = ⎨ +⎪⎪ +⎩

, | |)| |) 1, | | 1.

)

Ax

xA A

<

≤ ≤ (7)

and it inverse is expressed as

( )1

| | (1 ln( )) 1, | |1 ln( )

( ) sgnexp(| | (1 ln( )) 1) 1, |

1 ln( )

y A yA A

x f y yy A y

A A

+⎧ <

| 1.

+= = ⎨ + −⎪ ≤ ≤

⎪ +⎩

(8)

⎪⎪

5

Page 6: LAB SHEET - Faculty of Engineeringfoe.mmu.edu.my/lab/lab sheet/Tri1 2010-2011/Delta/ETM... · 2010-05-27 · Trimester 1 (2010/2011) DTL1: Pulse Code Modulation (PCM) ... Block diagram

2.3 Encoding: It is the process of representing a particular quantization level of the analog signal with a

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 (NB

MANCE:

Performance Metrics:

3.1.1 PCM Transmission Bandwidth:

The transmission bandwidth of a serial binary PCM (BPCM) waveform depends on the bit esent the data. The bit rate Rb is given by

Because an input analog signal band-limited to B Hz, requires a minimum fs ≥ 2B

samples per second (Nyquist theorem)we can transmit error-free at most two pieces of information per second per Hz bandwidth(realiza

M Signal-to-Quantization-Noise Ratio:

he signal-to-quantization-ratio (SQNR) in dB is expressed as follows

binary codeword.

C), 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.

3. PCM SYSTEM PERFOR

3.1

rate and the waveform pulse shape used to repr

Rb = R fs (9)

, we require a total of Rb = 2RB bits per second. Since

ble using Nyquist pulse shape), thus we require a minimum PCM transmission bandwidth of

BPCM = R B (10)

3.1.2 PC

T

2 2

2 2

( )10log 10log 20log( )

mdBSQNR

E m m norm= = =

σ −( )

( )e q

E m norm mm m

σ q−

(11)

where is the variance of the input analog signal m(t) and is the varquantization noise error as stated in equation 4.

iance of the

6

Page 7: LAB SHEET - Faculty of Engineeringfoe.mmu.edu.my/lab/lab sheet/Tri1 2010-2011/Delta/ETM... · 2010-05-27 · Trimester 1 (2010/2011) DTL1: Pulse Code Modulation (PCM) ... Block diagram

3.2 Performance Tradeoffs

values of R, the bandwidth of the serial PCM ignal will be significantly larger than the bandwidth of the original analog signal it presents. Thus, increasing the number of quantization levels will lead to the negative effect

andwidth. However, this increased number of quantization vels will result in the positive effect of reducing the quantization error in equation 11 and

thu

In this lab experiment, the MATLAB software will be used to understand and simulate the niform and nonuniform PCM quantizers. MATLAB is an

teractive matrix based system for scientific and engineering numeric computation and he fact that complex numerical problems can be solved

asily and in fraction of the time required with a programming language such as Fortran or C. it i

ommands using the ATLAB help. Explain briefly the functionality of each command and also perform two

From equation 10, and for reasonable large sreof increasing the transmission ble

s, improving the SQNR. Therefore, there exists a tradeoff between BCM transmission bandwidth (cost) and the SQNR (quality). 4. EXPERIMENT SOFTWARE

4.1 Introductory Information

basic concepts and mechanisms of uinvisualization. Its strength lies in te

s also powerful in the sense that by using its relatively simple programming capabilities, MATLAB can be easily extended to create new commands and functions.

4.2 Getting familiar with related MATLAB Commands and Functions

1. Open and start the MATLAB program by double-clicking the MATLAB icon. 2. In the MATLAB COMMAND WINDOW, learn about the following c

Marbitrary corresponding examples to enhance your familiarity.

>> help randn >>

>>

>> help abs >>

>>

> help max >

>

> >>

7

Page 8: LAB SHEET - Faculty of Engineeringfoe.mmu.edu.my/lab/lab sheet/Tri1 2010-2011/Delta/ETM... · 2010-05-27 · Trimester 1 (2010/2011) DTL1: Pulse Code Modulation (PCM) ... Block diagram

>> help length >>

>>

> help ones

>

>>

>>

> help fix

>

>>

>>

> help find

>

>>

>>

> help norm

>

>>

>>

> help echo

>

>>

>>

> help pause

>

>>

>>

> help sort

>

>>

>>

>> help global >>

>>

>> help de2bi >>

>>

8

Page 9: LAB SHEET - Faculty of Engineeringfoe.mmu.edu.my/lab/lab sheet/Tri1 2010-2011/Delta/ETM... · 2010-05-27 · Trimester 1 (2010/2011) DTL1: Pulse Code Modulation (PCM) ... Block diagram

4.3 SIMULATION OF PCM OPERATIONS USING MATLAB

f PCM MATLAB Functions and Scripts into MATLAB Environment

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

µ-law TLAB

unctio

4.3.1 Setup o

uniform_ex3.m, uniform_ex4.m, uniform_ex5.m, nonuniform. The first five scripts are based on mid-rise uniform quantization (even nonuniform_ex5.m

number of quantization levels) whereas the last two examples are based on a These 7 MATLAB scripts (examples) use another 5 MAnonuniform quantization.

f ns; 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:

1. Go to MATLAB CURRENT DIRECTROY WINDOW and create a folder and name ias DTL1_PCM.

t

9

Page 10: LAB SHEET - Faculty of Engineeringfoe.mmu.edu.my/lab/lab sheet/Tri1 2010-2011/Delta/ETM... · 2010-05-27 · Trimester 1 (2010/2011) DTL1: Pulse Code Modulation (PCM) ... Block diagram

2. C new m-files and save them into the DTL1_PCM folder. By the end of this step, your

les. 3. You only need to run the 7 MATLAB scripts whereas the other 5 MATLAB functions

k its m-file and then click on the Run button and follow the

ting each individual line. This is a

opy and paste all the MATLAB scripts and functions below into individual

DTL1_PCM should contain a total of 12 m-fi

will be called automatically by corresponding scripts as shown in Figure 4. To run a script, double-clicrequested commands in the COMMAND WINDOW (if any).

4. Proceed to section 4.3.2 to start exercising the examples provided. Please analyze the codes carefully and understand the effect of execucrucial task as it will help you to easily modify a code for a given problem.

4.3.2 PCM MATLAB-BASED FUNCTIONS

Please STUDY the following functions carefully!

• Function: uniform_pcm

a sequence of sampled values (m_samp) and e number of desired quantization levels (L) and finds the quantized sequence (m_quan), the

encoded sequen sed in uniform quantization and it is also used with other functions in nonuniform quantization as shown in

igure 4.

Cop

This function, given next, takes as its input th

ce (code), and the resulting SQNR (sqnr) in dB. It is u

F

y 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).

m_quan = quantized output before encoding.

value of m_samp.

x.

ation regions. levels

i=1:L

.

d(m_quan==q(i))));

% sqnr = output SQNR (in dB).%% idx_quan = index of quantized output. % code = the encoded output. m_max = max(abs(m_samp)); % Find the maximum m_quan = m_samp/m_max; % Normalizing m_samp. idx_quan = m_quan; % Quantization indedelta = 2/L; % Quantization step. q = delta.*[0:L-1]; % Define quantizq = q-((L-1)/2)*delta; % Centralize all quantization % around the x-axis. for 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(finend

10

Page 11: LAB SHEET - Faculty of Engineeringfoe.mmu.edu.my/lab/lab sheet/Tri1 2010-2011/Delta/ETM... · 2010-05-27 · Trimester 1 (2010/2011) DTL1: Pulse Code Modulation (PCM) ... Block diagram

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.

ft-msb'); % Generate codewords. code = de2bi(idx_quan', R, 'lesqnr = 20 * log10(norm(m_samp)/norm(m_samp - m_quan)); % Estimate SQNR.

• Function: mulaw_pcm

the number of d

equence (m_quan), the encoded sequence (code), and the resulting SQNR (sqnr) in dB.

nction into an m-file and save it as mulaw_pcm.m

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 desired quantization levels (L), and the compression constant µ and finds the quantizes Copy and paste this MATLAB fufun

sqnr = output SQNR (in dB). m_quan = quantized output before encoding.

all the mulaw function:

norm(m_samp - m_quan));

ction [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). %%% code = the encoded output. % C[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)/

• Function: mulaw

onlinearity used in nonuniform quantization. The inputs his function are the sampled sequence and µ and it produces the compressed output y and

opy and paste this MATLAB function into an m-file and save it as mulaw.m

This function realizes the -law nµto tthe maximum value of the samples sequence m_max. Cfunction [y,m_max]=mu%MULAW mu-law nonlinearity for nonuniform PCM

law(m_samp,mu)

%

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

Y = MULAW(M_SAMP,MU). % M_SAMP = input vector. m_max = max(abs(m_samp));

11

Page 12: LAB SHEET - Faculty of Engineeringfoe.mmu.edu.my/lab/lab sheet/Tri1 2010-2011/Delta/ETM... · 2010-05-27 · Trimester 1 (2010/2011) DTL1: Pulse Code Modulation (PCM) ... Block diagram

ompressed sequence y and µ

ction into an m-file and save it as invmulaw.m

• Function: invmulaw This function is the inverse of the µ-law; the inputs are the c

and the output is the decompressed one x. Copy and paste this MATLAB funfunction x = invmulaw(y,mu) %INVMULAW The inverse of mu-law nonlinearity

rmalized output of the mu-law nonlinearity.

x=(

%X=INVMULAW(Y,MU) Y=no

((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

, 0 if the is positive. This function is used by the

ulaw.m and invmulaw.m m-files.

s n into an m-file and save it as signum.m

in mathematics. The output of this function is -1 if the current input value is negativecurrent input value is also 0, and +1 if the input m Copy and paste thi MATLAB functiofunction y = signum(x) %SI

0))); (find(x<0))=-ones(size(find(x<0)));

GNUM finds the signum of a vector. % Y=SIGNUM(X) % X=input vector y=x; y(find(x>0))=ones(size(find(x>yy(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:

u

e first one shows the original input signal and its samples whereas the second one shows the ed values. In addition, the SQNR and the encoded quantized

amples (codewords) are returned. Remember that this is mid-rise uniform quantization where

EXAMPLE (uniform_ex1):

This example is just an illustrative example with very low sampling frequency. It issed to allow you to investigate easily on the resulting outputs. Two figures will be generated;

thnormalized signal with its quantizs

12

Page 13: LAB SHEET - Faculty of Engineeringfoe.mmu.edu.my/lab/lab sheet/Tri1 2010-2011/Delta/ETM... · 2010-05-27 · Trimester 1 (2010/2011) DTL1: Pulse Code Modulation (PCM) ... Block diagram

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]; = 10 * sin(t); m

'-b','linewidth', 2) d on

,'linewidth', 2)

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

6; n,code]=uniform_pcm(m_samp,L)

', 2)

i=1:L t (t,q(i)* ones(1,length(t)),'--g');hold on

end('normalized original signal','normalized sampled signal'); i -1.5 1.5])

t_samp = [0:pi/4 :2*pi]; m_samp = 10 * sin(t_samp) figure(1) plot (t,m,holstem (t_samp,m_samp, '--ro'hold on legaxis([0 2*pi -15 15]) L=1[sqnr,m_qua figure(2)plot (t,m/max(m),'-b','linewidth', 2) hold on stem (t_samp,m_samp/max(m), '--ro','linewidthhold on for ploend legaxis([0 2*pecho off Questions:

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

ndicate 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.

our sketch above, show the assigned codewords to each quantization level and

d 16 quantization levels. It plots the

2) Show the waveforms of the second figure generated on a full page. quantization regions, i

3) On yshow 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 anoriginal signal and the quantized signal on the same axes.

13

Page 14: LAB SHEET - Faculty of Engineeringfoe.mmu.edu.my/lab/lab sheet/Tri1 2010-2011/Delta/ETM... · 2010-05-27 · Trimester 1 (2010/2011) DTL1: Pulse Code Modulation (PCM) ... Block diagram

Copy and paste this MATLAB script into an m-file and save it as uniform_ex2.m % MATLAB script for Illusclc;clear;close all

trative Example uniform_ex2.m

echo o

sqnr_8L,m_quan_8L,code_8L]=uniform_pcm(m_samp,8);

to see the SQNR for L = 8.

o see the SQNR for L = 16.

and its

t_samp; m = m_samp; eros(1,length(t)), ...

width', 2) end('Original','Quantized (L=8)','Quantized (L=16)','Location', ...

ause % Press a key to see the first 5 samples, corresponding quanited ion levels

nd corresponding codewords with 16 quantization levels

(1:5)

n t_samp = [0:0.01:10]; m_samp = sin(t_samp); [[sqnr_16L,m_quan_16L,code_16L]=uniform_pcm(m_samp,16); pause % Press a keysqnr_8L pause % Press a key tsqnr_16L pause % Press a key to see the plot of the signal % quantized versions. t =plot(t,m,'-',t,m_quan_8L,'-.',t,m_quan_16L,'-',t,z 'lineleg 'SouthEast'); % p% % values, and corresponding codewords with 8 quantizat% 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, a% m% m_quan_16L(1:5) % code_16L(1:5,:) echo off

Questions:

1) Determine the sampling frequency used in this example. 2) 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. 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.

he SQNR with 64

3) View

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

14

Page 15: LAB SHEET - Faculty of Engineeringfoe.mmu.edu.my/lab/lab sheet/Tri1 2010-2011/Delta/ETM... · 2010-05-27 · Trimester 1 (2010/2011) DTL1: Pulse Code Modulation (PCM) ... Block diagram

Copy and paste this MATLAB script into an m-file and save it as uniform_ex3.m % MATLclc;cl

mp,L);

to see the first five input values. 5)

se % Press a key to see the first five quantized values.

s a key to see the first five codewords.

o off

AB script for Illustrative Example uniform_ex3.m ear;close all

echo on m_samp = randn(1,500); L = 64; sqnr,m_quan,code]=uniform_pcm(m_sa[ pause % Press a key to see the SQNR. sqnr pause % Press a keym_samp(1:paum_quan(1:5) pause % Prescode(1:5,:) ech Questions:

1) Record the first 5 samples obtained, their corresponding quantized values, and the

ny bits per codeword is used? Why is it so? 3) 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 bandwidth and SQNR for the two cases).

the difference between the input

script into an m-file and save it as uniform_ex4.m

corresponding codewords. 2) How ma

PCM EXAMPLE (uniform_ex4):

In this example, the quantization error, defined as 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 % MATLclc;cl

or i=1:length(L)

]=uniform_pcm(m_samp,L(i)); ----------------------------------------------------------------

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

y to see the SQNR. sqnr

a key to see the first five input values.

AB script for Illustrative Example uniform_ex4.m ear;close all

% echo on no_samp = 500; L = [16 64 128]; f randn('state',0) m_samp= randn(1,no_samp); [sqnr,m_quan,code %------ %----------- pause % Press a ke % pause % Press

15

Page 16: LAB SHEET - Faculty of Engineeringfoe.mmu.edu.my/lab/lab sheet/Tri1 2010-2011/Delta/ETM... · 2010-05-27 · Trimester 1 (2010/2011) DTL1: Pulse Code Modulation (PCM) ... Block diagram

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

(1:5,:)

ample. r = m_samp - m_quan;

m_samp);

% m_quan(1:5) % pause % Press a key to see the first five codewords. % code % Plot the quantization error for each s q_erro figure; plot ([1:no_samp],q_error) % Plot the quantized value as a function of the input value. [Y,Index]=sort( figure; plot(Y,m_quan(Index)) end echo off

Questions:

1) Record the SQNR values obtained with the number of quantization levels set to 16, ures obtained.

r in each sample, compare between the natures of s for the 3 cases with different number of quantization levels.

3) Observe the changes between the 3 figures of input-output relationships. How can you this to the SQNR values recorded above?

n and variance

.

script into an m-file and save it as uniform_ex5.m

64, and 128 and show the fig2) On the figures of quantization erro

the curve

relate 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 mea400 (σ = 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 % 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)];

]=uniform_pcm(m_samp,L(i)); ----------------------------------------------------------------

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

y to see the SQNR. sqnr

a key to see the first five input values.

lues.

[sqnr,m_quan,code %------ %----------- pause % Press a ke % pause % Press% m_samp(1:5) % pause % Press a key to see the first five quantized va% m_quan(1:5) % pause % Press a key to see the first five codewords.

16

Page 17: LAB SHEET - Faculty of Engineeringfoe.mmu.edu.my/lab/lab sheet/Tri1 2010-2011/Delta/ETM... · 2010-05-27 · Trimester 1 (2010/2011) DTL1: Pulse Code Modulation (PCM) ... Block diagram

% code(1:5,:)

ample. r = m_samp - m_quan;

m_samp);

% Plot the quantization error for each s q_erro figure; plot ([1:no_samp],q_error) % Plot the quantized value as a function of the input value. [Y,Index]=sort( figure; plot(Y,m_quan(Index)) end echo off

Questions:

1) Record the SQNR values obtained with the number of quantization levels set to 16, ures obtained.

mmand in the script above functioning? e effect of the randn('state',0)command?

niform Quantization:

ept that a

nto an m-file and save it as nonuniform_ex4.m

64, and 128 and show the fig2) Explain how is the sort(m_samp) co3) What is th

4.3.3.2 Nonu EXAMPLE (nonuniform_ex4):

This example is similar to the preceding uniform_ex4.m example above excµ-law nonuniform quantization is used here. Copy and paste this MATLAB script i%c MATLAB script for Illustrative Example nonuniform_ex4.m lc;clear;close all

u = 255;

]=mulaw_pcm(m_samp,L(i),mu); ----------------------------------------------------------------

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

y to see the SQNR.

a key to see the first five input values.

ee the first five quantized values.

(1:5,:)

ample. r = m_samp - m_quan;

% echo on

no_samp = 500; L = [16 64 128]; mfor i=1:length(L) randn('state',0) m_samp=randn(1,no_samp); [sqnr,m_quan,code %------ %----------- pause % Press a ke sqnr % pause % Press% m_samp(1:5) % pause % Press a key to s% m_quan(1:5) % pause % Press a key to see the first five codewords. % code % Plot the quantization error for each s q_erro figure; plot ([1:no_samp],q_error) % Plot the quantized value as a function of the input value.

17

Page 18: LAB SHEET - Faculty of Engineeringfoe.mmu.edu.my/lab/lab sheet/Tri1 2010-2011/Delta/ETM... · 2010-05-27 · Trimester 1 (2010/2011) DTL1: Pulse Code Modulation (PCM) ... Block diagram

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

Questions:

set to 16, tained.

fect of the command “figure” in the line; figure; plot ([1:no_samp],q_error)

in briefly the execution flow of this script and show why the uniform_pcm.m

iform_ex5.m example above except that

1) Record the SQNR values obtained with the number of quantization levels64, and 128 and show the figures ob

2) What is the ef

3) Explam-file is still used and invoked by the mulaw_pcm.m m-file.

EXAMPLE (nonuniform_ex5):

This example is similar to the preceding unµ-law nonuniform quantization is used here.

opy and paste this MATLAB script into an m-file and save it as nonuniform_ex5.mC% MATLAB script for Illustrative Example nonuniform_ex5.m

u = 255;

(1,no_samp-480) randn(1,no_samp-20)]; _quan,code]=mulaw_pcm(m_samp,L(i),mu);

%----------------------------------------------------------------------

--------------------------------------------------- ess a key to see the SQNR.

key to see the first five input values.

ntized values.

e % Press a key to see the first five codewords.

the quantization error for each sample.

1:no_samp],q_error)

tized value as a function of the input value.

m_quan(Index))

clc;clear;close all % echo on

no_samp = 500; = [16 64 128]; Lmfor i=1:length(L) randn('state',0) m_samp= [20*randn [sqnr,m L(i) %------------------- pause % Pr sqnr % pause % Press a % m_samp(1:5) % pause % Press a key to see the first five qua% m_quan(1:5) % paus% code(1:5,:) % Plot q_error = m_samp - m_quan; figure; plot ([ % Plot the quan [Y,Index]=sort(m_samp); figure; plot(Y,end echo off

18

Page 19: LAB SHEET - Faculty of Engineeringfoe.mmu.edu.my/lab/lab sheet/Tri1 2010-2011/Delta/ETM... · 2010-05-27 · Trimester 1 (2010/2011) DTL1: Pulse Code Modulation (PCM) ... Block diagram

19

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

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

niform_ex5.m.

r nonuniform, is superior to the other one

B script for a mid-tread uniform quantizer (odd number of uantization levels) that can digitize the analog signal m(t) = t2 sin(t), -10 sec ≤ t ≤ 10 sec with

tion levels. Show the signal samples, their uantized values, and the corresponding codewords. Plot the original and quantized signals

raphically the correctness of the codewords obtained. Then, vary the odd numbe

nonuniform_ex4.m and nonuniform_ex5.m using A-law and s inverse functions and then tabulate and compare the SQNR values obtained for 3 different

uss the PCM performance in the two cases and its sensitivity to the ynam

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

007, “Digital and Analog Communication Systems”, Prentice Hall.

[5] ital & Analog Communication Systems”, Oxford.

Questions: 1) Record the SQNR values obtained

nonu3) Compare between the SQNR values obtained from the four scripts as tabulated above.

Show which quantization scheme, uniform oand how this superiority is sensitive to the dynamic range of the input sequence? Justify your answer.

4.3.3 PCM MATLAB-BASED EXERCISES PROBLEM (1):

Construct a MATLAqa sampling duration of 1 sec and 7 quantizaqand then verify g

r of quantization levels and plot the corresponding SQNR values as a function of the number of bits per codeword. Consider that the number of quantization levels is L = 2i -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 itquantization levels. Discd ic range of the input sequence.

REFERENCES

[1] J. G. Proakis, M. Salehi, and G. Bauch, 2004, “Contemporary Communication Systems using MATLAB”, Thomoson.

[2

[3] L. W. Couch, 2

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

B. P. Lathi, 1998, “Modern Dig