You are on page 1of 4

EE 333

COMMUNICATION AND DSP LABORATORY


Assignment 2
Name: Yash Kataria Roll Number: 210102100

Question 4. Error correction codes:

a. Construct a uniform random binary number of length N.


b. Divide the random numbers into block of 4 and for each block of 4 bits, encode
using Hamming code. Final length of the code will be 7N/4.
c. Modulate the above encoded message using BPSK and add AWGN of variance σ2
d. Perform BPSK detection and divide the resultant estimated message into block of
7 bits.
e. Perform Hamming decoding (Minimum weight decoding) and plot the BER.
Compare the BER vs SNR with the one plotted in previous assignment.

Solution - Here is the code, alongwith its explanation


A. Initialization:
N = 10000; specifies the number of bits to transmit.
sigma = 0.1; sets the variance of the Gaussian noise to simulate channel noise.

B. Generate Random Bits:


rand_bits = randi([0, 1], 1, N); generates an array of N random binary bits.
C. Encoding with Hamming Code:
encoded_bits = encodeHam(rand_bits); encodes the random bits using Hamming
coding.

D. Modulation:
modulated_signal = 1 - 2 * encoded_bits; maps the encoded bits to modulated signals.

E. Add Noise:
noise = sqrt(sigma) * randn(1, length(modulated_signal)); generates Gaussian noise.
received_signal = modulated_signal + noise; adds the noise to the modulated signal.

F. Demodulation:
detected_bits = received_signal < 0; demodulates the received signal.

G. Decoding:
decoded_bits = decodeHam(detected_bits); decodes the received bits using Hamming
decoding.

H. Compute Bit Error Rate (BER):


ber = sum(rand_bits ~= decoded_bits) / length(rand_bits); calculates the bit error
rate.

I. SNR Sweep:
The code then simulates the system over a range of signal-to-noise ratios (SNR).
For each SNR value, it repeats steps 5-7 and calculates the BER.
The BER values for different SNR levels are stored in the array ber.

J. Plotting:
semilogy(snr, ber); plots the BER against SNR in logarithmic scale.
Labels and titles are added to the plot.

K. Hamming Encoding and Decoding Functions:


encodeHam function encodes input bits using Hamming coding.
decodeHam function decodes received bits using Hamming decoding.
Comparison of the BER vs SNR plots of the 3rd and 4th question -

Clearly, the error reduces by a significant amount in question 4.

You might also like