0% found this document useful (0 votes)
5 views3 pages

Digital (Exp - 11)

The document outlines an experiment to study the encoding and decoding of linear block codes, specifically the (7,4) Hamming Code. It details the use of generator and parity-check matrices for encoding and error detection, demonstrating the process through MATLAB code. The experiment successfully illustrates single-bit error correction and retrieval of the original message.

Uploaded by

amritapandey0424
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Digital (Exp - 11)

The document outlines an experiment to study the encoding and decoding of linear block codes, specifically the (7,4) Hamming Code. It details the use of generator and parity-check matrices for encoding and error detection, demonstrating the process through MATLAB code. The experiment successfully illustrates single-bit error correction and retrieval of the original message.

Uploaded by

amritapandey0424
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Experiment - 11

Aim:
To study encoding and decoding of linear block codes.

Theory:
Linear block codes are a category of error-correcting codes commonly used in digital communication systems. A

linear block code is denoted as (n, k), where k represents the number of data bits and n is the total number of bits

in the codeword after adding redundancy for error correction.

The (7,4) Hamming Code is a classic example that takes 4 data bits and encodes them into 7-bit codewords

by appending 3 parity bits. It has the capability to detect up to two-bit errors and correct one-bit errors.

Encoding is performed using a Generator Matrix (G), and decoding uses a Parity-Check Matrix (H) to compute

the syndrome. The syndrome helps to identify and correct the position of any single-bit error in the codeword.

MATLAB Code:
clc;
clear;

% Generator matrix G for (7,4) Hamming Code


G = [1 0 0 0 1 1 0;
0 1 0 0 1 0 1;
0 0 1 0 0 1 1;
0 0 0 1 1 1 1];

% Parity-check matrix H
H = [1 1 0 1 1 0 0;
1 0 1 1 0 1 0;
0 1 1 1 0 0 1];

% Input 4-bit message


msg = [1 0 1 1]; % You can change this input

% Encoding
codeword = mod(msg * G, 2);
disp('Encoded Codeword:');
disp(codeword);

% Simulate an error in transmission (introducing a single-bit error)


received = codeword;
received(3) = mod(received(3) + 1, 2); % Introducing error at 3rd bit
disp('Received Codeword with Error:');
disp(received);

% Syndrome calculation
syndrome = mod(H * received', 2);
disp('Syndrome:');
disp(syndrome');

% Find error position using syndrome


syndrome_decimal = bi2de(syndrome', 'left-msb');
if syndrome_decimal ~= 0
fprintf('Error detected at position: %d\n', syndrome_decimal);
received(syndrome_decimal) = mod(received(syndrome_decimal) + 1, 2);
disp('Corrected Codeword:');
disp(received);
else
disp('No error detected.');
end

% Decoding (Extract original message)


decoded_msg = received(1:4);
disp('Decoded Message:');
disp(decoded_msg);

Output:
Encoded Codeword:
1 0 1 1 0 0 1

Received Codeword with Error:


1 0 0 1 0 0 1

Syndrome:
1 1 0

Error detected at position: 3

Corrected Codeword:
1 0 1 1 0 0 1

Decoded Message:
1 0 1 1

Observations:
- The encoded 7-bit codeword correctly incorporates parity for error detection and correction.

- A single-bit error was introduced during transmission.


- The syndrome detected the error and identified its position.

- The error was successfully corrected, and the original message was accurately retrieved.

Conclusion:

The (7,4) Hamming Code effectively encodes 4-bit messages into 7-bit codewords, allowing for single-bit

error correction. Using generator and parity-check matrices in MATLAB, the experiment demonstrates

successful encoding, error detection, correction, and decoding.

You might also like