Professional Documents
Culture Documents
Bachelor of Technology
in
Electronics and Communication Engineering
by
Course Coordinator
Dr. Aakash Gupta
October 2020
Copyright
c The LNMIIT 2020
All Rights Reserved
Contents
Chapter Page
1 Experiment - 7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Aim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Hardware used . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3.1 (7, 4) Hamming Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3.2 Hard Decision Decoder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3.2.1 Find codeword closest in Hamming distance . . . . . . . . . . . . . 3
1.3.3 Soft Decision Decoder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3.3.1 Find codeword closest in Euclidean distance . . . . . . . . . . . . . 3
1.4 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4.1 Code for BER vs SNR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4.2 Codeword Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.5 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
iii
Chapter 1
Experiment - 7
1.1 Aim
1. To perform encoding and decoding for a (7, 4) Hamming code.
1.3 Theory
The Hamming code is a single error correction linear block code with (n, k) = (2m −1, 2m −1−m),
where m = n − k is the number of check bits in the codeword. The simplest non-trivial code is for
m = 3, which is the (7, 4) Hamming code.
The generator matrix of the Hamming code has dimension k × n and is of the form
G = [Ik×k S]
For this Hamming code, S has one row for each possible m− bit string with weight at least 2. There
are exactly k = 2m − m − 1 such strings. Any Hamming code is a 1-error correcting code as the two
conditions above are satisfied. The (7, 4) Hamming code is given by the generating matrix:
1 0 0 0 1 0 1
0 1 0 0 1 1 1
G= 0 0 1 0 1 1 0
0 0 0 1 0 1 1
1
1.3.1 (7, 4) Hamming Code
2
1.3.2.1 Find codeword closest in Hamming distance
3
1.4 Results
1.4.1 Code for BER vs SNR
clc;
clear all;
close all;
%18uec065
C = mod(d*G,2);
EBNdb=[0,1,2,3,4,5,6,7];
BER_hardm=[];
BER_softm=[];
for EbNdb = 0:7
R = 4/7;
EbN = 10^(EbNdb/10);
sigma = sqrt(1/(2*R*EbN));
k=4;
n=7;
nerr_hard = 0; nblocks = 10000; err_hard = 0;
nerr_soft = 0; err_soft = 0;
for i=1:nblocks
msg = randi([0,1], 1,k);
cword = [msg mod(msg(1) + msg(2) + msg(3),2) mod(msg(2) +
msg(3) + msg(4),2) mod(msg(1) + msg(2) + msg(4),2)];
noise = sigma*randn(1, n);
% bpsk
tx = 2*cword-1;
rx = tx+noise;
% hard decisions
% soft decisions
corr = (2*C-1)*rx';
[min2,pos] = max(corr);
msg_soft = C(pos,1:4);
err_soft = sum(msg~=msg_soft);
err_hard = sum(msg~=msg_hard);
nerr_hard = nerr_hard + err_hard;
nerr_soft = nerr_soft + err_soft;
end
4
BER_hard = nerr_hard/k/nblocks;
BER_soft = nerr_soft/k/nblocks;
BER_softm = [BER_softm BER_soft];
end
semilogy(EBNdb, BER_hardm);
hold on
semilogy(EBNdb, BER_softm);
title('BER curve for (7,4) Hamming Code - (18UEC065 - Shaan Gupta)')
5
2
1.4.2 Codeword Table
1.5 Conclusion
In this experiment we are able to study the hamming code, hard decision and soft decision decoder
and finally after plotting the graph between BER for different value of SER (like: 1dB, 2dB, 3dB, 4dB),
we conclude that Soft Decision Decoder performs better than the Hard Decision Decoder because it
does not have the threshold step involved in it as in the Hard Decision Decoder.