Sie sind auf Seite 1von 11

IMPLEMENTATION OF HAMMING CODE USING

VERILOG
ABSTACT – In digital communication while transmitting the data from source to destination
some corruption in data occurs due to some environmental conditions, which is nothing but
the transmitted data is included with some errors. Error coding is the method to detect and
correct these errors so that the information is transferred without any errors from source to
destination. There are many error detecting and correcting codes, one of such is Hamming
code. Hamming code is single bit error detecting and correcting method. In this paper we are
going to discuss about the implementation of Hamming code in verilog module which is
improved version of previous existing technique. Both the techniques are implemented with
the help of redundancy bits (does not carry information). The advantage of improved
technique over the previous technique is there is decrease in the usage of bits while
calculating the values redundancy bits.

Keywords – Hamming code, Encoder, Decoder, Error detector and corrector, Verilog HDL,
Xilinx

INTRODUCTION

In digital communication systems, environmental effects and other defects can cause random
bit errors during data transmission. Digital data is transmitted over a channel and there should
be a noise present in the channel. The noise may distort the data that is transmitting.
Therefore, the data received by the receiver is not same as the data that is transmitted by the
transmitter, so error detection and correction plays an important role so that the information is
transferred without any errors.

ERROR : The encoded data is usually transmitted over a channel is not completely error
free. Due to the external interference, signal distortion, attenuation and noise in channel the
manipulation of data occurs. The manipulated data is called as error. There are two types of
errors.

1. Single bit error


2. Burst error (more than one error in data).
ERROR DETECTION AND CORRECTION :

The phenomenon of detecting the position of error from the received data is known as error
detection. The process of correcting the bit value at that error position is nothing but error
correction. There are various error detecting and correcting methods such as cyclic
redundancy check (CRC), Parity check, Vertical redundancy check (VRC), Longitudinal
redundancy check (LRC) and Hamming code. This work mainly focuses on Hamming code.

HAMMING CODE

Hamming code is a linear block code. Hamming code can detect up to 2 bit errors and correct
can correct a single bit error. Hamming code includes encoding, error detection and
correction and decoding. Encoding provides the encryption of data by adding redundancy
bits to the data. The number of redundancy bits required are calculated using the formula

2^r >= d + r + 1 …………. (1).

Where r = number of redundancy bits.

d = number of data bits.

The smallest value of ‘r’ that satisfies the above relation is considered as the number of
required redundancy bits. Encoded data of length d + r bits is transmitted. In the receiving
side, the presence and location of single bit error is determined by calculating the parities of
combinations of received data to produce a table of parities each of which corresponds to a
particular bit error combination. Now the value present in this error position is complimented
so that the error is removed. Now this error free encoded data is decoded to get the original
information data. Hamming codes are easy to implement and are used in telecommunication,
and other applications including data compression. They are also used for low cost and low
power applications.

PREVIOUS METHOD

ENCODING OF HAMMING CODE :

Here the information data of length d bits that is to be transmitted is encoded with the
addition of redundancy bits (r) required to correct d data bits. So a total of d + r bits are
transmitted. Here r value is determined by using the formula 2^r >= d + r + 1. Here each r bit
is extra bit that does not carry information. These redundancy bits are added at 2^r positions
that is 1, 2, 4 and 8 so on. For example, let us take a 7 bit data to be transmitted, so that the
value of r that satisfies the above condition (1) is 4. So total 7+4=11 bits are to be
transmitted. Let us take the 4 redundancy bits are r1, r2, r3 and r4. Each r bit is parity bit for
one combination of data bits as shown below:

r1 - 1, 3, 5, 7, 9, 11 ……….. (a) r2 - 2, 3, 6, 7, 9, 10, 11 ………. (b)

r3 – 4, 5, 6, 7 ……….. (c) r4 – 8, 9, 10, 11 ……….. (d)

11 10 9 8 7 6 5 4 3 2 1

d7 d6 d5 r4 d4 d3 d2 r3 d1 r2 r1
Position of redundancy bits in hamming code

Here the d1 to d7 are data bits to be transmitted and r1 to r4 are redundancy bits. Let the data
be 1100110. Now the values of r1, r2, r3 and r4 are calculated based on the even parity
condition for those positions given in (a), (b), (c) and (d) respectively.

Since the number of 1’s at positions 3, 5, 7, 9, 11 is 2. It satisfies the even parity condition, so
the required value of r1 is ‘0’. Since the number of 1’s at positions 3, 6, 7, 10, 11 is 3. It does
not satisfies the even parity condition, so the required value of r2 is ‘1’. Since the number of
1’s at positions 5, 6, 7 is 2. It satisfies the even parity condition, so the required value of r3 is
‘0’. Since the number of 1’s at positions 9, 10, 11 is 2. It satisfies the even parity condition,
so the required value of r4 is ‘0’. So the encoded data obtained is “11000110010”.

ERROR DETECTION, CORRECTION AND DECODING :

If there is any error in received data here we need to detect and correct. Here the error
position is indentified with the help of c3 c2 c1 c0 whose values obtained after checking the
even parity condition by considering the parity of the bit positions as given in (a), (b), (c) and
(d). Now let the received data is “11001110010”, which has error at position 7 by comparing
with above obtained encoded data. Now the values of c3, c2, c1 and c0 are calculated as
follows:

Since the number of 1’s at positions 1, 3, 5, 7, 9, 11 is 3. It does not satisfies the even parity
condition, so the required value of c0 is ‘1’. Since the number of 1’s at positions 2, 3, 6, 7,
10, 11 is 5. It does not satisfies the even parity condition, so the required value of c1 is ‘1’.
Since the number of 1’s at positions 4, 5, 6, 7 is 1. It does not satisfies the even parity
condition, so the required value of c2 is ‘1’. Since the number of 1’s at positions 8, 9, 10, 11
is 2. It satisfies the even parity condition, so the required value of c3 is ‘0’. Now the error
position is identified with help of c3 c2 c1 c0 as shown below:

Error position C3 C2 C1 C0

7 0 1 1 1

Now the value at this position 7 is to be complimented so that the error can be corrected. So
that we can get the original encoded data. Now this data is to be decoded to get the original
information data without any errors.

PRESENT TECHNIQUE

This process is also similar to previous technique at the same steps including encoding, error
detection and correction, decoding. But the only difference is in the previous technique
redundancy bit positions are taken at 2^r positions, where as in this proposed improved
method the redundancy bit positions are taken at the end of the data. In the previous
technique a total of 20 bits are involved in the process of calculation of redundancy bits,
where as in this proposed improved method a total of 19 bits are involved in the process of
calculations of redundancy bits. This is the advantage of this proposed method over the
previous method where there is a reduction in the usage of 1 bit.

ENCODING :

Similar to previous technique here the data bits(d) are encoded with redundancy bits(r) that
are to be transmitted. Here the value of r is obtained by using the formula

2^r >= d+r+1 ….. (1)

Where r = number of redundancy bits

d = number of data bits

Let us consider the same example, The 7-bit data to be transmitted is “0110010”. For this the
smallest value of r that satisfies the above condition (1) is 4. So a total of 11-bit encoded data
is transmitted. Here let us consider r1, r2, r3 and r4 as 4 redundancy bits. Each r bit is parity
bit for one combination of data bits as shown below:

r1 - 1, 3, 5, 7 ……….. (a) r2 - 2, 3, 6, 7 ………. (b)

r3 – 4, 5, 6, 7 ….……... (c) r4 – r1, r2, r3 ……….. (d)

11 10 9 8 7 6 5 4 3 2 1

r4 r3 r2 r1 d7 d6 d5 d4 d3 d2 d1
Position of redundancy bits in hamming code

Here in this table the d1 to d7 are data bits to be transmitted and r1 to r4 are redundancy bits.
Now the values of r1, r2, r3 and r4 are calculated based on the even parity condition for those
positions given in (a), (b), (c) and (d) respectively.

Since the number of 1’s at positions 1, 3, 5, 7, 9, 11 is 1. It does not satisfies the even parity
condition, so the required value of r1 is ‘1’. Since the number of 1’s at positions 2, 3, 6, 7 is
2. It satisfies the even parity condition, so the required value of r2 is ‘0’. Since the number of
1’s at positions 4, 5, 6, 7 is 2. It satisfies the even parity condition, so the required value of r3
is ‘0’. Since the number of 1’s at positions 8, 9, 10 is 1. It does not satisfies the even parity
condition, so the required value of r4 is ‘1’. So the encoded data obtained is “10010110010”.

Fig : Hamming encoder

ERROR DETECTION,CORRECTION AND DECODING :

If there is any error in received data here we need to detect and correct. Here the error
position is indentified with the help of c3 c2 c1 c0 whose values obtained after checking the
even parity condition by considering the parity of the bit positions as given in (a), (b), (c) and
(d). Now let the received data is “10010100010”, which has error at position 5 by comparing
with above obtained encoded data. Now the values of c3, c2, c1 and c0 are calculated as
follows:

Since the number of 1’s at positions 1, 3, 5, 7, 8 is 1. It does not satisfies the even parity
condition, so the required value of c0 is ‘1’. Since the number of 1’s at positions 2, 3, 6, 7, 9
is 2. It satisfies the even parity condition, so the required value of c1 is ‘0’. Since the number
of 1’s at positions 4, 5, 6, 7, 10 is 1. It does not satisfies the even parity condition, so the
required value of c2 is ‘1’. Since the number of 1’s at positions 8, 9, 10, 11 is 2. It satisfies
the even parity condition, so the required value of c3 is ‘0’. Now the error position is
identified with help of c3 c2 c1 c0 as shown below:

Error position C3 C2 C1 C0

5 0 1 0 1

Now the value at this position 5 is to be complimented so that the error can be corrected. So
that we can get the original encoded data. Now the 11-bit encoded data is to be decoded to
get the original 7-bit information data without any errors.

Fig : Hamming decoder

NOTE :

If we get error at positions 8, 9, 10 or 11. It can noit able to detect the correct position. Since
the bits at these positions are redundancy bits which are just used for the purpose of encoding
and to provide help for error detecting in the original information data, they does not carry
any information. So it is not necessary to detect and correct the errors at these redundancy
positions. It is briefly explained here with an table.
11 10 9 8 7 6 5 4 3 2 1 C3 C2 C1 C0 ERRORPOSITION

1 0 0 0 0 1 1 0 0 1 0 F T T F Error in redundancy
bit 8

1 0 0 1 0 1 1 0 0 1 0 T T T T No error

Table 2.31 : Encoded data with error at different positions

Suppose the received information is 10000110010, with an error at redundancy bit position 8.
Then the status of parity check will turn out to be FTTF. [‘F’ indicates bit ‘1’ and ‘T’
indicates ‘0’] If status of parity check is FXXX, it implies that there is an error only in a
redundancy bit. The actual redundancy bit in error can easily be identified by the position of
the occurrence of F. However, this is not a data bit there is no need for any correction.
Suppose the received information is 10010110010, with no error. Then the status of parity
check will turn out to be TTTT, implying error at bit position 0000 i.e. 0. This is treated as no
error.
RESULTS
Simulation Results :

Fig :Simulation results of encoder


The above figure shows the simulation waveforms of Hamming encoder(7-bit to 11-bit).
Here copy[7:1] indicates the input data (information data) which is to be encoded. copy[11:1]
indicates the encoded output data which is to be transmitted. Here the 7-bit data “0110010” is
given as input data and the obtained 11-bit data is “10010110010”.

Fig : Simulation results of Error position detector

The above figure shows the simulation waveforms of error position detector. Here copy[11:1]
indicates received encoded data with error at one position and y[4:1] indicates the position of
error. Here 11-bit data is “10010100010” is given as input which have error at position “5”.
The output data “0101” indicates the error at position “5”.

Fig :Simulation results of Error position correction

The above figure shows the simulation waveforms of error position correction. Here i0[10:0]
indicates the original encoded data and i1[11:1] indicates the encoded data with error at one
position and d[10:0] indicates the original encoded data after correcting the error present in
the data i1[11:1]. Here the input data i0[11:1] = “10010110010” and i1[11:1] =
“10010100010” and the output data d[10:0] = “10010110010”.

Fig : Simulation waveforms for decoder

The above figure shows the simulation waveforms of Hamming decoder. Here copy1[11:1]
indicates the encoded data and copy[7:1] indicates the original information data after
decoding the encoded data. Here the 11-bit data “10010110010” is the encoded input data
and the 7-bit data “0110010” is the obtained original information data.

CONCLUSION

In this proposed method the redundancy bits are placed at the end of the data bits. This
method has the advantage of reducing the usage of bits for the calculation of redundancy bits.
Here we are using 19 bits for calculation of redundancy bits while in previous method we
used 20 bits and it includes the advantage that there is no position change of information data
during the entire process and it is easy to remove (decode) the redundancy bits from the
encoded data. So that large number of data can be easily transmitted, corrected and decoded.
It is used only for single bit error correction. Because of these features this method is most
suitable than the previous existing method.

REFERENCES

[1] W. W. Peterson and E. J. Weldon, Jr., Error-Correcting Codes (2nd ed.). Cambridge, MA:
MIT Press, 1972.
[2] T. Fujiwara et al., “Error Detecting Capabilities of the Shortened Hamming Codes
Adopted for Error Detection in IEEE Standard 802.3,” IEEE Trans. Communications, vol. 37,
no. 9, pp. 986–989, Sep 1989.
[3] W. Xiong, and D. W. Matolak, “Performance of Hamming Codes in Systems Employing
Different Code Symbol Energies,” IEEE Communications Society, pp. 1055–1058 [Wireless
and Communications and Networking Conference (WCNC)].
[4] Xilinx “Spartan-3 FPGA Family, complete datasheet”, Xilinx Corp., Aug 2005.
[5] Xilinx “Synthesis and Simulation Design Guide”, Xilinx Tech UG626 2012.
[6] Leena, Mr. Subham Gandhi and Mr. Jitender Khurana, “Implementing (7,4) Hamming
Code using CPLD on VHDL” International Journal of New Trends in Electronics , Vol. 1,
Issue 1, Aug. 2013.

Das könnte Ihnen auch gefallen