0% found this document useful (0 votes)
3 views

hammimng code

The document explains Forward Error Correction using Hamming code, which allows the receiver to detect and correct errors using parity bits. It details the algorithm for determining bit positions, the role of parity bits, and includes a C program for encoding and error detection. Additionally, it describes the Stop and Wait Protocol, a flow control method where the sender transmits one frame at a time and waits for an acknowledgment before sending the next frame.

Uploaded by

s.mishra
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

hammimng code

The document explains Forward Error Correction using Hamming code, which allows the receiver to detect and correct errors using parity bits. It details the algorithm for determining bit positions, the role of parity bits, and includes a C program for encoding and error detection. Additionally, it describes the Stop and Wait Protocol, a flow control method where the sender transmits one frame at a time and waits for an acknowledgment before sending the next frame.

Uploaded by

s.mishra
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

In Forward Error correction the code set is so designed that it is possible for the receiver to detect

and correct error as well by itself. Hamming code is a set of error-correction codes that can be used
to detect and correct the errors that can occur when the data is moved or stored from the sender to
the receiver. General Algorithm of Hamming code – The Hamming Code is the use of extra parity bits
to allow the identification of an error.

1. Write the bit positions starting from 1 in binary form (1, 10, 11, 100, etc).

2. All the bit positions that are a power of 2 are marked as parity bits (1, 2, 4, 8, etc).

3. All the other bit positions are marked as data bits.

4. Each data bit is included in a unique set of parity bits, as determined its bit pos

position in binary form.

• Parity bit 1 covers all the bits positions whose binary representation includes a 1 in the least
significant position (1, 3, 5, 7, 9, 11, etc).

• Parity bit 2 covers all the bits positions whose binary representation includes a 1 in the second
position from the least significant bit (2, 3, 6, 7, 10, 11, etc).

• Parity bit 4 covers all the bits positions whose binary representation includes a 1 in the third
position from the least significant bit (4–7, 12–15, 20–23, etc).

• Parity bit 8 covers all the bits positions whose binary representation includes a 1 in the fourth
position from the least significant bit bits (8–15, 24–31, 40–47, etc

• In general each parity bit covers all bits where the bitwise AND of the parity position and the bit
position is non-zero. Parity check is done for even parity, hence set a parity bit to 1 if the total
number of ones in the positions it checks is odd. Set a parity bit to 0 if the total number of ones in
the positions it checks is even.

Determining the position of redundant bits –


redundancy bits are placed at the positions which correspond to the power of 2. As in the above
example
1. The number of data bits = 7
2. The number of redundant bits = 4
3. The total number of bits = 11
4. The redundant bits are placed at positions corresponding to power of 2 ie.. 1, 2, 4, and 8
#include<stdio.h>
#include <conio.h>
void main()
{
int data[7],rec[7],i,c1,c2,c3,c;
printf("this works for message of 4bits in size \nenter message bit one by one: ");
scanf("%d%d%d%d",&data[0],&data[1],&data[2],&data[4]);
data[6]=data[0]^data[2]^data[4];
data[5]=data[0]^data[1]^data[4];
data[3]=data[0]^data[1]^data[2];
printf("\nthe encoded bits are given below: \n");
for (i=0;i<7;i++) {
scanf("%d",&rec[i]);
}
c1=rec[6]^rec[4]^rec[2]^rec[0];
c2=rec[5]^rec[4]^rec[1]^rec[0];
c3=rec[3]^rec[2]^rec[1]^rec[0];
c=c3*4+c2*2+c1 ;
if(c==0) {
printf("\ncongratulations there is no error: ");
} else {
printf("\nerron on the postion: %d\nthe correct message is \n",c);
if(rec[7-c]==0)
rec[7-c]=1; else
rec[7-c]=0;
for (i=0;i<7;i++) {
printf("%d ",rec[i]);
}
}
getch();
}
What is the Stop and Wait
Protocol
is the simplest flow control method. In this, the sender will transmit one frame at a time to the
receiver. The sender will stop and wait for the acknowledgement from the receiver.

This time (i.e. the time joining message transmitting and acknowledgement receiving) is the
sender’s waiting time, and the sender is idle during this time.

When the sender gets the acknowledgement (ACK), it will send the next data packet to the
receiver and wait for the disclosure again, and this process will continue as long as the sender
has the data to send.

While sending the data from the sender to the receiver, the data flow needs to be controlled.
If the sender is transmitting the data at a rate higher than the receiver can receive and
process it, the data will get lost.

The Flow-control methods will help in ensuring that the data doesn't get lost. The flow control
method will check that the senders send the data only at a rate that the receiver can receive
and process. The working of Stop and Wait Protocol is shown in the figure b below:
#include<stdio.h>
int sender();
int recv();
int timer=0,wait_for_ack=-1,frameQ=0,cansend=1,t=0;
main()
{
int i,j;
int frame[5];

printf("enter the time when data frame will be ready\n");


for(j=0;j<3;j++)
{
sender( i,frame[]);
recv(i);
}

sender(int i,int frame[])


{
wait_for_ack++;
if(wait_for_ack==3)
{

if(i==frame[t])
{
frameQ++;
t++;
}

if(frameQ==0)
printf("NO FRAME TO SEND at time=%d \n",i);

if(frameQ>0 && cansend==1)

{
printf("FRAME SEND AT TIME=%d\n",i);
cansend=-1;
frameQ--;
timer++;
printf("timer in sender=%d\n",timer);
}
if(frameQ>0 && cansend==-1)
printf("FRAME IN Q FOR TRANSMISSION AT TIME=%d\n",i);
if(frameQ>0)
t++;
}
printf("frameQ=%d\n",frameQ);
printf("i=%d t=%d\n",i,t);
printf("value in frame=%d\n",frame[t]);
return 0;
}

int recv(int i )

{ printf("timer in recvr=%d\n",timer);
if(timer>0)
{
timer++;
}
if(timer==3)
{
printf("FRAME ARRIVED AT TIME= %d\n",i);
wait_for_ack=0;
timer=0;
}
else
printf("WAITING FOR FRAME AT TIME %d\n",i);
return 0;

}
}

You might also like