0% found this document useful (0 votes)
17 views

EE3262 - Assignment 2

Uploaded by

Vindula Lakshani
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

EE3262 - Assignment 2

Uploaded by

Vindula Lakshani
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Department of Electrical and Electronic Engineering

Faculty of Engineering
University of Sri Jayewardenepura

Electrical and Electronic Engineering Laboratory

Course Data Communication and Networks

Course Code EE3262

Assignment Name Error Correcting Codes

Outcomes/Evaluation This assignment will evaluate the understanding of a particular type of


error correcting code, called a Hamming code.

1. Introduction

a. Briefly discuss the difference between hamming distance and hamming code.

b. What is the function of Binary Symmetric Channel (BSC) during transmission?

2. Encoding and decoding binary messages

a. Generate a random four bit word msg.


msg = randi([0 1], 1, 4)

b. Generate the codeword using a Hamming (7, 4) scheme.


codeword = encode(msg,7,4)

c. Decode the codeword using the same Hamming (7, 4) scheme.


received = decode(codeword, 7, 4)

d. Was the correct message recovered?

3. Introducing error bits


a. Create a new variable rxinput which we can use to represent the signal at the receiver
input, after passing through a BSC.
rxinput = codeword

b. Try simulating the effect of transmitting a codeword through a BSC with a


probability of 0.1 a few times using
rxinput = bsc(code, 0.1)

1
4. Processing sequences of data words
a. Define the number of words that need to be processed.
numwords = 5
msg = randi([0 1], numwords, 4)

b. Encode the words using Hamming (7, 4) scheme.

c. Introduce errors using BSC.

5. Running Simulations
a. Run the ‘Monte Carlo’ simulation for ‘numwords = [Your_Index_No] + 10’ for 3
times and export the generated plots.

b. Discuss the reasons the difference between obtained results in question a.

c. Run the simulation for 10 words, 100 words, and 100,000 words for a probability bit
error p of 0.1 and export the generated plots.

d. Explain the relationship between the histograms and the number of uncorrected
errors.

e. Try running the simulation with a probability of error p = 0.01. Comment on the
results.

Note:
You have to submit the assignment as a compressed folder which consist of your
assignment report and .m files on or before the due date. All the files should be named as
ENG_XXX_A02 [XXX-Your Index NO].
The report should follow the standard formatting and be well organized with the content.
[Font-Times New Roman, Font size-12, Line spacing-1.5, Alignment-Justify]
All the reports should have the same format for cover page.
Plagiarism will not be tolerated.
Due date will be announced by the Module coordinator and will not be changed for any
reason.

2
Appendix 1 - .m file for Hamming code simulation
n = 7; %Length of the words after coding
k = 4; %Number of message bits
numwords = 10; %The number of words to be encoded and decoded
p = 0.1; %Probability of bit error in the BSC

msg = randi([0 1], numwords, k); %Generate the random data


codeword = encode(msg, n, k); %Encode the data
rxinput = bsc(codeword, p); %Simulate the BSC
rxdecode = decode(rxinput, n, k); %Decode the received signal

% Compare the transmitted data before coding and the received data
% after decoding to see where errors have occurred

erroredbits = mod(msg+rxdecode, 2);


errsperword = sum(erroredbits, 2); %Add up the errors in each word

% The array errsperword contains the number of errors in each word sent.
% In this case we are interested in whether the word is decoded correctly,
% not how many errors it has, so we want to count up the number of words
% with one or more errors:
numwitherr = length(find(errsperword));

% Look at the statistics of errors introduced by the BSC


erroredbits_before_decode = mod(codeword + rxinput, 2); %Find bit errors
errsperword_before_decode = sum(erroredbits_before_decode, 2);

figure; %Create a new figure


color = [0.5 0.1 0.6]; %RGB values for a nice deep purple
K = histc(errsperword_before_decode, 0:1:n); %Calculate the histogram
bar(0:1:n,K,0.9); %Plot the histogram
xlabel('Number of errors');
ylabel('Frequency');
grid on;

h = findobj(gca,'Type','patch'); %Find the histogram area (default blue)


set(h,'FaceColor',color,'EdgeColor','w') %Set the histogram to color

m = max(K); %Find the max value in K (used to position labels)


for count = 1:(n+1) %Add data labels to the plot
if K(count) > m*0.1 %This value is bigger than 10% of the max
%Add white text slightly inside the bar
text(count-1,K(count)-m*0.06,sprintf('%d',K(count)), ...
'HorizontalAlignment','center', ...
'Color', [1 1 1], ...
'EdgeColor', [1 1 1]);

else %This value is less than 10% of the max


%Add color text slightly outside the bar
text(count-1,K(count)+m*0.06,sprintf('%d',K(count)), ...
'HorizontalAlignment','center', ...
'Color', color, ...
'EdgeColor', color, ...
'BackgroundColor', [1 1 1]);
end
end

You might also like