SlideShare a Scribd company logo
1 of 31
Wireless Communications
Forward Bit Error Correction
Final Project Report
Surya Sekhar Chandra
Electrical Engineering
Colorado School Of Mines
1 Abstract
This project aims to investigate the applications and effectiveness of different types of for-
ward error detecting and correcting techniques. The topics explored in the project include
error detecting techniques, such as, vertical redundancy check and cyclic redundancy check
(checksum), and error correcting techniques, such as, Hamming 7,4 coding. Each topic is
explored with an example implementation with signals affected by Gaussian noise and burst
errors. It is then shown how interleaving can provide robustness against burst errors. The
project concludes with an overview of convolutional coding and decoding methods.
2 Implementation
An image is selected and broken down into its grayscale values. Each grayscale value is
converted to an 8-bit binary. All the values are converted to a bit stream and sent for
encoding and then transmitted through a noisy channel.
Fig. 1: Implementation process - converting an image into a bit stream
Figure 1 shows the process of obtaining a bit stream from an image. Noise in the channel
is added to the encoded bit stream in the form of Gaussian noise or burst errors in Matlab.
The received signal(bit stream) is decoded and matched with transmitted signal to calculate
the percentage of errors detected. For a better visualization of the effectiveness of each
technique, the corrected bit stream is reconstructed and compared with the uncorrected bit
stream.
1
3 Parity bit (VRC)
Parity bit or vertical redundancy check is an error detecting technique. In this method, for
a given set of symbols (8-bit in this case), an extra bit is added at the end of the symbol to
make the sum of all the bits in the symbol either a 0 or 1 (even or odd parity). When the set
of symbols passes through a noisy channel and reaches the receiver, errors can be checked
for by simply doing the modulo 2 sum of all of the bits in the symbol. If the sum does not
match the parity scheme, then at least one error has occurred in the symbol. This method is
relatively limited, as it cannot detect an even number of errors in a symbol. A Matlab script
was created to show the effectiveness of parity scheme in error detection. The program took
an input signal (a vectorized version of the cameraman.tif image), added parity bits, and
then applied white Gaussian noise to the signal. The number of parity detected bit errors
vs. the actual number of errors is shown below in Figure 2.
Fig. 2: Parity error detection
The results show that adding a parity bit can be a useful tool for detecting relatively
sparse Gaussian noise, however this method breaks down relatively quickly at higher noise
levels for a gaussian noise.
2
4 Checksum (CRC)
Checksum is a type of cyclic redundancy check used for bit error detection. In this method,
an extra symbol (8-bits in this case) called checksum is added after every two symbols (16
bits), such that the binary sum of the three symbols is a zero. If at the sum at receiving end
is found to be different from a zero, then an error must have occurred during the transmission
through the channel. This method is more robust compared to VRC because it has a very
low probability of occurrence of an undetected error.
Fig. 3: An example of error detection using checksum
Figure 3 shows the step by step procedure of encoding and decoding a data using check-
sum method. Encoded data encounters a noise while passing through the channel and this
causes some of the bits to flip during transmission. At the receiver end, data is accepted or
rejected based on the value of the summation. As shown in check2, even though there are
two bit errors the result of summation is still zero and the data is accepted. This is a case
of false error detection using CRC.
3
Fig. 4: CRC error detection for AWGN Fig. 5: CRC error detection for burst error
As it is evident from Figure 4, the performance of error detection using this method
is better than the vertical redundancy check technique, even for a higher Gaussian noise
variance. This technique was then applied with a burst error (multiple bit errors occurring
simultaneously within a period of time) in the channel and the performance of error detection
was observed to be much better even for high variance of burst error occurrence as seen in
Figure 5
5 Hamming 7,4 coding
Block codes are one of the two main classes of FEC codes. They take an input of k charac-
ters and output n characters. Thus block codes utilize 2k out of 2n possible codewords, the
unused codewords allow the code to have a certain hamming distance for error correction.
The encoding of each length n block is completely independent of other blocks that have
been previously encoded. This means that the block encoders are memory-less devices. The
ability to look at each block separately greatly simplifies the decoding process.
Hamming 7,4 is an extension of the idea of parity, instead of just detecting one bit error
per symbol, this code (with a Hamming distance of 3) is able to correct one bit error per 4
bit symbol. This class has focused on the method in which the Hamming 7,4 encoding and
decoding functions, thus this project will focus more on demonstrating its error correcting
abilities.
4
Fig. 6: Steps involved in hamming 7,4 Fig. 7: Hamming 7,4 parity diagram
This method involves adding three parity bits to every four bits of data. Each of these
partiy bits forms an even parity with three of the four bits as shown in Figures 6 and 7. The
first test of this code is to see how it preforms in correcting AWGN at different noise variance
levels. To test this, the input signal is again a vectorized version of the ’cameraman.tif’ image.
The signal is encoded, AWGN is added, and then the signal is reconstructed and compared
to the original image. The result of this test is shown below in Figure 8.
Fig. 8: Error correction using Hamming 7-4 coding for AWGN
5
The results show that Hamming 7,4 performs well in low noise environments. A link to the
video simulation showing the same is given below with Figure 9.
Fig. 9: Hamming awgn correction video simulation
Click on the image or go to https://youtu.be/ppSRTn3GK5I
Next step is to see how well hamming 7,4 performs when attempting to correct burst errors.
This test follows the same outline as above, but adds burst errors to the signal instead of
AWNG. The results are shown below in Figure 10
Fig. 10: Error correction using Hamming 7-4 coding for burst error
6
Fig. 11: Hamming burst error correction video simulation
Click on the image or go to https://youtu.be/0FImOsM2zeQ
As it can be seen in the video, there is no correction for even for a low level of burst
noise occurrence. The bit error rate stays the same even after the correction. Hamming 7,4
code is clearly not suited to correct burst errors, as there are almost always multiple errors
occurring per symbol. This problem can be remedied using the concept of interleaving.
6 Interleaving
Interleaving is a separate process that can be applied to encoded data before it is passed
through a noisy channel. The idea is to somehow scramble the data (there are numerous
ways of doing this) before putting it through the noisy channel and then unscramble the
data before decoding. This unscrambling of the data after it passes through the channel
has the effect of scrambling the noise that the data was subject to in the channel. This can
aide greatly in in the ability of block codes to decode burst errors. A simple example of
interleaving using a shifting operation is illustrated below in Figure 12. The colored columns
represent 7-bit symbols (including the parity bits) that are transmitted.
Since interleaving ’smears out’ burst errors, it is useful in correcting them with block
encoding. This kind of interleaving was added to the Hamming 7,4 encoding process. Each
column of the data is shifted by a specific amount before transmission and then shifted back
after it is received. The results of this process are shown on the next page in Figure 13.
7
Fig. 12: Interleaving process for block codes
Fig. 13: Error correction for hamming 7,4 burst errors using interleaving
8
Fig. 14: Hamming + interleave burst error correction video simulation
Click on the image or go to https://youtu.be/jrUhW_5C4Sw
From the graph (Figure 13) and the video (Figure 14), it is obvious that interleaving restores
the error correcting ability of the Hamming 7,4 code when exposed to burst errors. Note
that the noise variance in this case refers to the Gaussian distribution of the noise errors.
The error increases at a faster rate with the variance because multiple bit errors occur at
every error occurrence.
7 Convolutional coding
Convolutional coding methods still involves generating a set of parity bits from an set of
input bits. However, rather than calculating these parity bits through a matrix multipli-
cation with a single block of data at a time, convolutional coding schemes create parity
bits progressively as the input is shifted into the encoder. Sliding the input stream past an
encoding function and preforming a convolution (XOR operations on current and previous
bits) at each step produces the parity bits. This operation can be modeled as a shift register
as shown below in Figure 15. x[n] is the input, and p1[n] and p2[n] are the output parity bits.
While convolutionally encoding data is relatively simple, decoding the data can be much
more challenging. Considering the case of no errors in the received data, the decoder can
simply follow a trellis diagram, as shown in Figure 16. The correct path through the trellis is
mapped by the parity bits and the states of the code (in this case, the states are the previous
two input bits). Once this path is found, the original data bits are recovered by looking at
the state transitions. In this case, there are only two possible transitions from one state to
the next, representing either a one or zero.
If we introduce errors into the convolutionally encoded data, then it becomes far more
complex decode, as there is now no correct path through the trellis! One strategy for re-
9
covering the data could be to follow every path in the trellis and then sum the accumulated
error along each path and pick the path with the least error. However this is not practical
Fig. 15: Convolutional coding shift register model
since an algorithm would run forever to do this computation. A realistic approach would be
to guess at the next state based on the current state, and the probability of the transition
between states. In this way the algorithm is outputting the ’most likely’ path through the
trellis. Errors are corrected by maximizing the probability that the correct path was chosen.
Fig. 16: Trellis diagram for convolutional encoding and decoding
One widely used method that is used to preform this kind of analysis is the Viterbi
algorithm. It looks at a subset of the trellis and eliminates the least likely paths in order to
greatly reduce the complexity of finding the most probable path.
8 Conclusion
In the real world, bit errors occurrence for the data transmitted cannot be avoided. Forward
error correction is an invaluable tool for a reliable transmission of data across such a noisy
10
channel. It allows for a trade off between the data rate and the bit error rate. This project
demonstrated the functionality of Hamming codes under different noise conditions, as well
as discussing the difference between block and convolutional coding methods. Since virtu-
ally all forms of wireless communication involve noise, FEC is an invaluable for improving
performance and reliability.
11
Appendix
MATLAB Code:
%% PARITY MAIN PROGRAM
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
close all
clc
%% To Generate New Data
% bit_length = 8;
% T = im2bits(imread('cameraman.tif'),bit_length);
% save T
% LOADING GENERATED DATA
load('T.mat','T'); % T.bits contains columns of binary bits
%% Adding the parity bit
% To add parity bit at the end of each column in T_image.bits
% Specify even or odd parity
T.pbits = parity_add(T.bits,'even');
%% Adding awgn noise to data
noise_sigma_max = 0.5;
samples = 100;
sigma = linspace(0,noise_sigma_max,samples);
for i=1:size(sigma,2)
% Adding Noise for given sigma
[R(i).pbits] = add_awgn(T.pbits, sigma(i), 2);
% Find Bit Errors
Err(i) = find_errors(T.pbits,R(i).pbits);
BER_actual(i) = Err(i).BER_actual;
BER_actual_w(i) = Err(i).BER_actual_words;
undetected(i) = sum(Err(i).symbol(find(Err(i).symbol == 2 | ...
Err(i).symbol == 4 | Err(i).symbol == 6 | Err(i).symbol == 8)));
undetected_w(i) = size(Err(i).symbol(find(Err(i).symbol == 2 | ...
12
Err(i).symbol == 4 | Err(i).symbol == 6 | Err(i).symbol == 8)),2);
parity_error(i) = 100*(undetected(i)/prod(size(R(i).pbits)));
parity_error_w(i) = 100*(undetected_w(i)/(size(R(i).pbits,2)));
parity_estimated_BER(i) = BER_actual(i) − parity_error(i);
parity_estimated_BER_w(i) = BER_actual_w(i) − parity_error_w(i);
end
%% PLOT AND LABELS
figure(1)
plot(sigma,BER_actual,'b','LineWidth',2);
hold on
plot(sigma,parity_estimated_BER,'g','LineWidth',2);
plot(sigma,parity_error,'−−r','LineWidth',2);
title('bf PARITY SCHEME : NOISE VARIANCE VS BER','FontSize',18);
xlabel('bf Noise Standard deviation ( sigma )','FontSize',16);
ylabel('bf BER ','FontSize',16);
h = legend('Actual BER','Parity estimated BER','Parity undetected',...
'Location','NorthWest');
set(h,'FontSize',16);
hold off
figure(2)
plot(sigma,BER_actual_w,'b','LineWidth',2);
hold on
plot(sigma,parity_estimated_BER_w,'g','LineWidth',2);
plot(sigma,parity_error_w,'−−r','LineWidth',2);
title('bf PARITY SCHEME : NOISE VARIANCE VS BER − Symbols','FontSize',18);
xlabel('bf Noise Standard deviation ( sigma )','FontSize',16);
ylabel('bf BER ','FontSize',16);
h = legend('Actual BER (Symbol)','Parity estimated BER',...
'Parity undetected','Location','NorthWest');
set(h,'FontSize',16);
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% CRC_Checksum
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
close all
clc
13
%% To Generate New Data
% bit_length = 8;
% T = im2bits(imread('cameraman.tif'),bit_length);
% save T
% LOADING GENERATED DATA
load('T.mat','T'); % T.bits contains columns of binary bits
%% Appending a 8bit Checksum for every 16 bits
% To add checksum as a new column in T_image.bits
[T.pbits, S] = checksum_add(T.bits);
%% Adding awgn noise to data
noise_sigma_max = 0.5;
samples = 100;
sigma = linspace(0,noise_sigma_max,samples);
for i=1:size(sigma,2)
% Adding Noise for given sigma
[R(i).pbits] = add_awgn(T.pbits, sigma(i), 2);
% Find Bit Errors
Err(i) = find_errors_crc(T.pbits,R(i).pbits);
BER_actual(i) = Err(i).BER_CRC;
[summed, t_error, BER_detected(i)] = checksum_check(R(i).pbits);
disp(i);
end
%% PLOT AND LABELS
figure(1)
plot(sigma,BER_actual,'b','LineWidth',2);
hold on
plot(sigma,BER_detected,'g','LineWidth',2);
title('bf CRC−CHECKSUM : NOISE VARIANCE VS BER','FontSize',18);
xlabel('bf Noise Standard deviation ( sigma )','FontSize',16);
ylabel('bf BER−symbols(16bits) ','FontSize',16);
h = legend('Actual BER','CRC Detected BER',...
'Location','NorthWest');
set(h,'FontSize',16);
14
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% CRC_Checksum_burst_noise
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
close all
clc
%% To Generate New Data
% bit_length = 8;
% T = im2bits(imread('cameraman.tif'),bit_length);
% save T
% LOADING GENERATED DATA
load('T.mat','T'); % T.bits contains columns of binary bits
%% Appending a 8bit Checksum for every 16 bits
% To add checksum as a new column in T_image.bits
[T.pbits, S] = checksum_add(T.bits);
%% Adding awgn noise to data
noise_sigma_max = 0.35;
samples = 100;
sigma = linspace(0,noise_sigma_max,samples);
for i=1:size(sigma,2)
% Adding Noise for given sigma
[R(i).pbits] = burst_add(T.pbits, sigma(i));
% Find Bit Errors
Err(i) = find_errors_crc(T.pbits,R(i).pbits);
BER_actual(i) = Err(i).BER_CRC;
[summed, t_error, BER_crc ] = checksum_check(R(i).pbits);
BER_detected(i) = BER_crc;
15
disp(i);
end
%% PLOT AND LABELS
figure(1)
plot(sigma,BER_actual,'b','LineWidth',2);
hold on
plot(sigma,BER_detected,'g','LineWidth',2);
title('bf CRC−CHECKSUM : BURST NOISE VARIANCE VS BER','FontSize',18);
xlabel('bf Noise Standard deviation ( sigma )','FontSize',16);
ylabel('bf BER−symbols(16bits) ','FontSize',16);
h = legend('Actual BER','CRC Detected BER',...
'Location','NorthWest');
set(h,'FontSize',16);
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Hamming Main Program
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
close all
clc
%% To Generate New Data
% bit_length = 8;
% T = im2bits(imread('cameraman.tif'),bit_length);
% save T
% LOADING GENERATED DATA
load('T.mat','T'); % T.bits contains columns of binary bits
bits = T.bits;
% Encode
HE = Hamming_encode(bits);
%% Add awgn error
noise_sigma_max = 0.35;
samples = 100;
sigma = linspace(0,noise_sigma_max,samples);
16
% Looping through the noise
for i=1:size(sigma,2)
% Adding Noise for given sigma
HEN(i).Tbits = add_awgn(HE.Tbits, sigma(i), 2);
R(i) = Hamming_decode(HEN(i).Tbits);
sigma(i)
% Find Bit Errors
Err(i) = find_errors(HE.Tbits,R(i).Rbits);
BER_actual(i) = Err(i).BER_actual;
Err_after_corr(i) = find_errors(HE.Tbits,R(i).Corr_bits);
BER_after_corr(i) = Err_after_corr(i).BER_actual;
BER_corrected(i) = BER_actual(i) − BER_after_corr(i);
end
%% PLOT AND LABELS
figure(1)
plot(sigma,BER_actual,'b','LineWidth',2);
hold on
plot(sigma,BER_after_corr,'−−r','LineWidth',2);
title('bf HAMMING 7,4 SCHEME : NOISE VARIANCE VS BER','FontSize',18);
xlabel('bf Noise Standard deviation ( sigma )','FontSize',16);
ylabel('bf BER ','FontSize',16);
h = legend('Actual BER','BER after Hamming correction',...
'Location','NorthWest');
set(h,'FontSize',16);
hold off
%% Reconstruct
vidObj = VideoWriter('Simulation.avi');
vidObj.FrameRate = 6;
open(vidObj);
for l = 1:100
% Plotting the image after the bit correction by hamming code
R_bits = Reconstruct_Hbits(R(l).Corr_bits);
BIT_STREAM=((R_bits));
Im = bits2im(BIT_STREAM,[256 256]);
hFig = figure(2);
set(hFig, 'Position', [150 150 1000 600])
subplot(1,2,2)
17
imshow(Im.image,[]);
title('bf Image after Hamming correction','FontSize',16);
% plotting the image before the correction by hamming code
E_bits = Reconstruct_Hbits(HEN(l).Tbits);
BIT_STREAM=((E_bits));
Im2 = bits2im(BIT_STREAM,[256 256]);
subplot(1,2,1)
title_string = sprintf('Noisy image before correction, Sigma = %f',...
sigma(l));
imshow(Im2.image,[]);
tt=title(title_string ,'FontSize',16);
set(tt,'FontWeight','bold');
currFrame = getframe(hFig);
writeVideo(vidObj,currFrame);
end
close(hFig);
close(vidObj);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Hamming With Burst Noise Main Program
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
close all
clc
%% To Generate New Data
% bit_length = 8;
% T = im2bits(imread('cameraman.tif'),bit_length);
% save T
% LOADING GENERATED DATA
load('T.mat','T'); % T.bits contains columns of binary bits
bits = T.bits;
HE = Hamming_encode(bits);
%% Add burst error
noise_sigma_max = 0.3;
samples = 100;
% chance of burst
sigma = linspace(0,noise_sigma_max,samples);
18
% Looping through the noise
for i=1:size(sigma,2)
% Adding Noise for given sigma
HEN(i).Tbits = burst_add(HE.Tbits,sigma(i));
R(i) = Hamming_decode(HEN(i).Tbits);
sigma(i)
% Find Bit Errors
Err(i) = find_errors(HE.Tbits,R(i).Rbits);
BER_actual(i) = Err(i).BER_actual;
Err_after_corr(i) = find_errors(HE.Tbits,R(i).Corr_bits);
BER_after_corr(i) = Err_after_corr(i).BER_actual;
BER_corrected(i) = BER_actual(i) − BER_after_corr(i);
end
%% PLOT AND LABELS
figure(1)
plot(sigma,BER_actual,'b','LineWidth',2);
hold on
plot(sigma,BER_after_corr,'−−r','LineWidth',2);
title('bf HAMMING 7,4 SCHEME : BURST NOISE VARIANCE VS BER',...
'FontSize',18);
xlabel('bf Noise Standard deviation ( sigma )','FontSize',16);
ylabel('bf BER ','FontSize',16);
h = legend('Actual BER','BER after Hamming correction',...
'Location','NorthWest');
set(h,'FontSize',16);
hold off
%% Reconstruct
vidObj = VideoWriter('Hamming_Burst_Simulation.avi');
vidObj.FrameRate = 6;
open(vidObj);
for l = 1:100
% Plotting the image after the bit correction by hamming code
R_bits = Reconstruct_Hbits(R(l).Corr_bits);
BIT_STREAM=((R_bits));
Im = bits2im(BIT_STREAM,[256 256]);
hFig = figure(2);
19
set(hFig, 'Position', [150 150 1000 600])
subplot(1,2,2)
imshow(Im.image,[]);
title('bf Image after Hamming correction','FontSize',16);
% plotting the image before the correction by hamming code
E_bits = Reconstruct_Hbits(HEN(l).Tbits);
BIT_STREAM=((E_bits));
Im2 = bits2im(BIT_STREAM,[256 256]);
subplot(1,2,1)
title_string = sprintf('Noisy image before correction, Sigma = %f'...
,sigma(l));
imshow(Im2.image,[]);
tt=title(title_string ,'FontSize',16);
set(tt,'FontWeight','bold');
currFrame = getframe(hFig);
writeVideo(vidObj,currFrame);
end
close(hFig);
close(vidObj);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Hamming + Interleave Burst Noise Main Program
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
close all
clc
%% To Generate New Data
% bit_length = 8;
% T = im2bits(imread('cameraman.tif'),bit_length);
% save T
% LOADING GENERATED DATA
load('T.mat','T'); % T.bits contains columns of binary bits
bits = T.bits;
HE = Hamming_encode(bits);
%% Add burst error
noise_sigma_max = 0.35;
samples = 100;
20
% chance of burst
sigma = linspace(0,noise_sigma_max,samples);
% BACKUP OF BITS BEFORE INTERLEAVING
HE.before_Tbits = HE.Tbits;
% INTERLEAVING
for zz = 1 : 7
HE.Tbits(zz,:) = circshift(HE.Tbits(zz,:)',20*zz)';
end
% Looping through the noise
for i=1:size(sigma,2)
% Adding Noise for given sigma
HEN(i).Tbits = burst_add(HE.Tbits,sigma(i));
% DE−INTERLEAVING
for zz = 1 : 7
HEN(i).Rbits(zz,:) = circshift(HEN(i).Tbits(zz,:)',−20*zz)';
end
R(i) = Hamming_decode(HEN(i).Rbits);
sigma(i)
% Find Bit Errors
Err(i) = find_errors(HE.before_Tbits,R(i).Rbits);
BER_actual(i) = Err(i).BER_actual;
Err_after_corr(i) = find_errors(HE.before_Tbits,R(i).Corr_bits);
BER_after_corr(i) = Err_after_corr(i).BER_actual;
BER_corrected(i) = BER_actual(i) − BER_after_corr(i);
end
%% PLOT AND LABELS
figure(1)
plot(sigma,BER_actual,'b','LineWidth',2);
hold on
plot(sigma,BER_after_corr,'−−r','LineWidth',2);
title('bf HAMMING 7,4 : BURST−INTERLEAVE NOISE VS BER','FontSize',18);
xlabel('bf Noise Standard deviation ( sigma )','FontSize',16);
ylabel('bf BER ','FontSize',16);
h = legend('Actual BER','BER after Hamming correction',...
'Location','NorthWest');
set(h,'FontSize',16);
hold off
%% Reconstruct
21
vidObj = VideoWriter('Hamming_Burst_Interleave_Simulation.avi');
vidObj.FrameRate = 6;
open(vidObj);
for l = 1:100
% Plotting the image after the bit correction by hamming code
R_bits = Reconstruct_Hbits(R(l).Corr_bits);
BIT_STREAM=((R_bits));
Im = bits2im(BIT_STREAM,[256 256]);
hFig = figure(2);
set(hFig, 'Position', [150 150 1000 600])
subplot(1,2,2)
imshow(Im.image,[]);
title('bf Image after Hamming correction','FontSize',16);
% plotting the image before the correction by hamming code
E_bits = Reconstruct_Hbits(HEN(l).Rbits);
BIT_STREAM=((E_bits));
Im2 = bits2im(BIT_STREAM,[256 256]);
subplot(1,2,1)
title_string = sprintf('Noisy image before correction, Sigma = %f'...
,sigma(l));
imshow(Im2.image,[]);
tt=title(title_string ,'FontSize',16);
set(tt,'FontWeight','bold');
currFrame = getframe(hFig);
writeVideo(vidObj,currFrame);
end
close(hFig);
close(vidObj);
22
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%
%% FUNCTIONS USED
%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% ADDS A PARITY BIT ACCORDING TO THE SPECIFIED SCHEME ( EVEN OR ODD )
function pbits = parity_add(bits,str)
% Remainder vector for each column after dividing sum of the column by 2
R = mod(sum(bits),2);
% Deciding the remainder based on the parity scheme
if( strcmpi('even',str) )
pbits = [bits;R];
else
pbits = [bits;~R]; % default is odd parity scheme
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% IMAGE TO BITS
function T_Im = im2bits(I,bit_length)
I = double(I);
T_Im.size = size(I);
Im = I(:);
% BITS IN THE FORM OF CHARACTERS
T_Im.bits_char = dec2bin(Im,bit_length);
% CONVERTING CHARACTERS TO NUMBERS
for j = 1:size(T_Im.bits_char,1)
for i=1:bit_length
T_Im.bits(i,j) = str2num(T_Im.bits_char(j,i));
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23
%% FUNCTION TO CONVERT THE RECEIVED BIT STREAM BACK TO ORIGINAL IMAGE
% NOTE : BITS MUST BE A ROW VECTOR OF BINARY(0 or 1) IN CHAR DATATYPE
function [R_Image] = bits2im(Bits,Image_size)
bit_length = 8; % Image values go for 0−255
% Converting to a column vector of values
for i=1:size(Bits,2)
R_Image.bit_values(1,i) = 0;
for j=1:8
R_Image.bit_values(1,i) = R_Image.bit_values(1,i)+ ...
(Bits(j,i)*2^(8−j));
end
end
% Reshaping to the orginal image size
R_Image.image = reshape((R_Image.bit_values),Image_size);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ADDS ADDITIVE WHITE GAUSSIAN NOISE
% CHOOSE A SCHEME (1|2)
function [Rpbits] = add_awgn(pbits, sigma, scheme)
%% SCHEME 1 : Defining pbits from −1 to +1 instead of 0 to 1
if(scheme == 1)
temp_pbits = 2*pbits − ones(size(pbits));
temp_Rpbits = temp_pbits + sigma*randn(size(pbits));
Rpbits = zeros(size(temp_Rpbits));
Rpbits(find(temp_Rpbits>0)) = 1;
end
%% SCHEME 2 : Letting pbits from 0 to 1
if(scheme == 2)
temp_Rpbits = pbits + sigma * randn(size(pbits));
temp_Rpbits(find(temp_Rpbits>1)) = 1;
temp_Rpbits(find(temp_Rpbits<0)) = 0;
temp_Rpbits = round(temp_Rpbits);
Rpbits = temp_Rpbits;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24
% ADDS A BURST NOISE TO A GIVEN DATA MATRIX
function b_data = burst_add(bits_matrix, sigma)
burst_min = 3;
burst_max = 10;
Msize = size(bits_matrix);
bits = bits_matrix(:); % converting to a bit stream
% Random locations to add burst
b_prob = sigma * randn(size(bits,1)−burst_max−burst_min,1);
b_prob(b_prob<0) = 0;
b_prob(b_prob>1) = 1;
b_prob = round(b_prob);
sigma2 = 0.5;
%Choosing a random length for burst in the min and max range
length(b_prob==1) = randi(burst_max − (burst_min −1),...
size(b_prob(b_prob==1),1),1 ) ...
+ ones(size(b_prob(b_prob==1),1),1) *burst_min − 1;
for i=1:size(b_prob,1)
if(b_prob(i) == 1)
% If only few errors occurs in that burst, sigma =0.5
error = sigma2 + randn(length(i),1);
error(error<0) = 0;
error(error>1) = 1;
error = round(error);
% adding error to the bitstream
bits(i:i+length(i)−1,1) = bits(i:i+length(i)−1,1) + error;
end
end
% Getting the bits to binary
bits = mod(bits,2);
% Reshaping the bits back to its intial matrix form
b_data = reshape(bits,Msize);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25
%% FIND THE BIT ERRORS BETWEEN TRANSMITTED AND RECEIVED BITS
function Error = find_errors(T,R)
Error.diff = abs(T − R);
Error.symbol = sum(Error.diff);
Error.total = sum(Error.symbol(:));
Error.total_words = size(find(Error.symbol>0),2);
Error.BER_actual = 100*(Error.total/prod(size(T)));
Error.BER_actual_words = 100*(Error.total_words/(size(T,2)));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% ADDS A 8−BIT CHECKSUM FOR EVERY 16 BITS
function [pbits, summed] = checksum_add(bits)
% Matirx size of the input bits
rows = size(bits,1);
cols = size(bits,2);
% Converting all bits to decimals
D = bits2im(bits,[1 cols]);
Dec = D.image;
% Summing adjacent columns to create a sum matrix
sum = Dec(1:2:cols) + Dec(2:2:cols);
% Restricting values to be 8bit
sum = mod(sum,256);
% Converting sum back to decimals
sum = im2bits(sum,8);
% Flipping all the bits
summed = ~sum.bits;
% Adding that sum column next to every two columns
for i=1:1:size(summed,2)
pbits(:,(3*i)−2:3*i) = [bits(:,(2*i)−1:2*i) summed(:,i)];
end
26
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% VERIFY THE CHECKSUM TO DETERMINE BIT ERRORS
% Returns the checksum rows
% If all of which are zero, implies no bit errors
function [summed, total_errors, BER_crc] = checksum_check(bits)
% Matrix size of the input bits
rows = size(bits,1);
cols = size(bits,2);
% Converting all bits to decimals
D = bits2im(bits,[1 cols]);
Dec = D.image;
% Summing and checking for all zeors
summed = Dec(1,1:3:cols) + Dec(1,2:3:cols) + Dec(1,3:3:cols);
summed = mod(summed,256);
summed = mod(summed,255);
% Finding the non−zero elements and classifying them as errors
total_errors = size(summed(summed~=0),2);
% BER For each 16 bit symbol
BER_crc = 100*(total_errors/size(summed,2));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% FIND THE BIT ERRORS BETWEEN TRANSMITTED AND RECEIVED BITS
function Error = find_errors(T,R)
Error.diff = abs(T − R);
Error.symbol = sum(Error.diff);
Error.symbol2 = Error.symbol(1:3:size(Error.symbol,2)) + ...
Error.symbol(2:3:size(Error.symbol,2)) + ...
Error.symbol(3:3:size(Error.symbol,2));
Error.total = sum(Error.symbol(:));
Error.total_words = size(find(Error.symbol>0),2);
Error.total_CRC = size(find(Error.symbol2>0),2);
Error.BER_actual = 100*(Error.total/prod(size(T)));
27
Error.BER_actual_words = 100*(Error.total_words/(size(T,2)));
Error.BER_CRC = 100*(Error.total_CRC/((size(T,2))/3));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Hamming 7,4 Encoding
function H = Hamming_encode(bits)
% bits is a 8 row, many columns matrix
% Define N and K for the Hamming Encoding 7,4
N = 7;
K = 4;
% Change the received data to 4bits in each column (for K = 4)
H.new_data_bits = reshape(bits, K , size(bits,2) * (8/K) ) ;
% Define G
G = [ 1 1 0 1 ;
1 0 1 1 ;
1 0 0 0 ;
0 1 1 1 ;
0 1 0 0 ;
0 0 1 0 ;
0 0 0 1 ];
% Encoding the 3 parity bits
for i = 1 : size(H.new_data_bits,2)
H.Tbits(:,i) = G * H.new_data_bits(:,i);
end
H.Tbits = mod(H.Tbits,2);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Hamming 7,4 Decoding
function R = Hamming_decode(HE_bits)
% HE_bits is a 8 row, many columns matrix
% Define N and K for the Hamming Encoding 7,4
% N = 7;
% K = 4;
%
% % Change the received data to 4bits in each column (for K = 4)
% H.new_data_bits = reshape(bits, K , size(bits,2) * (8/K) ) ;
28
% Define H
H = [ 1 0 1 0 1 0 1;
0 1 1 0 0 1 1;
0 0 0 1 1 1 1];
% Decoding
for i = 1 : size(HE_bits,2)
R.Ebits(:,i) = H * HE_bits(:,i);
end
R.Ebits = mod(R.Ebits,2);
% CORRECTING
% Gives error locations as in H
% R.E_loc = (bin2dec(num2str(R.Ebits')))'; % TAKES TOO LONG
for z=1:size(R.Ebits,2);
R.E_loc(1,z) = 4*R.Ebits(1,z) + 2*R.Ebits(2,z) + 1*R.Ebits(3,z);
end
R.H_loc = (bin2dec(num2str(H')))';
% Defining Received bits with errors
R.Rbits = HE_bits;
R.Corr_bits = R.Rbits;
for i = 1 : size(R.Rbits,2)
R.Err_at(i) = 0;
if(R.E_loc(i))
% Location of the bits (in row number) of where the error occured
% in each column
R.Err_at(i) = (find(R.H_loc == R.E_loc(i)));
% Corrected bits
R.Corr_bits(R.Err_at(i),i) = ~R.Corr_bits(R.Err_at(i),i);
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% RECONSTRUCT FROM HAMMING ENCODE/DECODE
% Reconstruct 8bit code from hamming output by removing parity bits and
% reshaping
29
function R_bits = Reconstruct_Hbits(bits)
bits_2 = [bits(3,:); bits(5:7,:)];
R_bits = bits_2(:,1:2:end);
R_bits = [R_bits; bits_2(:,2:2:end)];
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% HAMMING CODE IMPLEMENTATION ERROR
function [ERR ] = H_error(HEN,R)
samples = size(R,2);
for j=1:samples
ERR(i).xor = mod((R(j).Corr_bits .* ~HE.Tbits + ~R(j).Corr_bits ...
.* HE.Tbits),2);
end
% TO VIEW EACH ERROR AND CORRECTION
% for j=1:samples
% clc
% fprintf('Error at %.0f is : n n', j);
% disp(R(j).Err_at);
% fprintf('Correction is n n', j);
% disp(mod((R(j).Corr_bits .* ~HE.Tbits + ~R(j).Corr_bits ...
% .* HE.Tbits),2));
% pause
% end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30

More Related Content

What's hot

The Performance Evaluation of IEEE 802.16 Physical Layer in the Basis of Bit ...
The Performance Evaluation of IEEE 802.16 Physical Layer in the Basis of Bit ...The Performance Evaluation of IEEE 802.16 Physical Layer in the Basis of Bit ...
The Performance Evaluation of IEEE 802.16 Physical Layer in the Basis of Bit ...IJCI JOURNAL
 
Design, Analysis and Implementation of Modified Luby Transform Code
Design, Analysis and Implementation of Modified Luby Transform CodeDesign, Analysis and Implementation of Modified Luby Transform Code
Design, Analysis and Implementation of Modified Luby Transform CodeIOSR Journals
 
Jaimin chp-3 - data-link layer- 2011 batch
Jaimin   chp-3 - data-link layer- 2011 batchJaimin   chp-3 - data-link layer- 2011 batch
Jaimin chp-3 - data-link layer- 2011 batchJaimin Jani
 
Unit 10 Assignment_2_Sig_Theory_and_Data Elements V3
Unit 10 Assignment_2_Sig_Theory_and_Data Elements V3Unit 10 Assignment_2_Sig_Theory_and_Data Elements V3
Unit 10 Assignment_2_Sig_Theory_and_Data Elements V3John Mathias
 
ND0801_Assignment_3_Protocols for P3
ND0801_Assignment_3_Protocols for P3ND0801_Assignment_3_Protocols for P3
ND0801_Assignment_3_Protocols for P3John Mathias
 
Exercises TCP/IP Networking With Solutions
Exercises TCP/IP Networking With SolutionsExercises TCP/IP Networking With Solutions
Exercises TCP/IP Networking With SolutionsFelipe Suarez
 
6 2 transport layer (tcp)
6 2 transport layer (tcp)6 2 transport layer (tcp)
6 2 transport layer (tcp)Tutun Juhana
 
Internet technology unit 4
Internet technology unit 4Internet technology unit 4
Internet technology unit 4WE-IT TUTORIALS
 
Internet technology unit 3
Internet technology unit 3Internet technology unit 3
Internet technology unit 3WE-IT TUTORIALS
 
IEEE 802.11a Physical Layer Simulation
IEEE 802.11a Physical Layer SimulationIEEE 802.11a Physical Layer Simulation
IEEE 802.11a Physical Layer SimulationMichail Grigoropoulos
 
Satellite error detection and correction presentation
Satellite error detection and correction presentationSatellite error detection and correction presentation
Satellite error detection and correction presentationAhmedMuhumed2
 
IRJET-Simulation of Channel-Estimation for Digital Communication System based...
IRJET-Simulation of Channel-Estimation for Digital Communication System based...IRJET-Simulation of Channel-Estimation for Digital Communication System based...
IRJET-Simulation of Channel-Estimation for Digital Communication System based...IRJET Journal
 

What's hot (20)

Tcp ip
Tcp ipTcp ip
Tcp ip
 
Data link layer
Data link layerData link layer
Data link layer
 
Coding
CodingCoding
Coding
 
The Performance Evaluation of IEEE 802.16 Physical Layer in the Basis of Bit ...
The Performance Evaluation of IEEE 802.16 Physical Layer in the Basis of Bit ...The Performance Evaluation of IEEE 802.16 Physical Layer in the Basis of Bit ...
The Performance Evaluation of IEEE 802.16 Physical Layer in the Basis of Bit ...
 
Cn lab manual 150702
Cn lab manual 150702Cn lab manual 150702
Cn lab manual 150702
 
Design, Analysis and Implementation of Modified Luby Transform Code
Design, Analysis and Implementation of Modified Luby Transform CodeDesign, Analysis and Implementation of Modified Luby Transform Code
Design, Analysis and Implementation of Modified Luby Transform Code
 
Turbocode
TurbocodeTurbocode
Turbocode
 
Jaimin chp-3 - data-link layer- 2011 batch
Jaimin   chp-3 - data-link layer- 2011 batchJaimin   chp-3 - data-link layer- 2011 batch
Jaimin chp-3 - data-link layer- 2011 batch
 
Unit 10 Assignment_2_Sig_Theory_and_Data Elements V3
Unit 10 Assignment_2_Sig_Theory_and_Data Elements V3Unit 10 Assignment_2_Sig_Theory_and_Data Elements V3
Unit 10 Assignment_2_Sig_Theory_and_Data Elements V3
 
ND0801_Assignment_3_Protocols for P3
ND0801_Assignment_3_Protocols for P3ND0801_Assignment_3_Protocols for P3
ND0801_Assignment_3_Protocols for P3
 
Chapter5
Chapter5Chapter5
Chapter5
 
02 Network Models
02 Network Models02 Network Models
02 Network Models
 
Exercises TCP/IP Networking With Solutions
Exercises TCP/IP Networking With SolutionsExercises TCP/IP Networking With Solutions
Exercises TCP/IP Networking With Solutions
 
6 2 transport layer (tcp)
6 2 transport layer (tcp)6 2 transport layer (tcp)
6 2 transport layer (tcp)
 
Chapter 21
Chapter 21Chapter 21
Chapter 21
 
Internet technology unit 4
Internet technology unit 4Internet technology unit 4
Internet technology unit 4
 
Internet technology unit 3
Internet technology unit 3Internet technology unit 3
Internet technology unit 3
 
IEEE 802.11a Physical Layer Simulation
IEEE 802.11a Physical Layer SimulationIEEE 802.11a Physical Layer Simulation
IEEE 802.11a Physical Layer Simulation
 
Satellite error detection and correction presentation
Satellite error detection and correction presentationSatellite error detection and correction presentation
Satellite error detection and correction presentation
 
IRJET-Simulation of Channel-Estimation for Digital Communication System based...
IRJET-Simulation of Channel-Estimation for Digital Communication System based...IRJET-Simulation of Channel-Estimation for Digital Communication System based...
IRJET-Simulation of Channel-Estimation for Digital Communication System based...
 

Similar to Forward Bit Error Correction - Wireless Communications

Vlsi Implementation of Low Power Convolutional Coding With Viterbi Decoding U...
Vlsi Implementation of Low Power Convolutional Coding With Viterbi Decoding U...Vlsi Implementation of Low Power Convolutional Coding With Viterbi Decoding U...
Vlsi Implementation of Low Power Convolutional Coding With Viterbi Decoding U...IOSR Journals
 
ITERATIVE METHOD FOR IMPROVEMENT OF CODING AND DECRYPTION
ITERATIVE METHOD FOR IMPROVEMENT OF CODING AND DECRYPTIONITERATIVE METHOD FOR IMPROVEMENT OF CODING AND DECRYPTION
ITERATIVE METHOD FOR IMPROVEMENT OF CODING AND DECRYPTIONIJNSA Journal
 
Error detection and correction
Error detection and correctionError detection and correction
Error detection and correctionSisir Ghosh
 
Accurate wireless channel modeling for efficient adaptive Forward Error Corre...
Accurate wireless channel modeling for efficient adaptive Forward Error Corre...Accurate wireless channel modeling for efficient adaptive Forward Error Corre...
Accurate wireless channel modeling for efficient adaptive Forward Error Corre...IJERD Editor
 
Presentation for the Project on VLSI and Embedded
Presentation for the Project on VLSI and EmbeddedPresentation for the Project on VLSI and Embedded
Presentation for the Project on VLSI and Embeddedlthanuja01
 
Single-Bit Parity Detection and Correction using Hamming Code 7-Bit Model
Single-Bit Parity Detection and Correction using Hamming Code 7-Bit ModelSingle-Bit Parity Detection and Correction using Hamming Code 7-Bit Model
Single-Bit Parity Detection and Correction using Hamming Code 7-Bit ModelUniversitas Pembangunan Panca Budi
 
Error correction and detection th
Error correction and detection thError correction and detection th
Error correction and detection thShardaSalunkhe1
 
DCN Error Detection & Correction
DCN Error Detection & CorrectionDCN Error Detection & Correction
DCN Error Detection & CorrectionRohan Bhatkar
 
Hard Decision Viterbi Decoder: Implementation on FPGA and Comparison of Resou...
Hard Decision Viterbi Decoder: Implementation on FPGA and Comparison of Resou...Hard Decision Viterbi Decoder: Implementation on FPGA and Comparison of Resou...
Hard Decision Viterbi Decoder: Implementation on FPGA and Comparison of Resou...IJERA Editor
 
Paper id 312201514
Paper id 312201514Paper id 312201514
Paper id 312201514IJRAT
 
data link layer - Chapter 3
data link layer - Chapter 3data link layer - Chapter 3
data link layer - Chapter 3SakthiVinoth78
 
07 Data Link LayerError Control.pdf
07 Data Link LayerError Control.pdf07 Data Link LayerError Control.pdf
07 Data Link LayerError Control.pdfbaysahcmjames2kblax
 
Implementation of a bit error rate tester of a wireless communication system ...
Implementation of a bit error rate tester of a wireless communication system ...Implementation of a bit error rate tester of a wireless communication system ...
Implementation of a bit error rate tester of a wireless communication system ...eSAT Publishing House
 
chp2 - data link layer.pptx
chp2 - data link layer.pptxchp2 - data link layer.pptx
chp2 - data link layer.pptxChakra Pani
 

Similar to Forward Bit Error Correction - Wireless Communications (20)

crc_checksum.pdf
crc_checksum.pdfcrc_checksum.pdf
crc_checksum.pdf
 
Vlsi Implementation of Low Power Convolutional Coding With Viterbi Decoding U...
Vlsi Implementation of Low Power Convolutional Coding With Viterbi Decoding U...Vlsi Implementation of Low Power Convolutional Coding With Viterbi Decoding U...
Vlsi Implementation of Low Power Convolutional Coding With Viterbi Decoding U...
 
ITERATIVE METHOD FOR IMPROVEMENT OF CODING AND DECRYPTION
ITERATIVE METHOD FOR IMPROVEMENT OF CODING AND DECRYPTIONITERATIVE METHOD FOR IMPROVEMENT OF CODING AND DECRYPTION
ITERATIVE METHOD FOR IMPROVEMENT OF CODING AND DECRYPTION
 
Hamming code system
Hamming code systemHamming code system
Hamming code system
 
Error detection and correction
Error detection and correctionError detection and correction
Error detection and correction
 
E42032732
E42032732E42032732
E42032732
 
Accurate wireless channel modeling for efficient adaptive Forward Error Corre...
Accurate wireless channel modeling for efficient adaptive Forward Error Corre...Accurate wireless channel modeling for efficient adaptive Forward Error Corre...
Accurate wireless channel modeling for efficient adaptive Forward Error Corre...
 
Presentation for the Project on VLSI and Embedded
Presentation for the Project on VLSI and EmbeddedPresentation for the Project on VLSI and Embedded
Presentation for the Project on VLSI and Embedded
 
Single-Bit Parity Detection and Correction using Hamming Code 7-Bit Model
Single-Bit Parity Detection and Correction using Hamming Code 7-Bit ModelSingle-Bit Parity Detection and Correction using Hamming Code 7-Bit Model
Single-Bit Parity Detection and Correction using Hamming Code 7-Bit Model
 
Error correction and detection th
Error correction and detection thError correction and detection th
Error correction and detection th
 
DCN Error Detection & Correction
DCN Error Detection & CorrectionDCN Error Detection & Correction
DCN Error Detection & Correction
 
X04408122125
X04408122125X04408122125
X04408122125
 
Hard Decision Viterbi Decoder: Implementation on FPGA and Comparison of Resou...
Hard Decision Viterbi Decoder: Implementation on FPGA and Comparison of Resou...Hard Decision Viterbi Decoder: Implementation on FPGA and Comparison of Resou...
Hard Decision Viterbi Decoder: Implementation on FPGA and Comparison of Resou...
 
Paper id 312201514
Paper id 312201514Paper id 312201514
Paper id 312201514
 
Lecture 22
Lecture 22Lecture 22
Lecture 22
 
data link layer - Chapter 3
data link layer - Chapter 3data link layer - Chapter 3
data link layer - Chapter 3
 
J0445255
J0445255J0445255
J0445255
 
07 Data Link LayerError Control.pdf
07 Data Link LayerError Control.pdf07 Data Link LayerError Control.pdf
07 Data Link LayerError Control.pdf
 
Implementation of a bit error rate tester of a wireless communication system ...
Implementation of a bit error rate tester of a wireless communication system ...Implementation of a bit error rate tester of a wireless communication system ...
Implementation of a bit error rate tester of a wireless communication system ...
 
chp2 - data link layer.pptx
chp2 - data link layer.pptxchp2 - data link layer.pptx
chp2 - data link layer.pptx
 

More from Surya Chandra

Robotics Simulation by Wireless Brains - ROBOKDC'15 Project
Robotics Simulation by Wireless Brains - ROBOKDC'15 ProjectRobotics Simulation by Wireless Brains - ROBOKDC'15 Project
Robotics Simulation by Wireless Brains - ROBOKDC'15 ProjectSurya Chandra
 
Wordoku Puzzle Solver - Image Processing Project
Wordoku Puzzle Solver - Image Processing ProjectWordoku Puzzle Solver - Image Processing Project
Wordoku Puzzle Solver - Image Processing ProjectSurya Chandra
 
Direction Finding - Antennas Project
Direction Finding - Antennas Project Direction Finding - Antennas Project
Direction Finding - Antennas Project Surya Chandra
 
Smart Bin – Advanced Control System Design Project
Smart Bin – Advanced Control System Design ProjectSmart Bin – Advanced Control System Design Project
Smart Bin – Advanced Control System Design ProjectSurya Chandra
 
Augmented Reality Video Playlist - Computer Vision Project
Augmented Reality Video Playlist - Computer Vision ProjectAugmented Reality Video Playlist - Computer Vision Project
Augmented Reality Video Playlist - Computer Vision ProjectSurya Chandra
 
Balancing Robot Kalman Filter Design – Estimation Theory Project
Balancing Robot Kalman Filter Design – Estimation Theory ProjectBalancing Robot Kalman Filter Design – Estimation Theory Project
Balancing Robot Kalman Filter Design – Estimation Theory ProjectSurya Chandra
 
Exploring Support Vector Regression - Signals and Systems Project
Exploring Support Vector Regression - Signals and Systems ProjectExploring Support Vector Regression - Signals and Systems Project
Exploring Support Vector Regression - Signals and Systems ProjectSurya Chandra
 

More from Surya Chandra (7)

Robotics Simulation by Wireless Brains - ROBOKDC'15 Project
Robotics Simulation by Wireless Brains - ROBOKDC'15 ProjectRobotics Simulation by Wireless Brains - ROBOKDC'15 Project
Robotics Simulation by Wireless Brains - ROBOKDC'15 Project
 
Wordoku Puzzle Solver - Image Processing Project
Wordoku Puzzle Solver - Image Processing ProjectWordoku Puzzle Solver - Image Processing Project
Wordoku Puzzle Solver - Image Processing Project
 
Direction Finding - Antennas Project
Direction Finding - Antennas Project Direction Finding - Antennas Project
Direction Finding - Antennas Project
 
Smart Bin – Advanced Control System Design Project
Smart Bin – Advanced Control System Design ProjectSmart Bin – Advanced Control System Design Project
Smart Bin – Advanced Control System Design Project
 
Augmented Reality Video Playlist - Computer Vision Project
Augmented Reality Video Playlist - Computer Vision ProjectAugmented Reality Video Playlist - Computer Vision Project
Augmented Reality Video Playlist - Computer Vision Project
 
Balancing Robot Kalman Filter Design – Estimation Theory Project
Balancing Robot Kalman Filter Design – Estimation Theory ProjectBalancing Robot Kalman Filter Design – Estimation Theory Project
Balancing Robot Kalman Filter Design – Estimation Theory Project
 
Exploring Support Vector Regression - Signals and Systems Project
Exploring Support Vector Regression - Signals and Systems ProjectExploring Support Vector Regression - Signals and Systems Project
Exploring Support Vector Regression - Signals and Systems Project
 

Recently uploaded

HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...Call Girls in Nagpur High Profile
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 

Recently uploaded (20)

Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 

Forward Bit Error Correction - Wireless Communications

  • 1. Wireless Communications Forward Bit Error Correction Final Project Report Surya Sekhar Chandra Electrical Engineering Colorado School Of Mines
  • 2. 1 Abstract This project aims to investigate the applications and effectiveness of different types of for- ward error detecting and correcting techniques. The topics explored in the project include error detecting techniques, such as, vertical redundancy check and cyclic redundancy check (checksum), and error correcting techniques, such as, Hamming 7,4 coding. Each topic is explored with an example implementation with signals affected by Gaussian noise and burst errors. It is then shown how interleaving can provide robustness against burst errors. The project concludes with an overview of convolutional coding and decoding methods. 2 Implementation An image is selected and broken down into its grayscale values. Each grayscale value is converted to an 8-bit binary. All the values are converted to a bit stream and sent for encoding and then transmitted through a noisy channel. Fig. 1: Implementation process - converting an image into a bit stream Figure 1 shows the process of obtaining a bit stream from an image. Noise in the channel is added to the encoded bit stream in the form of Gaussian noise or burst errors in Matlab. The received signal(bit stream) is decoded and matched with transmitted signal to calculate the percentage of errors detected. For a better visualization of the effectiveness of each technique, the corrected bit stream is reconstructed and compared with the uncorrected bit stream. 1
  • 3. 3 Parity bit (VRC) Parity bit or vertical redundancy check is an error detecting technique. In this method, for a given set of symbols (8-bit in this case), an extra bit is added at the end of the symbol to make the sum of all the bits in the symbol either a 0 or 1 (even or odd parity). When the set of symbols passes through a noisy channel and reaches the receiver, errors can be checked for by simply doing the modulo 2 sum of all of the bits in the symbol. If the sum does not match the parity scheme, then at least one error has occurred in the symbol. This method is relatively limited, as it cannot detect an even number of errors in a symbol. A Matlab script was created to show the effectiveness of parity scheme in error detection. The program took an input signal (a vectorized version of the cameraman.tif image), added parity bits, and then applied white Gaussian noise to the signal. The number of parity detected bit errors vs. the actual number of errors is shown below in Figure 2. Fig. 2: Parity error detection The results show that adding a parity bit can be a useful tool for detecting relatively sparse Gaussian noise, however this method breaks down relatively quickly at higher noise levels for a gaussian noise. 2
  • 4. 4 Checksum (CRC) Checksum is a type of cyclic redundancy check used for bit error detection. In this method, an extra symbol (8-bits in this case) called checksum is added after every two symbols (16 bits), such that the binary sum of the three symbols is a zero. If at the sum at receiving end is found to be different from a zero, then an error must have occurred during the transmission through the channel. This method is more robust compared to VRC because it has a very low probability of occurrence of an undetected error. Fig. 3: An example of error detection using checksum Figure 3 shows the step by step procedure of encoding and decoding a data using check- sum method. Encoded data encounters a noise while passing through the channel and this causes some of the bits to flip during transmission. At the receiver end, data is accepted or rejected based on the value of the summation. As shown in check2, even though there are two bit errors the result of summation is still zero and the data is accepted. This is a case of false error detection using CRC. 3
  • 5. Fig. 4: CRC error detection for AWGN Fig. 5: CRC error detection for burst error As it is evident from Figure 4, the performance of error detection using this method is better than the vertical redundancy check technique, even for a higher Gaussian noise variance. This technique was then applied with a burst error (multiple bit errors occurring simultaneously within a period of time) in the channel and the performance of error detection was observed to be much better even for high variance of burst error occurrence as seen in Figure 5 5 Hamming 7,4 coding Block codes are one of the two main classes of FEC codes. They take an input of k charac- ters and output n characters. Thus block codes utilize 2k out of 2n possible codewords, the unused codewords allow the code to have a certain hamming distance for error correction. The encoding of each length n block is completely independent of other blocks that have been previously encoded. This means that the block encoders are memory-less devices. The ability to look at each block separately greatly simplifies the decoding process. Hamming 7,4 is an extension of the idea of parity, instead of just detecting one bit error per symbol, this code (with a Hamming distance of 3) is able to correct one bit error per 4 bit symbol. This class has focused on the method in which the Hamming 7,4 encoding and decoding functions, thus this project will focus more on demonstrating its error correcting abilities. 4
  • 6. Fig. 6: Steps involved in hamming 7,4 Fig. 7: Hamming 7,4 parity diagram This method involves adding three parity bits to every four bits of data. Each of these partiy bits forms an even parity with three of the four bits as shown in Figures 6 and 7. The first test of this code is to see how it preforms in correcting AWGN at different noise variance levels. To test this, the input signal is again a vectorized version of the ’cameraman.tif’ image. The signal is encoded, AWGN is added, and then the signal is reconstructed and compared to the original image. The result of this test is shown below in Figure 8. Fig. 8: Error correction using Hamming 7-4 coding for AWGN 5
  • 7. The results show that Hamming 7,4 performs well in low noise environments. A link to the video simulation showing the same is given below with Figure 9. Fig. 9: Hamming awgn correction video simulation Click on the image or go to https://youtu.be/ppSRTn3GK5I Next step is to see how well hamming 7,4 performs when attempting to correct burst errors. This test follows the same outline as above, but adds burst errors to the signal instead of AWNG. The results are shown below in Figure 10 Fig. 10: Error correction using Hamming 7-4 coding for burst error 6
  • 8. Fig. 11: Hamming burst error correction video simulation Click on the image or go to https://youtu.be/0FImOsM2zeQ As it can be seen in the video, there is no correction for even for a low level of burst noise occurrence. The bit error rate stays the same even after the correction. Hamming 7,4 code is clearly not suited to correct burst errors, as there are almost always multiple errors occurring per symbol. This problem can be remedied using the concept of interleaving. 6 Interleaving Interleaving is a separate process that can be applied to encoded data before it is passed through a noisy channel. The idea is to somehow scramble the data (there are numerous ways of doing this) before putting it through the noisy channel and then unscramble the data before decoding. This unscrambling of the data after it passes through the channel has the effect of scrambling the noise that the data was subject to in the channel. This can aide greatly in in the ability of block codes to decode burst errors. A simple example of interleaving using a shifting operation is illustrated below in Figure 12. The colored columns represent 7-bit symbols (including the parity bits) that are transmitted. Since interleaving ’smears out’ burst errors, it is useful in correcting them with block encoding. This kind of interleaving was added to the Hamming 7,4 encoding process. Each column of the data is shifted by a specific amount before transmission and then shifted back after it is received. The results of this process are shown on the next page in Figure 13. 7
  • 9. Fig. 12: Interleaving process for block codes Fig. 13: Error correction for hamming 7,4 burst errors using interleaving 8
  • 10. Fig. 14: Hamming + interleave burst error correction video simulation Click on the image or go to https://youtu.be/jrUhW_5C4Sw From the graph (Figure 13) and the video (Figure 14), it is obvious that interleaving restores the error correcting ability of the Hamming 7,4 code when exposed to burst errors. Note that the noise variance in this case refers to the Gaussian distribution of the noise errors. The error increases at a faster rate with the variance because multiple bit errors occur at every error occurrence. 7 Convolutional coding Convolutional coding methods still involves generating a set of parity bits from an set of input bits. However, rather than calculating these parity bits through a matrix multipli- cation with a single block of data at a time, convolutional coding schemes create parity bits progressively as the input is shifted into the encoder. Sliding the input stream past an encoding function and preforming a convolution (XOR operations on current and previous bits) at each step produces the parity bits. This operation can be modeled as a shift register as shown below in Figure 15. x[n] is the input, and p1[n] and p2[n] are the output parity bits. While convolutionally encoding data is relatively simple, decoding the data can be much more challenging. Considering the case of no errors in the received data, the decoder can simply follow a trellis diagram, as shown in Figure 16. The correct path through the trellis is mapped by the parity bits and the states of the code (in this case, the states are the previous two input bits). Once this path is found, the original data bits are recovered by looking at the state transitions. In this case, there are only two possible transitions from one state to the next, representing either a one or zero. If we introduce errors into the convolutionally encoded data, then it becomes far more complex decode, as there is now no correct path through the trellis! One strategy for re- 9
  • 11. covering the data could be to follow every path in the trellis and then sum the accumulated error along each path and pick the path with the least error. However this is not practical Fig. 15: Convolutional coding shift register model since an algorithm would run forever to do this computation. A realistic approach would be to guess at the next state based on the current state, and the probability of the transition between states. In this way the algorithm is outputting the ’most likely’ path through the trellis. Errors are corrected by maximizing the probability that the correct path was chosen. Fig. 16: Trellis diagram for convolutional encoding and decoding One widely used method that is used to preform this kind of analysis is the Viterbi algorithm. It looks at a subset of the trellis and eliminates the least likely paths in order to greatly reduce the complexity of finding the most probable path. 8 Conclusion In the real world, bit errors occurrence for the data transmitted cannot be avoided. Forward error correction is an invaluable tool for a reliable transmission of data across such a noisy 10
  • 12. channel. It allows for a trade off between the data rate and the bit error rate. This project demonstrated the functionality of Hamming codes under different noise conditions, as well as discussing the difference between block and convolutional coding methods. Since virtu- ally all forms of wireless communication involve noise, FEC is an invaluable for improving performance and reliability. 11
  • 13. Appendix MATLAB Code: %% PARITY MAIN PROGRAM %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear all close all clc %% To Generate New Data % bit_length = 8; % T = im2bits(imread('cameraman.tif'),bit_length); % save T % LOADING GENERATED DATA load('T.mat','T'); % T.bits contains columns of binary bits %% Adding the parity bit % To add parity bit at the end of each column in T_image.bits % Specify even or odd parity T.pbits = parity_add(T.bits,'even'); %% Adding awgn noise to data noise_sigma_max = 0.5; samples = 100; sigma = linspace(0,noise_sigma_max,samples); for i=1:size(sigma,2) % Adding Noise for given sigma [R(i).pbits] = add_awgn(T.pbits, sigma(i), 2); % Find Bit Errors Err(i) = find_errors(T.pbits,R(i).pbits); BER_actual(i) = Err(i).BER_actual; BER_actual_w(i) = Err(i).BER_actual_words; undetected(i) = sum(Err(i).symbol(find(Err(i).symbol == 2 | ... Err(i).symbol == 4 | Err(i).symbol == 6 | Err(i).symbol == 8))); undetected_w(i) = size(Err(i).symbol(find(Err(i).symbol == 2 | ... 12
  • 14. Err(i).symbol == 4 | Err(i).symbol == 6 | Err(i).symbol == 8)),2); parity_error(i) = 100*(undetected(i)/prod(size(R(i).pbits))); parity_error_w(i) = 100*(undetected_w(i)/(size(R(i).pbits,2))); parity_estimated_BER(i) = BER_actual(i) − parity_error(i); parity_estimated_BER_w(i) = BER_actual_w(i) − parity_error_w(i); end %% PLOT AND LABELS figure(1) plot(sigma,BER_actual,'b','LineWidth',2); hold on plot(sigma,parity_estimated_BER,'g','LineWidth',2); plot(sigma,parity_error,'−−r','LineWidth',2); title('bf PARITY SCHEME : NOISE VARIANCE VS BER','FontSize',18); xlabel('bf Noise Standard deviation ( sigma )','FontSize',16); ylabel('bf BER ','FontSize',16); h = legend('Actual BER','Parity estimated BER','Parity undetected',... 'Location','NorthWest'); set(h,'FontSize',16); hold off figure(2) plot(sigma,BER_actual_w,'b','LineWidth',2); hold on plot(sigma,parity_estimated_BER_w,'g','LineWidth',2); plot(sigma,parity_error_w,'−−r','LineWidth',2); title('bf PARITY SCHEME : NOISE VARIANCE VS BER − Symbols','FontSize',18); xlabel('bf Noise Standard deviation ( sigma )','FontSize',16); ylabel('bf BER ','FontSize',16); h = legend('Actual BER (Symbol)','Parity estimated BER',... 'Parity undetected','Location','NorthWest'); set(h,'FontSize',16); hold off %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% CRC_Checksum %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear all close all clc 13
  • 15. %% To Generate New Data % bit_length = 8; % T = im2bits(imread('cameraman.tif'),bit_length); % save T % LOADING GENERATED DATA load('T.mat','T'); % T.bits contains columns of binary bits %% Appending a 8bit Checksum for every 16 bits % To add checksum as a new column in T_image.bits [T.pbits, S] = checksum_add(T.bits); %% Adding awgn noise to data noise_sigma_max = 0.5; samples = 100; sigma = linspace(0,noise_sigma_max,samples); for i=1:size(sigma,2) % Adding Noise for given sigma [R(i).pbits] = add_awgn(T.pbits, sigma(i), 2); % Find Bit Errors Err(i) = find_errors_crc(T.pbits,R(i).pbits); BER_actual(i) = Err(i).BER_CRC; [summed, t_error, BER_detected(i)] = checksum_check(R(i).pbits); disp(i); end %% PLOT AND LABELS figure(1) plot(sigma,BER_actual,'b','LineWidth',2); hold on plot(sigma,BER_detected,'g','LineWidth',2); title('bf CRC−CHECKSUM : NOISE VARIANCE VS BER','FontSize',18); xlabel('bf Noise Standard deviation ( sigma )','FontSize',16); ylabel('bf BER−symbols(16bits) ','FontSize',16); h = legend('Actual BER','CRC Detected BER',... 'Location','NorthWest'); set(h,'FontSize',16); 14
  • 16. hold off %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% CRC_Checksum_burst_noise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear all close all clc %% To Generate New Data % bit_length = 8; % T = im2bits(imread('cameraman.tif'),bit_length); % save T % LOADING GENERATED DATA load('T.mat','T'); % T.bits contains columns of binary bits %% Appending a 8bit Checksum for every 16 bits % To add checksum as a new column in T_image.bits [T.pbits, S] = checksum_add(T.bits); %% Adding awgn noise to data noise_sigma_max = 0.35; samples = 100; sigma = linspace(0,noise_sigma_max,samples); for i=1:size(sigma,2) % Adding Noise for given sigma [R(i).pbits] = burst_add(T.pbits, sigma(i)); % Find Bit Errors Err(i) = find_errors_crc(T.pbits,R(i).pbits); BER_actual(i) = Err(i).BER_CRC; [summed, t_error, BER_crc ] = checksum_check(R(i).pbits); BER_detected(i) = BER_crc; 15
  • 17. disp(i); end %% PLOT AND LABELS figure(1) plot(sigma,BER_actual,'b','LineWidth',2); hold on plot(sigma,BER_detected,'g','LineWidth',2); title('bf CRC−CHECKSUM : BURST NOISE VARIANCE VS BER','FontSize',18); xlabel('bf Noise Standard deviation ( sigma )','FontSize',16); ylabel('bf BER−symbols(16bits) ','FontSize',16); h = legend('Actual BER','CRC Detected BER',... 'Location','NorthWest'); set(h,'FontSize',16); hold off %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Hamming Main Program %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear all close all clc %% To Generate New Data % bit_length = 8; % T = im2bits(imread('cameraman.tif'),bit_length); % save T % LOADING GENERATED DATA load('T.mat','T'); % T.bits contains columns of binary bits bits = T.bits; % Encode HE = Hamming_encode(bits); %% Add awgn error noise_sigma_max = 0.35; samples = 100; sigma = linspace(0,noise_sigma_max,samples); 16
  • 18. % Looping through the noise for i=1:size(sigma,2) % Adding Noise for given sigma HEN(i).Tbits = add_awgn(HE.Tbits, sigma(i), 2); R(i) = Hamming_decode(HEN(i).Tbits); sigma(i) % Find Bit Errors Err(i) = find_errors(HE.Tbits,R(i).Rbits); BER_actual(i) = Err(i).BER_actual; Err_after_corr(i) = find_errors(HE.Tbits,R(i).Corr_bits); BER_after_corr(i) = Err_after_corr(i).BER_actual; BER_corrected(i) = BER_actual(i) − BER_after_corr(i); end %% PLOT AND LABELS figure(1) plot(sigma,BER_actual,'b','LineWidth',2); hold on plot(sigma,BER_after_corr,'−−r','LineWidth',2); title('bf HAMMING 7,4 SCHEME : NOISE VARIANCE VS BER','FontSize',18); xlabel('bf Noise Standard deviation ( sigma )','FontSize',16); ylabel('bf BER ','FontSize',16); h = legend('Actual BER','BER after Hamming correction',... 'Location','NorthWest'); set(h,'FontSize',16); hold off %% Reconstruct vidObj = VideoWriter('Simulation.avi'); vidObj.FrameRate = 6; open(vidObj); for l = 1:100 % Plotting the image after the bit correction by hamming code R_bits = Reconstruct_Hbits(R(l).Corr_bits); BIT_STREAM=((R_bits)); Im = bits2im(BIT_STREAM,[256 256]); hFig = figure(2); set(hFig, 'Position', [150 150 1000 600]) subplot(1,2,2) 17
  • 19. imshow(Im.image,[]); title('bf Image after Hamming correction','FontSize',16); % plotting the image before the correction by hamming code E_bits = Reconstruct_Hbits(HEN(l).Tbits); BIT_STREAM=((E_bits)); Im2 = bits2im(BIT_STREAM,[256 256]); subplot(1,2,1) title_string = sprintf('Noisy image before correction, Sigma = %f',... sigma(l)); imshow(Im2.image,[]); tt=title(title_string ,'FontSize',16); set(tt,'FontWeight','bold'); currFrame = getframe(hFig); writeVideo(vidObj,currFrame); end close(hFig); close(vidObj); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Hamming With Burst Noise Main Program %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear all close all clc %% To Generate New Data % bit_length = 8; % T = im2bits(imread('cameraman.tif'),bit_length); % save T % LOADING GENERATED DATA load('T.mat','T'); % T.bits contains columns of binary bits bits = T.bits; HE = Hamming_encode(bits); %% Add burst error noise_sigma_max = 0.3; samples = 100; % chance of burst sigma = linspace(0,noise_sigma_max,samples); 18
  • 20. % Looping through the noise for i=1:size(sigma,2) % Adding Noise for given sigma HEN(i).Tbits = burst_add(HE.Tbits,sigma(i)); R(i) = Hamming_decode(HEN(i).Tbits); sigma(i) % Find Bit Errors Err(i) = find_errors(HE.Tbits,R(i).Rbits); BER_actual(i) = Err(i).BER_actual; Err_after_corr(i) = find_errors(HE.Tbits,R(i).Corr_bits); BER_after_corr(i) = Err_after_corr(i).BER_actual; BER_corrected(i) = BER_actual(i) − BER_after_corr(i); end %% PLOT AND LABELS figure(1) plot(sigma,BER_actual,'b','LineWidth',2); hold on plot(sigma,BER_after_corr,'−−r','LineWidth',2); title('bf HAMMING 7,4 SCHEME : BURST NOISE VARIANCE VS BER',... 'FontSize',18); xlabel('bf Noise Standard deviation ( sigma )','FontSize',16); ylabel('bf BER ','FontSize',16); h = legend('Actual BER','BER after Hamming correction',... 'Location','NorthWest'); set(h,'FontSize',16); hold off %% Reconstruct vidObj = VideoWriter('Hamming_Burst_Simulation.avi'); vidObj.FrameRate = 6; open(vidObj); for l = 1:100 % Plotting the image after the bit correction by hamming code R_bits = Reconstruct_Hbits(R(l).Corr_bits); BIT_STREAM=((R_bits)); Im = bits2im(BIT_STREAM,[256 256]); hFig = figure(2); 19
  • 21. set(hFig, 'Position', [150 150 1000 600]) subplot(1,2,2) imshow(Im.image,[]); title('bf Image after Hamming correction','FontSize',16); % plotting the image before the correction by hamming code E_bits = Reconstruct_Hbits(HEN(l).Tbits); BIT_STREAM=((E_bits)); Im2 = bits2im(BIT_STREAM,[256 256]); subplot(1,2,1) title_string = sprintf('Noisy image before correction, Sigma = %f'... ,sigma(l)); imshow(Im2.image,[]); tt=title(title_string ,'FontSize',16); set(tt,'FontWeight','bold'); currFrame = getframe(hFig); writeVideo(vidObj,currFrame); end close(hFig); close(vidObj); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Hamming + Interleave Burst Noise Main Program %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear all close all clc %% To Generate New Data % bit_length = 8; % T = im2bits(imread('cameraman.tif'),bit_length); % save T % LOADING GENERATED DATA load('T.mat','T'); % T.bits contains columns of binary bits bits = T.bits; HE = Hamming_encode(bits); %% Add burst error noise_sigma_max = 0.35; samples = 100; 20
  • 22. % chance of burst sigma = linspace(0,noise_sigma_max,samples); % BACKUP OF BITS BEFORE INTERLEAVING HE.before_Tbits = HE.Tbits; % INTERLEAVING for zz = 1 : 7 HE.Tbits(zz,:) = circshift(HE.Tbits(zz,:)',20*zz)'; end % Looping through the noise for i=1:size(sigma,2) % Adding Noise for given sigma HEN(i).Tbits = burst_add(HE.Tbits,sigma(i)); % DE−INTERLEAVING for zz = 1 : 7 HEN(i).Rbits(zz,:) = circshift(HEN(i).Tbits(zz,:)',−20*zz)'; end R(i) = Hamming_decode(HEN(i).Rbits); sigma(i) % Find Bit Errors Err(i) = find_errors(HE.before_Tbits,R(i).Rbits); BER_actual(i) = Err(i).BER_actual; Err_after_corr(i) = find_errors(HE.before_Tbits,R(i).Corr_bits); BER_after_corr(i) = Err_after_corr(i).BER_actual; BER_corrected(i) = BER_actual(i) − BER_after_corr(i); end %% PLOT AND LABELS figure(1) plot(sigma,BER_actual,'b','LineWidth',2); hold on plot(sigma,BER_after_corr,'−−r','LineWidth',2); title('bf HAMMING 7,4 : BURST−INTERLEAVE NOISE VS BER','FontSize',18); xlabel('bf Noise Standard deviation ( sigma )','FontSize',16); ylabel('bf BER ','FontSize',16); h = legend('Actual BER','BER after Hamming correction',... 'Location','NorthWest'); set(h,'FontSize',16); hold off %% Reconstruct 21
  • 23. vidObj = VideoWriter('Hamming_Burst_Interleave_Simulation.avi'); vidObj.FrameRate = 6; open(vidObj); for l = 1:100 % Plotting the image after the bit correction by hamming code R_bits = Reconstruct_Hbits(R(l).Corr_bits); BIT_STREAM=((R_bits)); Im = bits2im(BIT_STREAM,[256 256]); hFig = figure(2); set(hFig, 'Position', [150 150 1000 600]) subplot(1,2,2) imshow(Im.image,[]); title('bf Image after Hamming correction','FontSize',16); % plotting the image before the correction by hamming code E_bits = Reconstruct_Hbits(HEN(l).Rbits); BIT_STREAM=((E_bits)); Im2 = bits2im(BIT_STREAM,[256 256]); subplot(1,2,1) title_string = sprintf('Noisy image before correction, Sigma = %f'... ,sigma(l)); imshow(Im2.image,[]); tt=title(title_string ,'FontSize',16); set(tt,'FontWeight','bold'); currFrame = getframe(hFig); writeVideo(vidObj,currFrame); end close(hFig); close(vidObj); 22
  • 24. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%% %% FUNCTIONS USED %%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% ADDS A PARITY BIT ACCORDING TO THE SPECIFIED SCHEME ( EVEN OR ODD ) function pbits = parity_add(bits,str) % Remainder vector for each column after dividing sum of the column by 2 R = mod(sum(bits),2); % Deciding the remainder based on the parity scheme if( strcmpi('even',str) ) pbits = [bits;R]; else pbits = [bits;~R]; % default is odd parity scheme end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% IMAGE TO BITS function T_Im = im2bits(I,bit_length) I = double(I); T_Im.size = size(I); Im = I(:); % BITS IN THE FORM OF CHARACTERS T_Im.bits_char = dec2bin(Im,bit_length); % CONVERTING CHARACTERS TO NUMBERS for j = 1:size(T_Im.bits_char,1) for i=1:bit_length T_Im.bits(i,j) = str2num(T_Im.bits_char(j,i)); end end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 23
  • 25. %% FUNCTION TO CONVERT THE RECEIVED BIT STREAM BACK TO ORIGINAL IMAGE % NOTE : BITS MUST BE A ROW VECTOR OF BINARY(0 or 1) IN CHAR DATATYPE function [R_Image] = bits2im(Bits,Image_size) bit_length = 8; % Image values go for 0−255 % Converting to a column vector of values for i=1:size(Bits,2) R_Image.bit_values(1,i) = 0; for j=1:8 R_Image.bit_values(1,i) = R_Image.bit_values(1,i)+ ... (Bits(j,i)*2^(8−j)); end end % Reshaping to the orginal image size R_Image.image = reshape((R_Image.bit_values),Image_size); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % ADDS ADDITIVE WHITE GAUSSIAN NOISE % CHOOSE A SCHEME (1|2) function [Rpbits] = add_awgn(pbits, sigma, scheme) %% SCHEME 1 : Defining pbits from −1 to +1 instead of 0 to 1 if(scheme == 1) temp_pbits = 2*pbits − ones(size(pbits)); temp_Rpbits = temp_pbits + sigma*randn(size(pbits)); Rpbits = zeros(size(temp_Rpbits)); Rpbits(find(temp_Rpbits>0)) = 1; end %% SCHEME 2 : Letting pbits from 0 to 1 if(scheme == 2) temp_Rpbits = pbits + sigma * randn(size(pbits)); temp_Rpbits(find(temp_Rpbits>1)) = 1; temp_Rpbits(find(temp_Rpbits<0)) = 0; temp_Rpbits = round(temp_Rpbits); Rpbits = temp_Rpbits; end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 24
  • 26. % ADDS A BURST NOISE TO A GIVEN DATA MATRIX function b_data = burst_add(bits_matrix, sigma) burst_min = 3; burst_max = 10; Msize = size(bits_matrix); bits = bits_matrix(:); % converting to a bit stream % Random locations to add burst b_prob = sigma * randn(size(bits,1)−burst_max−burst_min,1); b_prob(b_prob<0) = 0; b_prob(b_prob>1) = 1; b_prob = round(b_prob); sigma2 = 0.5; %Choosing a random length for burst in the min and max range length(b_prob==1) = randi(burst_max − (burst_min −1),... size(b_prob(b_prob==1),1),1 ) ... + ones(size(b_prob(b_prob==1),1),1) *burst_min − 1; for i=1:size(b_prob,1) if(b_prob(i) == 1) % If only few errors occurs in that burst, sigma =0.5 error = sigma2 + randn(length(i),1); error(error<0) = 0; error(error>1) = 1; error = round(error); % adding error to the bitstream bits(i:i+length(i)−1,1) = bits(i:i+length(i)−1,1) + error; end end % Getting the bits to binary bits = mod(bits,2); % Reshaping the bits back to its intial matrix form b_data = reshape(bits,Msize); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 25
  • 27. %% FIND THE BIT ERRORS BETWEEN TRANSMITTED AND RECEIVED BITS function Error = find_errors(T,R) Error.diff = abs(T − R); Error.symbol = sum(Error.diff); Error.total = sum(Error.symbol(:)); Error.total_words = size(find(Error.symbol>0),2); Error.BER_actual = 100*(Error.total/prod(size(T))); Error.BER_actual_words = 100*(Error.total_words/(size(T,2))); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% ADDS A 8−BIT CHECKSUM FOR EVERY 16 BITS function [pbits, summed] = checksum_add(bits) % Matirx size of the input bits rows = size(bits,1); cols = size(bits,2); % Converting all bits to decimals D = bits2im(bits,[1 cols]); Dec = D.image; % Summing adjacent columns to create a sum matrix sum = Dec(1:2:cols) + Dec(2:2:cols); % Restricting values to be 8bit sum = mod(sum,256); % Converting sum back to decimals sum = im2bits(sum,8); % Flipping all the bits summed = ~sum.bits; % Adding that sum column next to every two columns for i=1:1:size(summed,2) pbits(:,(3*i)−2:3*i) = [bits(:,(2*i)−1:2*i) summed(:,i)]; end 26
  • 28. end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% VERIFY THE CHECKSUM TO DETERMINE BIT ERRORS % Returns the checksum rows % If all of which are zero, implies no bit errors function [summed, total_errors, BER_crc] = checksum_check(bits) % Matrix size of the input bits rows = size(bits,1); cols = size(bits,2); % Converting all bits to decimals D = bits2im(bits,[1 cols]); Dec = D.image; % Summing and checking for all zeors summed = Dec(1,1:3:cols) + Dec(1,2:3:cols) + Dec(1,3:3:cols); summed = mod(summed,256); summed = mod(summed,255); % Finding the non−zero elements and classifying them as errors total_errors = size(summed(summed~=0),2); % BER For each 16 bit symbol BER_crc = 100*(total_errors/size(summed,2)); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% FIND THE BIT ERRORS BETWEEN TRANSMITTED AND RECEIVED BITS function Error = find_errors(T,R) Error.diff = abs(T − R); Error.symbol = sum(Error.diff); Error.symbol2 = Error.symbol(1:3:size(Error.symbol,2)) + ... Error.symbol(2:3:size(Error.symbol,2)) + ... Error.symbol(3:3:size(Error.symbol,2)); Error.total = sum(Error.symbol(:)); Error.total_words = size(find(Error.symbol>0),2); Error.total_CRC = size(find(Error.symbol2>0),2); Error.BER_actual = 100*(Error.total/prod(size(T))); 27
  • 29. Error.BER_actual_words = 100*(Error.total_words/(size(T,2))); Error.BER_CRC = 100*(Error.total_CRC/((size(T,2))/3)); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Hamming 7,4 Encoding function H = Hamming_encode(bits) % bits is a 8 row, many columns matrix % Define N and K for the Hamming Encoding 7,4 N = 7; K = 4; % Change the received data to 4bits in each column (for K = 4) H.new_data_bits = reshape(bits, K , size(bits,2) * (8/K) ) ; % Define G G = [ 1 1 0 1 ; 1 0 1 1 ; 1 0 0 0 ; 0 1 1 1 ; 0 1 0 0 ; 0 0 1 0 ; 0 0 0 1 ]; % Encoding the 3 parity bits for i = 1 : size(H.new_data_bits,2) H.Tbits(:,i) = G * H.new_data_bits(:,i); end H.Tbits = mod(H.Tbits,2); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Hamming 7,4 Decoding function R = Hamming_decode(HE_bits) % HE_bits is a 8 row, many columns matrix % Define N and K for the Hamming Encoding 7,4 % N = 7; % K = 4; % % % Change the received data to 4bits in each column (for K = 4) % H.new_data_bits = reshape(bits, K , size(bits,2) * (8/K) ) ; 28
  • 30. % Define H H = [ 1 0 1 0 1 0 1; 0 1 1 0 0 1 1; 0 0 0 1 1 1 1]; % Decoding for i = 1 : size(HE_bits,2) R.Ebits(:,i) = H * HE_bits(:,i); end R.Ebits = mod(R.Ebits,2); % CORRECTING % Gives error locations as in H % R.E_loc = (bin2dec(num2str(R.Ebits')))'; % TAKES TOO LONG for z=1:size(R.Ebits,2); R.E_loc(1,z) = 4*R.Ebits(1,z) + 2*R.Ebits(2,z) + 1*R.Ebits(3,z); end R.H_loc = (bin2dec(num2str(H')))'; % Defining Received bits with errors R.Rbits = HE_bits; R.Corr_bits = R.Rbits; for i = 1 : size(R.Rbits,2) R.Err_at(i) = 0; if(R.E_loc(i)) % Location of the bits (in row number) of where the error occured % in each column R.Err_at(i) = (find(R.H_loc == R.E_loc(i))); % Corrected bits R.Corr_bits(R.Err_at(i),i) = ~R.Corr_bits(R.Err_at(i),i); end end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % RECONSTRUCT FROM HAMMING ENCODE/DECODE % Reconstruct 8bit code from hamming output by removing parity bits and % reshaping 29
  • 31. function R_bits = Reconstruct_Hbits(bits) bits_2 = [bits(3,:); bits(5:7,:)]; R_bits = bits_2(:,1:2:end); R_bits = [R_bits; bits_2(:,2:2:end)]; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % HAMMING CODE IMPLEMENTATION ERROR function [ERR ] = H_error(HEN,R) samples = size(R,2); for j=1:samples ERR(i).xor = mod((R(j).Corr_bits .* ~HE.Tbits + ~R(j).Corr_bits ... .* HE.Tbits),2); end % TO VIEW EACH ERROR AND CORRECTION % for j=1:samples % clc % fprintf('Error at %.0f is : n n', j); % disp(R(j).Err_at); % fprintf('Correction is n n', j); % disp(mod((R(j).Corr_bits .* ~HE.Tbits + ~R(j).Corr_bits ... % .* HE.Tbits),2)); % pause % end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 30