You are on page 1of 7

DIGITAL COMMUNICATIONS LAB MANUALS

2012

LAB 1: HAMMING CODE


In this lab, we will utilize one error control code, known as the (7,4) Hamming block code. (7,4) means that 4 message bits, represented by the vector m, are converted into a 7-bit code, represented by the vector x = mG (modulo 2), where G is the "generator matrix" given by: 1 1 0 1 0 0 0 0 1 1 0 1 0 0 (1) G= 1 1 1 0 0 1 0 1 0 1 0 0 0 1 After the message bits pass through a noisy medium that introduces unknown errors, we can model the received vector y as follows:

y = x + e (modulo 2)

(2)

In modulo 2 addition we have 0 + 0 = 1 + 1 = 0; 0 + 1 = 1 + 0 = 1. Therefore we imagine the error vector e as a binary vector; where a component of e is 1, the received y vector diers from the originating x vector. The receiver then needs to decode the data in an attempt to recover the original message bits. This produces a "syndrome", s, which determines what the error vector was (if no errors or only a single bit error has occurred): s = yHT (modulo 2) where HT is the transpose of the "parity-check" matrix, H, given by: 1 0 0 1 0 1 1 H= 0 1 0 1 1 1 0 (4) 0 0 1 0 1 1 1 The 3-bit syndrome uniquely determines what the error pattern was, for single bit errors. So since we know what the error was, we can correct it and decrease the probability of a received bit error for the system! If the syndrome is perceived as a binary number, it can be converted to decimal and used as an index into the following error-pattern look-up matrix. The decimal value of the syndrome now points to the row of E that contains the corresponding error pattern.
E=

(3)

0 0 0 0 1 0 0 0

0 0 1 0 0 0 0 0

0 1 0 0 0 0 0 0

0 0 0 0 0 0 1 0

0 0 0 1 0 0 0 0

0 0 0 0 0 0 0 1

0 0 0 0 0 1 0 0

(5)

The (7,4) Hamming code is such that, when there is a single error in y, the row of E chosen with the syndrome matches the e used above to model the relationship between x and y. Therefore, given y, the decoding procedure is: y (corrected) = y + e (modulo 2) = x + e + e (modulo2) = x (6)

since addition modulo 2 of any binary vector to itself results in a vector of zeroes. 1

Assignment:
Write the following functions, using the Hamming code given above: A routine that takes a vector of four binary (0,1) symbols, and returns a vector of seven bits containing the corresponding valid codeword (encoding); A routine that takes a vector of seven bits, decodes them, and returns a vector of seven bits containing the decoded valid codeword (decoding). The routines should be properly commented, and example outputs should be given. Question: Why might some of the bits still be in error after coding and decoding with this (7,4) Hamming code? Explain.

LAB 2: MODULATION - DEMODULATION


We are ready to transmit the binary data (such as bytes on a computer) over a physical medium (such as an ethernet cable). In order to do so, a discrete-time sequence must be converted into a continuous-time signal for transmission. This is known as modulation. Then the modulated signal will be sent to the channel for transmitting. Figure 1 presents an example of a channel of transmission.

Figure 1: Channel of transmission.

Figure 2: BPSK.

In this lab, we will using BPSK - Binary phase-shift keying. BPSK (gure 2, also sometimes called PRK, Phase Reversal Keying, or 2PSK) is the simplest form of phase shift keying (PSK). It uses two phases which are separated by 180o and so can also be termed 2-PSK. This modulation is the most robust of all the PSKs since it takes the highest level of noise or distortion to make the demodulator reach an incorrect decision. It is, however, only able to modulate at 1 bit/symbol and so is unsuitable for high data-rate applications when bandwidth is limited.

Assignment:
Your task is to generate a sequence of 10000 bits in Matlab, modulate that sequence using BPSK, let the resulting signal to pass through the channel, where additive white Gaussian noise will be added. You will then receive a signal at the receiver end, demodulate it to recover another sequence. Check if this received sequence is the same at the original one? In order to accomplish this in our simulation, we must convert a sequence of 1s and 0s into a sequence of +1 and -1, and then multiply by A, which is the amplitude of the carrier. In the rst simulation we use only the single value A = 2, 1 in the nal simulation we use A = 0.5, 2 , 1, 2, 2, 2 2, 4 . You may want to use the function randn of Matlab in the processing of generating the original sequence. This function generates random numbers with zero mean and a Gaussian distribution of unit variance. With some others commands, you will get the 0s and 1s sequence. 3

As for the additive white Gaussian noise, again, you can using the previously mentioned randn function to generate a noise centering around zero and has a variance of 1 which tells us how much the random numbers vary about the mean. Thus in the zero mean case, as we have here, the variance is the mean square value of the noise. Once the signal arrives at the receiver, it must convert the continuous time signal back into a discrete one through an analog-to-digital conversion called demodulation or detection. We will use a simple threshold detector referred to as a slicer. Its threshold is 0V , so any signal above 0V will be interpreted as a 1 and any signal below 0V will be interpreted as a 0 (gure 3).

Figure 3: Demodulation. Since this is a simulation, we have the original data sequence and can compare the two received sequences to it to determine exactly how many errors occurred. This gives us an indication as to the probability of error for the particular signal energy per bit to noise power density ratio we were using. For each value of A E compute the SNR in dB, plot the probability of message bit error vs. Nb . 0

LAB 3: COMMUNICATION SYSTEM


A simple communication system is presented in gure 4.

Figure 4: Communication system. In the previvous sections you have already simulated the Channel Encoder & Channel Decoder; Modulation & Demodulation; as well as the Additive White Gaussian Noise. In this lab, you are required to put all of these blocks together to form this system of communication.

Assignment:
1. Your task is to generate a sequence of N bits in Matlab, modulate the uncoded sequence using BPSK (of amplitude A), let the resulting signal pass through the channel, where additive white Gaussian noise will be added. You will then receive a signal at the receiver end, demodulate it to recover a demodulated sequence. Check if this received sequence is the same at the original one? For each value of A and N compute the SNR in dB, plot the probability of message E bit error vs. Nb . This is the performance of your system without channel 0 coding. 2. Using the same sequence generated in the previous task, now you should code it using Hamming code before sending to the channel, then modulate the coded sequence using BPSK (of amplitude A), let the resulting continuous signal pass through the channel, where additive white Gaussian noise will be added. You will receive a noisy signal at the receiver end, demodulate it to recover a demodulated sequence. You will nally decode that sequence to obtain the receiving sequence. Check if this received sequence is the same at the original one? For each value of A and N compute the SNR in dB, plot the probability E of message bit error vs. Nb . This is the performance of your system with 0 channel coding (Hamming code). 3. Data:
1 The amplitude of BPSK modulation is A = 0.5, 2 , 1,

2, 2, 2 2, 4, 4 2 .

The number of bits is N = [20, 1000, 10000, 50000, 100000, 200000]. Check if the value of N has an eect on the probability of message bit error? Note: Since the simulation will take time, you are recommended to avoid wasting a lot of time by being sure that the rst simulation of N = 1000 is correct before proceeding with the array of N . 5

4. Discussion: Check if the value of N has an eect on the probability of message bit error? You should be able to see that the validity of the results depends on not only your choice of A, but also your data stream length. Why? Think about why a simulation with a choice of parameters that yield of no errors is not very useful (what is the error probability for those parameters? Is it valid?). How many bits would you need to simulate with to detect a probability of error of 107 ? Choosing a very long data stream may become computationally prohibitive. Comment on how closely your data matches the theoretical curves shown in gure 5 (for the "Uncoded BPSK" and "(7,4) Hamming"). In your conclusion, discuss how forward error control coding compares to simply raising the signal to noise ratio for a digital communication system. Be sure to mention power savings versus bandwidth.

Figure 5: Block code performance.

You might also like