You are on page 1of 6

CPE 340: Communication Systems (1/2552) Hands-on Assignment II Solution; Pulse Code Modulation

Hands-on Assignment II Solution: Pulse Code Modulation


Reading
1. Couch textbook, section 3.1 -- 3.3

Objectives
To understand the pulse code modulation system. To investigate the quantization error associated with analog-to-digital conversion. To examine the effect of quantization levels on the SNQR.

Lab Procedures
1. Start Simulink and create the model as shown below with the following components: a. Signal Process Blockset Signal Processing Sources Chirp b. Simulink Sinks To Workspace

Fig. 2.1: PCM source signal 2. Set the following parameters of the blocks:

CPE 340: Communication Systems (1/2552) Hands-on Assignment II Solution; Pulse Code Modulation

a. Chirp: Frequency sweep = Swept cosine, Sweep mode = Bidirectional, Initial frequency = 2 Hz, Target frequency = 10 Hz, Sample time = 1/500 (Generate 500 sample points in one second) b. To Workspace: Output variable = pcm_src 3. Set the simulation time to 10 seconds and run the simulation 4. From MATLAB workspace, use the function my_fft.m provided in the class to plot the magnitude spectrum (in dB) of the chirp signal. Set the frequency resolution to 0.1 Hz.
fs = 500; df = 0.1; [f X] = my_fft(pcm_src.signals.values, fs, df); plot(f, 20*log10(abs(X))); grid on;

I-1: Include the magnitude spectrum plot in your report. Suppose we use 50-dB attenuation as the criteria to determine the maximum frequency component. What is the (approximate) maximum frequency content of this chirp signal?

10 0 -10 -20 -30 -40 -50 -60 -70 -80 -90 -250 -200 -150 -100 -50 0 50 100 150 200 250

CPE 340: Communication Systems (1/2552) Hands-on Assignment II Solution; Pulse Code Modulation

From the figure, the maximum frequency component is approximately 100 Hz. 5. Remove the To Workspace block and add the components to the model as shown below: a. Signal Processing Blockset Quantizers Quantizer b. Signal Processing Blockset Signal Operations Sample and Hold c. Simulink Sources Pulse Generator d. Simulink Math Operations Subtract

6. Save the model to pcm_system.mdl and set the following parameters of the blocks: a. Pulse Generator: Pulse type = Sample based, Period = 2, Pulse width = 1. The sample time should be set to half of the sampling interval based on the Nyquist sampling theorem. Here, the sampling frequency can be set based on the maximum frequency content you have answered in Question I-1. b. Set the save format for the To Workspace blocks as Structure with time. 7. For the Quantizer block, you have to set the Quantization interval parameter, which is the step size between two adjacent quantization levels. Suppose we use the MATLAB

CPE 340: Communication Systems (1/2552) Hands-on Assignment II Solution; Pulse Code Modulation

variable qbits as the number of bits to encode the quantized signal, set the Quantization interval parameter such that it varies with qbits We have to set Quantization interval = 2/2^qbits. That is, the quantization interval is the input signal range (-1 to +1) divided by the total number of levels.
8.

At MATLAB prompt, set qbits to 4. Try the simulation by setting the stop time to 5 seconds. In the model, qt is the quantized signal. The following MATLAB code is used to plot the input signal and quantization noise Observe how the quantization noise fluctuates around 0.

S=input.signals.values(1,:); t1=input.time'; N=qnoise.signals.values(1,:); t2=input.time'; figure; plot(t1,S); hold on; plot(t2,N); axis([0 5 -2 2]);

9. The signal-to-quantization-noise ratio (SQNR) is obtained by dividing the average input signal power by the average quantization noise power. Recall that an average power of a signal can be computed by

If

is represented by a Npoint discrete data set , and

, with corresponding times

, we can approximate the integration by the summation as

The MATLAB function to compute an average power of a signal is given below:


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function P=avgpow(x, t) % Determine the average power from a time series sequence x corresponding % to the time sequence t. % % x = N-point data. % t = N-point time. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CPE 340: Communication Systems (1/2552) Hands-on Assignment II Solution; Pulse Code Modulation

function P=avgpow(x, t) % Determine the average power from a time series sequence x corresponding % to the time sequence t. % % x = N-point data. Must be a vector of length N % t = N-point time. Must be a vector of length N N=length(x); if N ~= length(t) error('Two data sets must have the same length'); end T=t(N)-t(1); % Time interval dt = t(2:N) - t(1:N-1); xx = x(1:N-1); P = sum((xx.^2).*dt)/T;

Then, at the MATLAB prompt, issue the following commands to compute the SQNR:
S=input.signals.values(1,:); t=input.time'; Ps=avgpow(S,t); N=qnoise.signals.values(1,:); t=qnoise.time'; Pn=avgpow(N,t); SQNR=10*log10(Ps/Pn)

10. Change the number of bits in the Encoder and the Decoder to the following values: 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, and determine the corresponding SQNR and fill in the table below: # Bits SQNR (dB) 4 5 6 7 8 9 10 11 12 13 14

CPE 340: Communication Systems (1/2552) Hands-on Assignment II Solution; Pulse Code Modulation

# Bits SQNR (dB) 4 26.26 5 32.16 6 38.11 7 44.09 8 50.07 9 56.01 10 62.12 11 68.02 12 74.10 13 80.06 14 86.12 II-2: Plot the SQNR (dB) vs. # encoding bits in MATLAB and compare them with the theoretical formula provided in the class. On the same figure, plot theoretical SQNR values. Include the table as well as the plot in your report. II-3: State the assumption that is used to derive the SQNR formula. Do the theoretical result and the simulation result agree? Provide the reason why.
90 Theory Simulink

80

70

60

50

40

30

20

10

11

12

13

14

They agree because the SQNR depends on the average signal power. In this case, the sweeping sinusoid has the same average power as the sinusoid.

You might also like