Experiment # 2. Pulse Code Modulation: Uniform and Non-Uniform

c 2011 Bruno Korst-Fagundes ECE417 CommLab Experiment # 2 Pulse Code Modulation: Uniform and Non-Uniform • Name: Experiment Date: • Student No.:...
Author: Giles Goodwin
0 downloads 4 Views 357KB Size
c

2011 Bruno Korst-Fagundes

ECE417

CommLab

Experiment # 2 Pulse Code Modulation: Uniform and Non-Uniform • Name:

Experiment Date:

• Student No.:

Day of the week:

Time:

• Name: • Student No.:

Grade:

3

/ 10

3

2

2

1 1

−→

0

−1

−3

Output

Input Signal

−2

2

3

4

5

6

7

8

9

−→

E000 Mask

0

−1

−2

−3

−4

10

1

2

3

4

5

6

7

8

−3

9 −3

x 10

x 10

µ

1

10

[ln(1+mu)]^−1 1.5

8 1 6

+

4

ABS

2

0

X

ln

X

0.5

0

−2 −0.5 −4

−6 −1 −8

−10

0

0.002

0.004

0.006

0.008

0.01

0.012

0.014

0.016

0.018

−1.5

0.02

0

0.002

0.004

0.006

0.008

0.01

0.012

0.014

0.016

0.018

0.02

sign

1

Purpose

The purpose of this experiment is to introduce uniform and non-uniform Pulse Code Modulation (PCM). Uniform PCM will be explored through probing quantization, and Non-uniform PCM will be introduced with the implementation of a µ-Law compressor. PCM is a technique widely used in communication systems, in particular in the conversion of analog signals into their digital representation for processing and transmission. This experiment will be divided in four parts: • First, you will explore Uniform PCM by modifying the number of bits using to quantize each sample of a signal. You will use different number of bits per sample and observe the relation between number of bits per sample and quantization noise; 1

• You will then simulate a µ-Law compressor and modify its parameters to verify the outcomes; • Finally, you will run the µ-Law compressor on the DSP platform to observe the results on your oscilloscope.

2

Background Reading and Preparation

It is fair to say that every textbook in digital signal processing starts by describing how an analog signal is converted into a digital one prior to being processed. Sampling and quantization are described in detail in many references. Therefore, rather than looking for a single reference for background reading, you can refer to any of the textbooks cited in the bibliography presented at the end of this outline. Keep in mind, however, that these should be seen as introductory reading, since they only touch on PCM as applied to A/D conversion. Some references [1], [2] and [3], look at PCM from the point of view of communication systems, and go beyond A/D conversion. You should review your notes on sampling and quantization, or on analog-to-digital conversion. With the µ-Law PCM scheme, the signal will pass through a compressor , which will apply a logarithmic mapping to the incoming signal prior to quantization. The quantization of the compressed incoming signal is then done with a smaller number of bits per sample. The compression method you will utilize in this experiment is defined in the ITU/T G.711 standard. The outcome of µ-Law and A-Law compressors is very similar, and both can be implemented in a table look-up algorithm in which the compression curve is stored in an array and the output is generated by mapping the normalized input onto that array. Non-uniform quantization allows for the signal-to-noise ratio to be kept through the dynamic range of the signal. The louder parts of the signal (which are statistically less prevalent in telephony) are quantized with a smaller number of bits than they would with a uniform quantizer, resulting in a lower signal-to-noise ratio. That is, by applying compression prior to quantization, the signal that extends beyond a certain level will likely utilize only a few more bits per sample (the most significant ones) than would a softer signal. In turn, the softer signal will present a higher signal-to-noise ratio than the louder signals, keeping the ratio constant through the dynamic range. Subjectively, compression on a voice signal would be perceived by a loss of quality in the signal for loud talkers. At the receiving end, the compressed signal is passed through an expander and the original signal is recovered. It is possible, for instance, to achieve a compression from 14 bits to 8 bits on a voice signal (a compression ratio of 1.75:1) without much computational complexity. Before coming to the lab, complete the lab preparation and hand it to the T.A..

2

3

Experiment

3.1

Uniform Quantization

This section is divided into three main parts: the simulation of a system presenting aliasing; the modification of sampling rates to verify the occurence of aliasing on real signals; and the verification of the relation between signal integrity and word length in the quantization process. Differently that the previous experiments where you verified the concepts by designing a “whole” system (such as an FM modulator), this section will touch individually on the two main parts of PCM, namely: sampling and quantization. The reason for taking this approach is primarily due to the fact that the target hardware already provides a CODEC which utilizes PCM to convert the signal from analog to digital. In this section you will modify the data generated by the existing CODEC and observe the consequences of the modifications on the output signal.

3.1.1

Fewer Bits, More Noise

You should expect that as you reduce the number of bits assigned per sample of the incoming analog signal, you should have a gradually less accurate digital representation of your analog signal. Consider the extreme case: you have one bit to represent samples of a sinusoid. Of course, with only two values possible, one of them would be assigned to every sample in the positive cycle of the sinusoid and the other would be assigned to every sample in the negative cycle. The result would be a square wave with the same period as the original sinusoid. Now consider the frequency domain view of this new signal sampled with only one bit per sample. You used to have one component (ideally an impulse) in the frequency domain for the sinusoid, and after sampling it you have that same component and all of its odd harmonics. This is not at all a faithful representation of the analog signal. As you increase the number of bits, you decrease the amount of quantization noise, achieving a gradually better representation of your signal. The program to be run on the DSP is given to you (it is located at c:/ECE417 2011/Exp02/Uniform). Open Code Composer Studio and open the project named quantization.pjt. Look briefly at the code. You are to change the code to modify the number of bits used for each sample of the input signal. The CODEC provides 16 bits for each sample on each channel. You will force the samples for one of the channels to be “quantized” by using only a reduced number of bits. When you reduce the number of bits on the quantization, you increase the error introduced in the process by reducing the number of quantization levels available. So, should you modify the MSBs or the LSBs to accomplish this? The operation you will utilize to modify the word length of the incoming signal is known as “masking,” and you likely have already made use of it in a Microprocessors course. It consists of performing a logical AND operation between the data word passed on to the DAC and a “mask” that you select. Looking at your quantization.c program, you will notice that there are several masking options for the y variable. Use only one mask at a time, and comment out the others. You may change the mask to answer the questions below. Do not forget to recompile and run the program every time you make a change. Use an input signal of around 2.7 Vpp and 100Hz. You can choose to use a sine wave or a ramp.

3

The reason you are using 2.7 Vpp is that you must utilize the full range of the CODEC. If you do not have the full range of the signal going into the CODEC, you will not get the right results. • You are to implement a 3-bit quantizer using an appropriate mask. What should the mask be? How many quantization levels are there? Explain what part of the sample 16-bit field the mask is selecting. (1pt)

• Sketch the original signal, the quantized signal, and the quantization error by using the Subtraction function in Math mode on the oscilloscope. The quantization error is the difference between the original signal and its quantized version. (2pts)

• Show your quantization error output on the oscilloscope to the TA, ahd have the TA sign here. (1pt)

3.2

Non-Uniform Quantization

In this part, you will simulate first and then run a µ-Law compressor. On this second part, you will use a sinusoid and a ramp, and will observe the resulting compressed output on the oscilloscope. You will be required to understand the implementation of the compressor and relate it back to the theory, and to verify the characteristic curves for different parameter values. This is a fancy way of saying: vary the level at the input, read the level at the output and plot points for every level.

4

3.2.1

Simulation of a µ-Law Compressor

It is assumed that you are familiar with Simulink. If you can’t find the simulation blocks you are looking for, you can run a search within Simulink. Remember that you will never use continuoustime systems in the ECE417 experiments, and the sampling time of your blocks must be set to 1/48000, so that the system you simulate is representative of that you will implement on the DSP target. Not every block requires that you set a sampling time. Those which do require, must be set to 1/48000. Your first system will be made of a DSP-Sine wave generator, a ramp generator, a switch, your compressor of choice found in the ECE417 blockset and two time-based scopes. You can use the template file exp02 sim.mdl provided in the c:/ECE417 2011/Exp02/NonUniform directory. It will look like figure 1 below.

Figure 1: Non-Uniform PCM - model for simulation Use scopes to view the output of the generators and to view the output of the compressor. Your sine wave and ramp signals should be set to 1000Hz, amplitude of 1 and sampling frequency of 48KHz (this means “sampling time” of 1/48000 in the proper field of the sine wave generator block). Run the system and configure the time-based scopes to provide you with the best reading. You should observe the scopes looking like the Figure 2 (notice the maximum level of 1).

5

(a) µ-Law Ramp

(b) µ-Law Sine

Figure 2: Scope Displays After Compression: Ramp and Sine

Since you are simulating a µ-Law compressor, use first a µ value of 255. As you know from your preparation, this is a standard value and is equivalent to an A-Law value of 87.6. They are determined through subjective voice tests (Mean Opinion Square). If you right-click on the Mu-Law Compressor block , and select “look under mask”, a window will open with the block diagram presented in Figure 3 (comments were added for clarity).

Figure 3: µ-Law Compressor - modified from Simulink Library

After you got these models going, answer the question below: • Now you will draw the characteristic curve for your compressor. You will use four values for the constant, vary the input signal amplitude from 0.01 to 1.0 and measure the output (pick 6

five points and draw the graph with input amplitude on the x axis, and output amplitude on the y axis). Use a sine as an input. Use the values 0, 10, 255 and 1000 for µ. Draw the graph for every value of the constant (that is µ) and comment on your results.(3pts)

You could, alternatively, use an XY Graph found in the main blookset in Simulink to view the curves. Your simulation model would then look like the picture below. Since you are interested in input values from 0 to 1, you should set the axis of your XY Graph to those values by right-clicking on the block.

Figure 4: Alternative simulation with XY Graph

• Show the XY scope running and have the TA sign the box. (1pt)

7

3.3

Implementing and Evaluating µ-Law or A-Law Compressors

In this part of the experiment, you will run your compressor on a DSP platform. Keep in mind that this compression is applied prior to assigning bits to the levels (remember uniform PCM above?), so that the most compressed (higher) signal levels will have less room to manoueuvre, as you have just observed in the simulation. At the receiving end, the signal will be expanded back to its original shape. Systems which implement compression and expansion are known as companders. Here you will be given the necessary executable programs to be loaded and run on the DSP platform. If you would like to design your own compander some other time, refer to [?]. The procedure to download the executable program is as follows: • With the target powered on, open Code Composer Studio. You will notice the LEDs blink while CCS is coming up. If you want to check the target, go under GEL (top menu)/ Check DSK / QuickTest. This should cause the LEDs to blink again and a message will appear on the I/O panel of CCS. • Go under File (top menu) / Load Program. This will open a window from which you will select your program. The executable program is of type .out. All programs for this experiment will be found in the directory C:/ECE417 2011/Exp02/NonUniform/Executables. • After you select the file and click OK, the executable will be loaded onto the target memory. Now you can go under Debug (top menu)/ Run, or press F5 or click on the running man on the vertical panel on the left of the CCS window to run the program. • As a special feature of Code Composer Studio you may have to load it twice only for the first load. Go figure. Test your hardware first to see if it is implementing compression as it should. Use a ramp input (2.7Vpp , 1KHz) and observe the output. Then use a sinusoid with the same parameters. Notice that the higher levels are the ones being “punished” by the compression. You already know how this should look from the simulation portion of this experiment. First, load the executable program for your compressor of choice with the standard parameter value (for µ it is 255). • Load the executable program with the largest parameter value. If you decrease the gain of the input signal, do you expect the compressed signal to appear better or worse? Why? Does your system behave as you expect? (1pt)

To finalize your experiment and to convince yourself that µ-Law and A-Law are similar compression standards, load the executable in which one channel is compressed using A-Law and the other is 8

compressed using µ-Law (the name of the program is alawmulaw.out. Can you tell if there is a difference? Lower the input voltage, and bring it back to 2.7Vpp to observe the effect of both compressors.

• Show the running system to the TA, and have the TA sign the box. (1pt)

4

Accomplishments

In this experiment, you acquired a better understanding of Pulse Code Modulation by further probing into uniform and non-uniform quantization. You verified the impact caused by the number of bits on quantization noise, and also verified the effect of different µ values on the compression of a signal.

References [1] S. Haykin and M. Moher Introduction to Analog and Digital Communications, 2nd Ed. - Wiley, 2007 [2] B. P. Lathi, Modern Digital and Analog Communication Systems, 3rd Edition. New York: Oxford University Press, 1998. [3] S. Haykin Communication Systems, 4th Edition. Toronto: John Wiley & Sons, Inc., 2001.

9

Preparation - Uniform and Non-Uniform Quantization • Name:

Experiment Date:

• Student No.:

Grade:

/ 10

1. Sketch the process of sampling and quantization for a 1KHz sine wave sampled at 8KHz. You are to use a 3 bit quantizer and assume linear quantization. Use your illustration to explain quantization noise. (2pt)

2. Write the equations for µ-Law and A-Law compression. What are the typical values for the µ parameter and the A parameter? (assume 8 bits)(2pt)

3. Based on your experience in Simulink, draw a block diagram to implement a µ-Law OR an A-Law compressor.(2pt)

10

4. Explain how the use of non-uniform quantization causes the SNR to become almost independent of the input signal power for a large dynamic range.(2pt)

5. You have a speech signal and a sinusoidal signal. Based on your knowledge of their probability density function, explain on which of them it would be most appropriate to apply non-uniform quantization. (2pt)

11