The Wayback Machine - https://web.archive.org/web/20240605173905/https://www.geeksforgeeks.org/linear-block-code-using-matlab/
Open In App

Linear Block Code using MATLAB

Last Updated : 05 Sep, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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


Similar Reads

8085 Program to Copy a Source Block to Destination Block with Overlapping Memory Address
The task is to copy the data from some source block to some destination block given that the destination block has an overlapping memory address with the source block. Data cannot just simply be moved from source block to destination block because the destination block is having an overlapping memory address, it could lead to overriding of data and
5 min read
What is a Signature Block? How to Create Signature Block
A Signature block is a personalized section of text that automatically appears at the bottom of emails, articles, documents, or contracts. It typically includes the sender's or author's details such as their name, position, and contact information. The primary purpose of a signature block is to help recipients identify the sender or author, making
6 min read
Try and Catch Block in MATLAB
Exception Handling is a mechanism used to resolve/handle Runtime errors that arise during the execution of a program. Most programming languages offer some level of exception handling to deal with errors that arise while the program is executing. Exception handling deals with these events to avoid the program or system crashing, and without this pr
3 min read
Linear Convolution using C and MATLAB
A key concept often introduced to those pursuing electronics engineering is Linear Convolution. This is a crucial component of Digital Signal Processing and Signals and Systems. Keeping general interest and academic implications in mind, this article introduces the concept and its applications and implements it using C and MATLAB. Convolution: When
8 min read
How to Linear Filtering Without Using Imfilter Function in MATLAB?
Edges can be sharpened, random noise can be reduced, and uneven illuminations can be corrected using a linear filtering technique. Correlating the image with the proper filter kernel completes the process. The imfilter function calculates the value of each output pixel using double-precision floating-point arithmetic. If the result is outside the d
3 min read
Difference Between Linear Block Codes and Convolutional Codes
Information theory is a branch of probability theory that terms of error probability. An errorless transmission is possible when the probability of error at the receiver approaches 0. It is the numerical computation of the ideas, boundaries, and rules ruling the transmission of messages through communication systems. The information theory is relat
4 min read
Solution of system of linear equation in MATLAB
Let us see how to solve a system of linear equations in MATLAB. Here are the various operators that we will be deploying to execute our task : \ operator : A \ B is the matrix division of A into B, which is roughly the same as INV(A) * B. If A is an NXN matrix and B is a column vector with N components or a matrix with several such columns, then X
7 min read
Linear Interpolation in MATLAB
Interpolation is a numerical method of finding new data points by finding a pattern in a given set of discrete data points. There are various types and methods of interpolation in the field of Numerical Analysis such as linear interpolation, cubic interpolation, spline interpolation, etc. The key point to be noted when interpolating is that this me
3 min read
Uniquely Decodable Code using MATLAB
A code is distinct if each codeword is recognizable from every other (i.e., the planning from source messages to codewords is coordinated). A distinct code is extraordinarily decodable if each codeword is recognizable when drenched in a grouping of codewords or if the first source arrangement can be remade consummately from the encoded binary seque
3 min read
Set Breakpoints for Debugging MATLAB Code
MATLAB is one of the most powerful coding languages.MATLAB stands for Matrix Laboratory. It is a high-performance language that is used for technical computing. It was developed by Cleve Molar of the company MathWorks.Inc in the year 1984. It is written in C, C++, Java. It allows matrix manipulations, plotting of functions, implementation of algori
3 min read
Article Tags :