KEMBAR78
Error Correcting and Error Detecting Codes.pptx
Error Correcting and Error
Detecting Codes
Dr. Sudhanshu Janwadkar, Asst Professor, ITNU
Error Correcting Codes
 Hamming Code
 Binary Convolutional Code
 Reed-Solomon Code
 Low Density Parity Check Code
Hamming Code
 Hamming code is an error-correcting code used to ensure
data accuracy during transmission or storage.
 Hamming code detects and corrects the errors that can occur
when the data is moved from the sender to the receiver.
 What are Redundant bits?
 Extra binary bits that are generated and added to the information-
carrying bits of data transfer to ensure that no bits were lost during
the data transfer.
 The number of redundant bits can be calculated using the following
formula:
2r
≥ m + r + 1
 Calculate the number of redundant bits, if the number of
data bits is 7.
 24
≥ 7 + 4 + 1 .Thus, the number of redundant bits is 4.
Parity Bits
 A parity bit is a bit appended to a data of binary bits to ensure that the total
number of 1’s in the data is even or odd.
 Parity bits are used for error detection.
 There are two types of parity bits:
 Even Parity Bit: In the case of even parity, for a given set of bits, the number of
1’s are counted.
 If that count is odd, the parity bit value is set to 1, making the total count of
occurrences of 1’s an even number.
 If the total number of 1’s in a given set of bits is already even, the parity bit’s value is 0.
 Odd Parity Bit: In the case of odd parity, for a given set of bits, the number of
1’s are counted.
 If that count is even, the parity bit value is set to 1, making the total count of
occurrences of 1’s an odd number.
 If the total number of 1’s in a given set of bits is already odd, the parity bit’s value is 0.
Algorithm of Hamming Code
 Step 1:Write the bit positions starting from 1 in binary form (1, 10, 11, 100,
etc).
 Step 2:All the bit positions that are a power of 2 are marked as parity bits
(1, 2, 4, 8, etc).
 Step 3:All the other bit positions are marked as data bits.
 Step 4: Each data bit is included in a unique set of parity bits, as determined
its bit position in binary form:
 a. 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).
 b. 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).
 c. 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).And
so on…
 Step 5: Since we check for even parity 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.
Example
 Suppose the data to be transmitted is 1011001 from
sender to receiver, the bits will be placed as follows:
 The number of data bits = 7
 The number of redundant bits = 4
 The total number of bits = 7+4=>11
 The redundant bits are placed at positions corresponding to
power of 2 that is 1, 2, 4, and 8
 R1 bit is calculated using parity check at all the bits positions
whose binary representation includes a 1 in the least
significant position. R1: bits 1, 3, 5, 7, 9, 11
 To find the redundant bit R1, we check for even parity. Since
the total number of 1’s in all the bit positions corresponding
to R1 is an even number. So, the value of R1 (parity bit’s value)
= 0.
 R2 bit is calculated using parity check at all the bits positions
whose binary representation includes a 1 in the second
position from the least significant bit. R2: bits 2,3,6,7,10,11
 To find the redundant bit R2, we check for even parity. Since
the total number of 1’s in all the bit positions corresponding
to R2 is odd the value of R2(parity bit’s value)=1
 R4 bit is calculated using parity check at all the bits positions
whose binary representation includes a 1 in the third position
from the least significant bit. R4: bits 4, 5, 6, 7
 To find the redundant bit R4, we check for even parity. Since
the total number of 1’s in all the bit positions corresponding
to R4 is odd so the value of R4(parity bit’s value) = 1
 R8 bit is calculated using parity check at all the bits positions
whose binary representation includes a 1 in the fourth
position from the least significant bit. R8: bit 8,9,10,11
 To find the redundant bit R8, we check for even parity. Since
the total number of 1’s in all the bit positions corresponding
to R8 is an even number the value of R8(parity bit’s value)=0.
 Thus, the data transferred is:
Error Detection and Correction
 Suppose in the above example the 6th bit is changed from 0 to
1 during data transmission, then it gives new parity values in
the binary number:
 For all the parity bits we will check the number of 1’s in their
respective bit positions.
 For R1: bits 1, 3, 5, 7, 9, 11. We can see that the number of 1’s in
these bit positions are 4 and that’s even so we get a 0 for this.
 For R2: bits 2,3,6,7,10,11 . We can see that the number of 1’s in
these bit positions are 5 and that’s odd so we get a 1 for this.
 For R4: bits 4, 5, 6, 7 .We can see that the number of 1’s in these bit
positions are 3 and that’s odd so we get a 1 for this.
 For R8: bit 8,9,10,11 .We can see that the number of 1’s in these bit
positions are 2 and that’s even so we get a 0 for this.
 The bits give the binary number 0110 whose decimal
representation is 6. Thus, bit 6 contains an error. To correct
the error the 6th bit is changed from 1 to 0.
Binary Convolutional Codes
 In convolutional codes, the message comprises of data streams of
arbitrary length and a sequence of output bits are generated by
the sliding application of Boolean functions to the data stream.
 In block codes, the data comprises of a block of data of a definite
length.
 In convolutional codes, the input data bits are not divided into
block but are instead fed as streams of data bits, which convolve
to output bits based upon the logic function of the encoder.
 Also, unlike block codes, where the output codeword is
dependent only on the present inputs, in convolutional codes,
output stream depends not only the present input bits but also
only previous input bits stored in memory.
 Hamming distances are valuable for understanding block
codes.
 Convolutional code is not a block code.
 In a convolutional code, an encoder processes a sequence
of input bits and generates a sequence of output bits.
 There is no natural message size or encoding boundary as
in a block code.
 The output depends on the current and previous input
bits.That is, the encoder has memory.
 The number of previous bits on which the output
depends is called the constraint length of the code.
Generating a convolutional code
 The information is passed sequentially through a linear finite-
state shift register.
 A convolutional code can be represented as (n, k, K) where
 k is the number of bits shifted into the encoder at one time.
Generally, k = 1.
 n is the number of encoder output bits corresponding to k
information bits.
 The encoder memory, a shift register of size K, is the
constraint length.
 n is a function of the present input bits and the contents of K.
 The state of the encoder is given by the value of (K - 1) bits.
Consider a convolutional encoder with k = 1,
n = 2 and K = 3.
 When the first bit, 1, is streamed in the encoder, the
contents of encoder will be −
 When the next bit, 1 is streamed in the encoder, the
contents of encoder will be −
 When the next bit, 0 is streamed in the encoder, the
contents of encoder will be −
 When the last bit, 1 is streamed in the encoder, the
contents of encoder will be −
Reed-Solomon codes
 Like Hamming codes, Reed-Solomon codes are linear block codes.
 Unlike Hamming codes, which operate on individual bits, Reed-
Solomon codes operate on m bit symbols.
 Analogy
 A line having the form ax + b is determined by two points.
 Extra points on the same line are redundant, which is helpful for error
correction.
 Imagine that we have two data points that represent a line and we send
those two data points plus two check points chosen to lie on the same line.
 If one of the points is received in error, we can still recover the data points
by fitting a line to the received points.
 Three of the points will lie on the line, and one point, the one in error, will
not.
 By finding the line we have corrected the error.
 Reed-Solomon codes are actually defined as polynomials that
operate over finite fields, but they work in a similar manner.
 For m bit symbols, the codewords are 2m 1 symbols long.
−
 A popular choice is to make m = 8 so that symbols are bytes.
A codeword is then 255 bytes long.
 The (255, 233) code is widely used; it adds 32 redundant
symbols to 233 data symbols.
 Decoding with error correction is done with an algorithm
developed by Berlekamp and Massey that can efficiently
perform the fitting task for moderate-length codes.
 Reed-Solomon codes are widely used in practice because
of their strong error-correction properties, particularly
for burst errors.
 They are used for DSL, data over cable, satellite
communications, and perhaps most ubiquitously on CDs,
DVDs, and Blu-ray discs.
 Because they are based on m bit symbols, a single-bit
error and an m-bit burst error are both treated simply as
one symbol error.
 A low - density parity check (LFPC) code is specified by a
parity-check matrix containing mostly 0s and a low density
of 1s.
 The rows of the matrix represent the equations and the
columns represent the bits in the codeword, i.e. code
symbols.
 A LDPC code is represented by (n, j, k), where n is the
block length, j is the number of 1s in each column and k is
the number of 1s in each row, holding the following
properties −
 j is the small fixed number of 1’s in each column, where j > 3
 k is the small fixed number of 1’s in each row, where k > j.
LDPC (Low-Density Parity Check) code
 This examples illustrates an (12, 3, 4) LDPC matrix, i.e. n = 12,
j = 3 and k = 4.This implies that each equation operates on 4
code symbols and each code symbol appears in 3 equations.
Error Detection and Correction
 The decoder does all the parity checks as per the parity
equations.
 If any bit is contained in more than a fixed number of
unsatisfied parity equations, the value of that bit is
reversed.
 Once the new values are obtained, parity equations are
recomputed using the new values.
 The procedure is repeated until all the parity equations
are satisfied.
Applications
 LDPC codes are practical for large block sizes and have
excellent error-correction abilities that outperform many
other codes. For this reason they are rapidly being
included in new protocols.
 They are part of the standard for digital video
broadcasting, 10 Gbps Ethernet, power-line networks, and
the latest version of 802.11.
Error Detecting Codes
 Parity
 Check-Sum
 CRC (Cyclic Redundancy Check)
Parity Code
 Error-detecting code, in which a single parity bit is appended
to the data.
 The parity bit is chosen so that the number of 1 bits in the
codeword is even (or odd).
 Doing this is equivalent to computing the (even) parity bit as
the modulo 2 sum or XOR of the data bits.
 For example, when 1011010 is sent in even parity, a bit is
added to the end to make it 10110100.
 With odd parity 1011010 becomes 10110101.
 A code with a single parity bit has a distance of 2, since any
single-bit error produces a codeword with the wrong parity.
This means that it can detect single-bit errors.
Advantage of Parity Code over Hamming
Code
 To provide error correction for 1000-bit blocks (using
Hamming Code), 10 check bits are needed. How??
 Calculate for Parity Code.
 What if 1 Mb of data?
Limitation
 A single parity bit can only reliably detect a single-bit
error in the block.
 If the block is badly garbled by a long burst error. Then?
 We can do that provides better protection against burst
errors:
 We can compute the parity bits over the data in a
different order than the order in which the data bits are
transmitted. = .> interleaving.
 We will compute a parity bit for each of the n columns
and send all the data bits as k rows, sending the rows from
top to bottom and the bits in each row from left to right in
the usual manner.At the last row, we send the n parity
bits.
 A burst error does not imply that all the bits are wrong; it
just implies that at least the first and last are wrong.
 4 bits were flipped over a range of 7 bits.
 At most 1 bit in each of the n columns will be affected, so
the parity bits on those columns will detect the error.
Check-Sum
 Internet Check Sum
 The checksum field is the 16 bit one's complement of the
one's complement sum of all 16 bit words in the header.
 For purposes of computing the checksum, the value of the
checksum field is zero.
 If there is no corruption, the result of summing the entire IP
header, including checksum, should be zero. At each hop, the
checksum is verified. Packets with checksum mismatch are
discarded.The router must adjust the checksum if it changes
the IP header.
Example
 To calculate the checksum, we can first calculate the sum of
each 16 bit value within the header, skipping only the checksum
field itself. Note that these values are in hexadecimal notation.
 Initial addition: 4500 + 0073 + 0000 + 4000 + 4011 + c0a8 +
0001 + c0a8 + 00c7 = 2479c
 Carry addition is then made by adding the fifth hexadecimal
digit to the first 4 digits: 2 + 479c = 479e
 The checksum is then the ones' complement (bitwise NOT) of
this result: NOT 479e = b861
 Fletcher’s checksum
 It includes a positional component, adding the product of the data
and its position to the running sum.
 This provides stronger detection of changes in the position of data.
 The checksum is therefore 0x0403. It could be transmitted with
the byte stream and be verified as such on the receiving end.

Error Correcting and Error Detecting Codes.pptx

  • 1.
    Error Correcting andError Detecting Codes Dr. Sudhanshu Janwadkar, Asst Professor, ITNU
  • 2.
    Error Correcting Codes Hamming Code  Binary Convolutional Code  Reed-Solomon Code  Low Density Parity Check Code
  • 3.
    Hamming Code  Hammingcode is an error-correcting code used to ensure data accuracy during transmission or storage.  Hamming code detects and corrects the errors that can occur when the data is moved from the sender to the receiver.  What are Redundant bits?  Extra binary bits that are generated and added to the information- carrying bits of data transfer to ensure that no bits were lost during the data transfer.  The number of redundant bits can be calculated using the following formula: 2r ≥ m + r + 1
  • 4.
     Calculate thenumber of redundant bits, if the number of data bits is 7.  24 ≥ 7 + 4 + 1 .Thus, the number of redundant bits is 4.
  • 5.
    Parity Bits  Aparity bit is a bit appended to a data of binary bits to ensure that the total number of 1’s in the data is even or odd.  Parity bits are used for error detection.  There are two types of parity bits:  Even Parity Bit: In the case of even parity, for a given set of bits, the number of 1’s are counted.  If that count is odd, the parity bit value is set to 1, making the total count of occurrences of 1’s an even number.  If the total number of 1’s in a given set of bits is already even, the parity bit’s value is 0.  Odd Parity Bit: In the case of odd parity, for a given set of bits, the number of 1’s are counted.  If that count is even, the parity bit value is set to 1, making the total count of occurrences of 1’s an odd number.  If the total number of 1’s in a given set of bits is already odd, the parity bit’s value is 0.
  • 7.
    Algorithm of HammingCode  Step 1:Write the bit positions starting from 1 in binary form (1, 10, 11, 100, etc).  Step 2:All the bit positions that are a power of 2 are marked as parity bits (1, 2, 4, 8, etc).  Step 3:All the other bit positions are marked as data bits.  Step 4: Each data bit is included in a unique set of parity bits, as determined its bit position in binary form:  a. 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).  b. 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).  c. 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).And so on…
  • 8.
     Step 5:Since we check for even parity 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.
  • 9.
    Example  Suppose thedata to be transmitted is 1011001 from sender to receiver, the bits will be placed as follows:  The number of data bits = 7  The number of redundant bits = 4  The total number of bits = 7+4=>11  The redundant bits are placed at positions corresponding to power of 2 that is 1, 2, 4, and 8
  • 10.
     R1 bitis calculated using parity check at all the bits positions whose binary representation includes a 1 in the least significant position. R1: bits 1, 3, 5, 7, 9, 11  To find the redundant bit R1, we check for even parity. Since the total number of 1’s in all the bit positions corresponding to R1 is an even number. So, the value of R1 (parity bit’s value) = 0.
  • 11.
     R2 bitis calculated using parity check at all the bits positions whose binary representation includes a 1 in the second position from the least significant bit. R2: bits 2,3,6,7,10,11  To find the redundant bit R2, we check for even parity. Since the total number of 1’s in all the bit positions corresponding to R2 is odd the value of R2(parity bit’s value)=1
  • 12.
     R4 bitis calculated using parity check at all the bits positions whose binary representation includes a 1 in the third position from the least significant bit. R4: bits 4, 5, 6, 7  To find the redundant bit R4, we check for even parity. Since the total number of 1’s in all the bit positions corresponding to R4 is odd so the value of R4(parity bit’s value) = 1
  • 13.
     R8 bitis calculated using parity check at all the bits positions whose binary representation includes a 1 in the fourth position from the least significant bit. R8: bit 8,9,10,11  To find the redundant bit R8, we check for even parity. Since the total number of 1’s in all the bit positions corresponding to R8 is an even number the value of R8(parity bit’s value)=0.
  • 14.
     Thus, thedata transferred is:
  • 15.
    Error Detection andCorrection  Suppose in the above example the 6th bit is changed from 0 to 1 during data transmission, then it gives new parity values in the binary number:
  • 16.
     For allthe parity bits we will check the number of 1’s in their respective bit positions.  For R1: bits 1, 3, 5, 7, 9, 11. We can see that the number of 1’s in these bit positions are 4 and that’s even so we get a 0 for this.  For R2: bits 2,3,6,7,10,11 . We can see that the number of 1’s in these bit positions are 5 and that’s odd so we get a 1 for this.  For R4: bits 4, 5, 6, 7 .We can see that the number of 1’s in these bit positions are 3 and that’s odd so we get a 1 for this.  For R8: bit 8,9,10,11 .We can see that the number of 1’s in these bit positions are 2 and that’s even so we get a 0 for this.  The bits give the binary number 0110 whose decimal representation is 6. Thus, bit 6 contains an error. To correct the error the 6th bit is changed from 1 to 0.
  • 17.
    Binary Convolutional Codes In convolutional codes, the message comprises of data streams of arbitrary length and a sequence of output bits are generated by the sliding application of Boolean functions to the data stream.  In block codes, the data comprises of a block of data of a definite length.  In convolutional codes, the input data bits are not divided into block but are instead fed as streams of data bits, which convolve to output bits based upon the logic function of the encoder.  Also, unlike block codes, where the output codeword is dependent only on the present inputs, in convolutional codes, output stream depends not only the present input bits but also only previous input bits stored in memory.
  • 18.
     Hamming distancesare valuable for understanding block codes.  Convolutional code is not a block code.  In a convolutional code, an encoder processes a sequence of input bits and generates a sequence of output bits.  There is no natural message size or encoding boundary as in a block code.  The output depends on the current and previous input bits.That is, the encoder has memory.  The number of previous bits on which the output depends is called the constraint length of the code.
  • 19.
    Generating a convolutionalcode  The information is passed sequentially through a linear finite- state shift register.  A convolutional code can be represented as (n, k, K) where  k is the number of bits shifted into the encoder at one time. Generally, k = 1.  n is the number of encoder output bits corresponding to k information bits.  The encoder memory, a shift register of size K, is the constraint length.  n is a function of the present input bits and the contents of K.  The state of the encoder is given by the value of (K - 1) bits.
  • 20.
    Consider a convolutionalencoder with k = 1, n = 2 and K = 3.
  • 21.
     When thefirst bit, 1, is streamed in the encoder, the contents of encoder will be −
  • 22.
     When thenext bit, 1 is streamed in the encoder, the contents of encoder will be −
  • 23.
     When thenext bit, 0 is streamed in the encoder, the contents of encoder will be −
  • 24.
     When thelast bit, 1 is streamed in the encoder, the contents of encoder will be −
  • 27.
    Reed-Solomon codes  LikeHamming codes, Reed-Solomon codes are linear block codes.  Unlike Hamming codes, which operate on individual bits, Reed- Solomon codes operate on m bit symbols.  Analogy  A line having the form ax + b is determined by two points.  Extra points on the same line are redundant, which is helpful for error correction.  Imagine that we have two data points that represent a line and we send those two data points plus two check points chosen to lie on the same line.  If one of the points is received in error, we can still recover the data points by fitting a line to the received points.  Three of the points will lie on the line, and one point, the one in error, will not.  By finding the line we have corrected the error.
  • 28.
     Reed-Solomon codesare actually defined as polynomials that operate over finite fields, but they work in a similar manner.  For m bit symbols, the codewords are 2m 1 symbols long. −  A popular choice is to make m = 8 so that symbols are bytes. A codeword is then 255 bytes long.  The (255, 233) code is widely used; it adds 32 redundant symbols to 233 data symbols.  Decoding with error correction is done with an algorithm developed by Berlekamp and Massey that can efficiently perform the fitting task for moderate-length codes.
  • 29.
     Reed-Solomon codesare widely used in practice because of their strong error-correction properties, particularly for burst errors.  They are used for DSL, data over cable, satellite communications, and perhaps most ubiquitously on CDs, DVDs, and Blu-ray discs.  Because they are based on m bit symbols, a single-bit error and an m-bit burst error are both treated simply as one symbol error.
  • 30.
     A low- density parity check (LFPC) code is specified by a parity-check matrix containing mostly 0s and a low density of 1s.  The rows of the matrix represent the equations and the columns represent the bits in the codeword, i.e. code symbols.  A LDPC code is represented by (n, j, k), where n is the block length, j is the number of 1s in each column and k is the number of 1s in each row, holding the following properties −  j is the small fixed number of 1’s in each column, where j > 3  k is the small fixed number of 1’s in each row, where k > j. LDPC (Low-Density Parity Check) code
  • 31.
     This examplesillustrates an (12, 3, 4) LDPC matrix, i.e. n = 12, j = 3 and k = 4.This implies that each equation operates on 4 code symbols and each code symbol appears in 3 equations.
  • 32.
    Error Detection andCorrection  The decoder does all the parity checks as per the parity equations.  If any bit is contained in more than a fixed number of unsatisfied parity equations, the value of that bit is reversed.  Once the new values are obtained, parity equations are recomputed using the new values.  The procedure is repeated until all the parity equations are satisfied.
  • 33.
    Applications  LDPC codesare practical for large block sizes and have excellent error-correction abilities that outperform many other codes. For this reason they are rapidly being included in new protocols.  They are part of the standard for digital video broadcasting, 10 Gbps Ethernet, power-line networks, and the latest version of 802.11.
  • 34.
    Error Detecting Codes Parity  Check-Sum  CRC (Cyclic Redundancy Check)
  • 35.
    Parity Code  Error-detectingcode, in which a single parity bit is appended to the data.  The parity bit is chosen so that the number of 1 bits in the codeword is even (or odd).  Doing this is equivalent to computing the (even) parity bit as the modulo 2 sum or XOR of the data bits.  For example, when 1011010 is sent in even parity, a bit is added to the end to make it 10110100.  With odd parity 1011010 becomes 10110101.  A code with a single parity bit has a distance of 2, since any single-bit error produces a codeword with the wrong parity. This means that it can detect single-bit errors.
  • 36.
    Advantage of ParityCode over Hamming Code  To provide error correction for 1000-bit blocks (using Hamming Code), 10 check bits are needed. How??  Calculate for Parity Code.  What if 1 Mb of data?
  • 37.
    Limitation  A singleparity bit can only reliably detect a single-bit error in the block.  If the block is badly garbled by a long burst error. Then?
  • 38.
     We cando that provides better protection against burst errors:  We can compute the parity bits over the data in a different order than the order in which the data bits are transmitted. = .> interleaving.  We will compute a parity bit for each of the n columns and send all the data bits as k rows, sending the rows from top to bottom and the bits in each row from left to right in the usual manner.At the last row, we send the n parity bits.
  • 40.
     A bursterror does not imply that all the bits are wrong; it just implies that at least the first and last are wrong.  4 bits were flipped over a range of 7 bits.  At most 1 bit in each of the n columns will be affected, so the parity bits on those columns will detect the error.
  • 41.
    Check-Sum  Internet CheckSum  The checksum field is the 16 bit one's complement of the one's complement sum of all 16 bit words in the header.  For purposes of computing the checksum, the value of the checksum field is zero.  If there is no corruption, the result of summing the entire IP header, including checksum, should be zero. At each hop, the checksum is verified. Packets with checksum mismatch are discarded.The router must adjust the checksum if it changes the IP header.
  • 42.
    Example  To calculatethe checksum, we can first calculate the sum of each 16 bit value within the header, skipping only the checksum field itself. Note that these values are in hexadecimal notation.  Initial addition: 4500 + 0073 + 0000 + 4000 + 4011 + c0a8 + 0001 + c0a8 + 00c7 = 2479c  Carry addition is then made by adding the fifth hexadecimal digit to the first 4 digits: 2 + 479c = 479e  The checksum is then the ones' complement (bitwise NOT) of this result: NOT 479e = b861
  • 43.
     Fletcher’s checksum It includes a positional component, adding the product of the data and its position to the running sum.  This provides stronger detection of changes in the position of data.  The checksum is therefore 0x0403. It could be transmitted with the byte stream and be verified as such on the receiving end.