PROJECT 5: DESIGNING A VOICE MODEM Instructor: Amir Asif CSE4214: Digital Communications (Fall 2012) Computer Science and Engineering, York University 1. PURPOSE In this laboratory project, you will design and built a prototype voice modem based on MATLAB. This project builds on Project 4 where a binary Pulse Shift Keying (BPSK) communication system was implemented. The system will be augmented by adding a convolutional encoder and its decoder to model a prototype voice modem. The focus of this project is on convolutional codes that were covered in this week s lecture. You will learn how a digitized speech signal is communicated over a noisy medium, explore how convolutional codes can detect and selfcorrect errors introduced during communication without any retransmission, and perform Monte Carlo simulations to compare the performance of a voice modem with convolutional codes versus one without the convolutional codes. By the end of this project, you will be able to 2. OBJECTIVES 1. Use a linear finite-state shift register to generate the convolution code for a given sequence of information. 2. Use the generator matrix approach as a computational implementation for the finite-state shift register to generate convolutional codes. 3. Implement the Viterbi implementation for decoding a convolution encoded information sequence. 4. Analyze the performance of a voice modem using convolutional code versus one without convolutional codes. You will quantify improvement in the performance of the voice modem with convolutional codes. 3. REFERENCE Review topics: Binary Pulse Shift Keying (BPSK), Convolutional Codes, Viterbi Algorithm, Trellis Diagram. References: Bernard Sklar, Digital Communications: Fundamentals and Applications, Prentice Hall Publisher, Second edition. Chapter 7: Channel Coding - Part 2. 4. INTRODUCTION In this project, we will build a prototype voice modem with the schematic representation shown in Fig. 1. Compared to the Phase Shift Keying (PSK) implementation that you designed in the last project, two additional blocks Convolutional Encoder and Convolutional Decoder are added to represent a voice modem. The focus of this project is on convolutional codes that were covered in this week s lecture. Recall that the convolutional codes represent one technique within the general class of channel codes (also called error-correction codes) that permit reliable communication of an information sequence over a channel that adds noise, introduces bit errors, or otherwise distorts the transmitted signal. As per the requirements of the voiceband modems, convolutional codes are typically used in low-latency applications such as real-time speech communication where a retransmit is not possible. Other applications of convolutional codes include deep-space communications and as constituent blocks in Turbo codes.
Information Source Convolutional Encoder Modulator s i (t) Input Sequence Codeword Sequence m = m 1,m 2,...,m i,... U = G(m) = U 1,U 2,...,U i,... with U i = u 1i,u 2i,...,u ji,...,u ni AWGN Channel Information Sink Convolutional Decoder Demodulator ŝ i (t) Detected Sequence Demodulated Codeword Sequence m = m 1, m 2,..., m i,... Z = Z 1,Z 2,...,Z i,... with Z i = z 1i,z 2i,...,z ji,...,z ni Figure 1: A digital communication system emphasizing channel encoding and modulation. We will run a Monte-Carlo simulation to characterize the performance of a binary communication system that uses convolutional encoding with pulse shift keying (PSK) modulation. Figure 1 illustrates the block diagram of such a digital communication system where the input message is denoted by the sequence m with each m i representing a binary digit (bit). The index i in m i is the time index, thus m 1 is transmitted before m 2 and so on with the remaining bits. The channel encoder encodes the input message m U = G(m) (1) producing the codeword U that is transmitted through an AWGN channel with power spectral density of N o. In this project, a (n, 1, K) binary convolutional encoder is used as the channel encoder. Therefore, a codeword of length n is produced for each input bit. More on the convolutional encoder later. The modulation and demodulation scheme used in the digital communication system modeled in figure 1, is the M-ary PSK. Recall that the general representation for the PSK waveforms is s i (t) = 2E T cos [ ω o t 2πi ], i = 1,...,M, 0 t T (2) M where ω o is the carrier frequency in radians/s and is assumed an integer multiple of 2π/T. The transmitted signal s i (t) has a constant envelope with a duration of T and energy E. In project 5, we implemented the PSK modulator and demodulator using Matlab. These functions are made available to you for this project. In the following section, we focus on the binary convolutional encoder and decoder. 5. LABORATORY PREPARATION A binary convolutional code is generated by passing the information sequence to be transmitted through a linear finite-state shift register. For a (n, 1, K) convolution code, the shift register consists of K stages and n linear modulo-2 function generators. The input data is shifted into and along the shift register a single bit at a time producing a n-tuples output for each shift. Consequently, the code rate for a (n, 1, K) convolutional encoder is 1/n. To illustrate the working of a convolutional encoder, consider the (3,1,3) convolutional encoder shown in figure 2 where the output U = [U i1,u i2,u i3 ] at instant i is obtained from the message bit m i at instant i and the previous (K 1) (which equals 2 for in our example) message bits m i 1 and m i 2. The operator is the modulo-2 arithmetic operator. Initially, the shift registers are assumed to be in the all zero state. Suppose the first input bit m 1 is a 1. At the next clock cycle, the initial content of the registers is moved towards the right by 1 bit and the message bit occupies the left most register. The registers are therefore set to states 1, 0, and 0, i.e., m i = 1,
m m i m i 1 m i 2 U i1 + U i2 + U i3 Figure 2: A (3,1,3) convolutional encoder. m i 1 = 0, and m i 2 = 0. The value of the three output bits U ij, for i = 1 and 1 j 3, are given by U i1 = m i, U i2 = m i m i 2, and U i3 = m i m i 1 m i 2. (3) Solving equations (3) for the codeword U 1 gives 111. Suppose now that the second bit is a 0. The registers are set to 0, 1, and 0 at the next clock cycle and the codeword U 2 is 001. By following this procedure, the codewords U i can be generated for the remaining message bits. Problem 1: Suppose that the registers in figure 2 are initially reset to 0. Find the output codeword sequence U if the input message sequence is given by m = 11011 followed by (K 1) zeros to flush the registers. Repeat if the registers are initially set to 1 and 1 s are used to flush the registers. In the remaining project, we will assume 0-initial and 0-flush conditions for the registers. This problem needs to be solved analytically. There are several alternative methods discussed in the Sklar text that can be used to describe a convolutional code. These include the state diagram, the tree diagram, and the trellis diagram. For implementing in Matlab, we will use an alternate approach of assigning a generator matrix G, just as we did for the block codes. The generator matrix G is defined in terms of n connection vectors, denoted by g 1, g 1,..., g n, one for each of the n-modulo-2 adders. Each vector has a dimension K and describes the connection of the encoding shift register to that of the modulo-2 adder. A 1 in the i th position of the vector indicates that the corresponding stage in the shift register is connected to the modulo-2 adder, and a 0 in a given position indicates that no connection exists. For the (3,1,3) convolutional encoder illustrated in figure 1, the connection vectors are given by g 1 = [ 1 0 0 ], g 2 = [ 1 0 1 ], and g 3 = [ 1 1 1 ] (4) The generator matrix G of the convolutional code is then given by G = [ g T 1 g T 2 g T 3 ] (5) where subscript T denotes transposition. In order to calculate the output codewords U, the content of the registers at each iteration i is placed in a row vector s i, which is multiplied with the generator matrix G, i.e., U i = s i G. In our example of (3,1,3) convolutional code, the content of the register is 1 0 0 for iteration i = 1. The codeword U 1 = [ 1 0 0 ] 1 1 1 0 0 1 0 1 1 The procedure is repeated for the remaining message bits. = [ 1 1 1 ]. Problem 2: Repeat problem 1 using the generator matrix G. Compare the code rate of the algorithm to the theoretical bound (k/n). This problem needs to be solved analytically. There are many algorithms that can be used for decoding of convolutional codes. The Viterbi algorithm is probably the most widely used decoding method for convolutional codes. This algorithm is particularly interesting because it is a maximum likelihood decoding algorithm which upon receiving the channel output, searches through the
trellis diagram to find the path that is most likely to have generated the received sequence. Details on the Viterbi algorithm are given in section 7.3 of the Sklar text. Problem 3: Assume that the transmitted sequence for problem 2 with 0 initial state and 0 used to flush the registers, is corrupted with AWGN so that the received sequence is given by 111001100110010011. Using the Viterbi algorithm, find the maximum likelihood information sequence and the number of errors. This problem needs to be solved analytically. 6. LABORATORY EXPERIMENT There are different implementations of the Viterbi algorithm for detection of binary convolutional code. We will be using the following implementation which consists of six steps. 1. Parse the received sequence into m subsequences of length n. 2. Set the index l to 1 and initialize the state value to (K 1) bits 0-tuples. The zero state correspond to the initial state. Since at this time, we have not traversed any path in the Trellis diagram, we initialize the corresponding Hamming distance to 0. For decoding of the (3,1,3) convolutional code in our example of fig. 2, the initialization conditions are state = [0 0]; hdistance = [0]; dsequence = [] where we use the notation used in Matlab. The variable state denotes the states being used in the Trellis diagram, the variable hdistance denotes the Hamming distance metric corresponding to that state, while dsequence denotes the decoded sequence. As the algorithm iterates, we assume different values of these variables are saved along different rows. 3. For each of the states included in state, do the following: (a) Assuming 0 as the message bit, append the variables state, hdistance, and output. The Hamming distance is calculated by comparing the n-bit parsed received sequence with the expected code symbols generated as a result of state transitions. (b) Repeat the item (a) assuming 1 as the message bit. For binary code, you will observe that the dimensions of the three variables would be doubled. Note that this step moves you to the (l + 1) stage of the Trellis diagram. 4. If states are repeated in the variable state, delete the entries corresponding to the higher Hamming distance from each of the three variables state, hdistance, and output. This is the path-elimination step of the Viterbi algorithm. 5. If l = m, proceed with the next step; else, increment l by 1 and go to step 3. 6. The decoded sequence is the value of dsequence corresponding to the minimum Hamming distance in hdistance. The minimum value of hdistance gives the number of corrected errors. Based on the information provided above, attempt the following problems. Problem 4:Write a Matlab function myconvcode that generates (3,1,3) convolution code according to the encoder illustrated in fig. 2. Use 0-initial and 0-flush conditions for the registers. Check your output with the theoretical value that you calculated in problem 1. Problem 5: Write a Matlab function myviterbi that decodes the codeword sequence U generated by the (3,1,3) convolution encoder shown in fig. 2. Check the function by decoding your answer to problem 1. Also, validate the function by solving problem 3. In problems 6-10, we will run a Monte Carlo simulation for the binary communication system illustrated in figure 1. As you will note, several of the functions that you wrote in project 5 can be used in the following problems. Problem 6: Write a function myinput that simulates the transmission of 5000 bits using the random number
generator. To accomplish this task, we use Matlab function rand to generate 5000 random numbers in the range (0,1). This range is divided into two equal intervals, (0, 0.5) and (0.5, 1) where the subintervals correspond to bits 0 and 1 respectively. Save the sequence of transmitted symbols m i s as you will be required to compare the sequence with the detected sequence at the receiver. Problem 7: The symbols, m i s, are encoded using the (3,1,3) convolutional encoder that you designed in problem 4. Calculate the output of the convolutional encoder first in terms of bits and then in terms of 4-ary symbols (a 1, a 2, a 3, a 4 ) by parsing m i in sub-sequences of 2-bits. Problem 8: The symbols, a i s, are modulated using a 4-ary PSK defined in equation (2). The signal energy can be normalized to unity, i.e., E = 1 with the carrier frequency ω o = 6π/T and T = 1. Choose a sampling frequency of 1/30s. Plot the waveform for the first 5 symbols. Save the 4-ary sequence a i s since we will be comparing the sequence with the demodulated value at the output of the PSK demodulator. Problem 9: Add AWGN with a PSD N o = 2 to the waveform generated in problem 7. This represents the received waveform. Plot the waveform for the first 5 received symbols and compare with your plots obtained in problem 7. Problem 10: Using a 4-ary coherent detection scheme, demodulate and detect the sequence of alphabets a i s. Compare the detected sequence with the transmitted sequence of problem 7 and calculate the symbol-error rate P E. Problem 11: Convert the message stream obtained in problem 10 to a binary sequence and decode using the Viterbi algorithm implemented in the function myviterbi, your answer to problem 5. Calculate probability of bit error P B. Problem 12: Repeat problem 5 to 10 for different values of PSD N o = 4, 8, 12, and 16 four to five times each and calculate the average values for the probability of errors. Plot the symbol-error rate P E versus the E b /N o ratio for both PSK-modulated sequence without convolutional encoding and PSK-modulated sequence with convolutional coding. Plot and compare with the theoretical limits. For a fair comparison, remember to convert symbol error rate to bit error rate or vice versa. Record your observations and any salient features that you may have observed in the Monte-Carlo simulations.