Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

Linear Block Code using MATLAB

  • Last Updated : 05 Sep, 2020

Any linear blend of codewords is likewise a code word only. So in coding, a linear code is a mistake correcting code. Linear codes are generally partitioned into block codes and convolutional codes, despite the fact that turbo codes can be viewed as a half breed of these two sorts. Linear codes take into account more productive encoding and deciphering calculations than different codes.

Linear codes are utilized in forward mistake adjustment and are applied in methods for techniques for sending symbols (e.g., bits) on a communications channel so that, if mistakes occur in the communication, some mistakes can be amended or recognized by the beneficiary of a message block. The code words in a linear block code are blocks of symbols that are encoded utilizing a greater number of symbols than the first incentive to be sent.  

Let us see the MATLAB code for Linear Block Code.




% Given H Matrix
H = [1 0 1 1 1 0 0;
     1 1 0 1 0 1 0;
     0 1 1 1 0 0 1]
  
k = 4;
n = 7;
  
% Generating G Matrix
  
% Taking the H Matrix Transpose
P = H';  
  
% Making a copy of H Transpose Matrix
L = P;  
  
% Taking the last 4 rows of L and storing
L((5:7), : ) = [];  
  
% Creating a Identity matrix of size K x K
I = eye(k);  
  
% Making a 4 x 7 Matrix
G = [I L]  
  
% Generate U data vector, denoting all information sequences
no = 2 ^ k
  
% Iterate through an Unit-Spaced Vector
for i = 1 : 2^k  
  
  % Iterate through Vector with Specified Increment 
  % or in simple words here we are decrementing 4 till we get 1    
  for j = k : -1 : 1 
    if rem(i - 1, 2 ^ (-j + k + 1)) >= 2 ^ (-j + k)
      u(i, j) = 1;
    else
      u(i, j) = 0;
    end
      
    % To avoid displaying each iteration/loop value
    echo off; 
  end
end
  
echo on;
u
  
% Generate CodeWords
c = rem(u * G, 2)
  
% Find the min distance
w_min = min(sum((c(2 : 2^k, :))'))
  
% Given Received codeword
r = [0 0 0 1 0 0 0];
r
  
p = [G(:, n - k + 2 : n)];
  
%Find Syndrome
ht = transpose(H)
  
s = rem(r * ht, 2)
  
for i = 1 : 1 : size(ht)
  if(ht(i,1:3)==s)
    r(i) = 1-r(i);
    break;
  end
end
  
disp('The Error is in bit:')
disp(i)
  
disp('The Corrected Codeword is :')
disp(r)

Output:

H =

   1   0   1   1   1   0   0
   1   1   0   1   0   1   0
   0   1   1   1   0   0   1

G =

   1   0   0   0   1   1   0
   0   1   0   0   0   1   1
   0   0   1   0   1   0   1
   0   0   0   1   1   1   1

no =  16
u =

   0   0   0   0
   0   0   0   1
   0   0   1   0
   0   0   1   1
   0   1   0   0
   0   1   0   1
   0   1   1   0
   0   1   1   1
   1   0   0   0
   1   0   0   1
   1   0   1   0
   1   0   1   1
   1   1   0   0
   1   1   0   1
   1   1   1   0
   1   1   1   1

c =

   0   0   0   0   0   0   0
   0   0   0   1   1   1   1
   0   0   1   0   1   0   1
   0   0   1   1   0   1   0
   0   1   0   0   0   1   1
   0   1   0   1   1   0   0
   0   1   1   0   1   1   0
   0   1   1   1   0   0   1
   1   0   0   0   1   1   0
   1   0   0   1   0   0   1
   1   0   1   0   0   1   1
   1   0   1   1   1   0   0
   1   1   0   0   1   0   1
   1   1   0   1   0   1   0
   1   1   1   0   0   0   0
   1   1   1   1   1   1   1

w_min =  3

r
r =

   0   0   0   1   0   0   0

ht =

   1   1   0
   0   1   1
   1   0   1
   1   1   1
   1   0   0
   0   1   0
   0   0   1


s =

   1   1   1


The Error is in bit:
 4

The Corrected Codeword is :
   0   0   0   0   0   0   0



My Personal Notes arrow_drop_up
Recommended Articles
Page :