How to detect errors for Reed-Solomon Code? - decoding

I am using (7,5) Reed-Solomon Error Correction Code.
I think I can decode "correct 1 error" or "find 2 error position".
However, there is a problem. My code can not find 2 error position.
For example, the message is 1 3 5 2 1 and RS parity is 0 5. So RS code is 0513521.
After then, there are two errors at parity part. So code is changed to 1113521.
I want to find these two errors, but my decoder said the answer is 1113621.
What should I do?

RS(7,5) can correct 1 error or detect up to 2 errors, but not determine the position of the 2 errors. In a two error case, there are multiple combinations of 2 error values and 2 error locations that produce the same 2 syndromes. Using your example, the two error cases 1113521 (errors in locations 0 and 1) and 0463521 (errors in locations 1 and 2) produce the same result: syndrome_1 = 4 and syndrome_2 = 6, and there's no way to determine where the errors are, only that they exist.
As commented, if a 1 error correction is attempted in a 2 error case, it's possible for the decoder to mis-correct and create a third error, in order to create a "valid" codeword, in this case it created 1113621. I got the same result with a test program I have.
The question is missing information, based on the example, it's using GF(8) = GF(2^3), modulo x^3 + x^2 + 1 (hex d), and the generator polynomial = (x-2)(x-4) = x^2 + 6 x + 5. Note for GF(2^m), addition and subtraction are both xor. The data is displayed least significant term first, so 0513521 = 0 + 5x + 1x^2 + 3x^3 + 5x^4 + 2x^5 + 1x^6.

Related

How to do DED in hamming

I'm trying to create a 1 bit error correction with 2 bit error detection hamming code. However, I encounter some problem with the algorithm. Without the 2 bit error detection part, 1 bit error correction works fine. However, adding 2 bit error detection into it, for some cases, it cannot correct 1 bit error nor detect 2 bit error.
My 2 bit error detection logic is as follow:
(say its (7 4) hamming code and 3 parity bit is called c)
1) xor every bit from the receiver side (called it as X)
2) If X == 0 and c == 0 then it is correct
3) If X ~= 0 then it has 1 error
4) If X == 0 and c ~= 0 then 2 bit error occurs.
I followed this https://www.tutorialspoint.com/hamming-code-for-single-error-correction-double-error-detection. But it doesn't seem it's working. Can someone help me out or give me some idea or a correct logic for 2 bit error detection.
Thanks!

What is non-trivial way of finding solution in systems of linear equations?

Hi!
I think I understood till (2.40) but i don't seem to understand
where the 0 = 8c1 + 2c2 - 1c3 + 0c4 came from.. where did this -1 and 0 is from?
In general these types of questions are probably better suited for https://math.stackexchange.com/ but since I like math and linear algebra I'll also answer your question.
The system of equations that you have has 4 variables and only 2 equations, so this means that you're going to have more than one solution and actually an infinite number of solutions. Not just anything will work though, so let's find what the solutions look like.
To simplify writing this let's call the 2x4 matrix A and the right hand side b=(42,8)T so what we are trying to solve is Ax = b. Also to write the zero vector (0,0)T I'll use ⍬ to save typing.
They first find a particular solution (some xp such that Axp = b) they do this with the first 2 columns and 0's for the other columns: xp = (42,8,0,0)T and when we plug this in we do get Axp = (42,8)T. Next they are trying to find the other solutions.
Notice that if we can find an x0 such that Ax0 = ⍬ then we can add this to our xp and it'll still be a solution: A(xp + x0) = Axp + Ax0 = b + ⍬ = b. So let's see if we can find an x0.
They do this in (2.40) by basically saying the 3rd and 4th column are not used in xp so let's see if we can make them 0 using the first two columns. Really we're looking for anything that'll give Ax0=⍬ and this is just an idea how we might find that.
Now notice that the 3rd column (8,2)T can be written as 8 times first column + 2 times second column. So if we do 8 first column + 2 second column - 1 times third column (+ zero times forth column) we get zero. This is just x0 = (8,2,-1,0)T because if we do Ax0 = A(8,2,-1,0)T = ⍬. Similarly we can find another one of these by using the forth column to get (-4,12,0,-1)T as another independent vector which I'll call x02 because I can't think of a better notation at the moment. Both of these satisfy Ax0 = ⍬, Ax02 = ⍬.
To make this really concrete you can see that computing A(xp+x0) = A(50,10,-1,0)T really does give you (42,8)T.
So we can add either or both to our original xp and it'll still be a solution that gives us the b we're looking for. A(xp + x0 + x02) = Axp + Ax0 + Ax02 = b + ⍬ + ⍬ = b Also any multiple of these x0 or x02 will work as well because for example A(3*x0) = 3*Ax0 = 3*⍬ = ⍬.
So really A(xp + c*x0 + d*x02) = Axp + c*Ax0 + d*Ax02 = b + c*⍬ + d*⍬ = b which means that any vector of the form xp + c*x0 + d*x02 where c and d are any numbers (scalars) will be a solution. This is our solution set and is what the last part (2.43) is saying.

i not showing up as number in loop

so I have a loop that finds the position in the matrix where there is the largest difference in consecutive elements. For example, if thematrix[8] and thematrix[9] have the largest difference between any two consecutive elements, the number given should be 8.
I made the loop in a way that it will ignore comparisons where one of the elements is NaN (because I have some of those in my data). The loop I made looks like this.
thenumber = 0 #will store the difference
for (i in 1:nrow(thematrix) - 1) {
if (!is.na(thematrix[i]) & !is.na(thematrix[i + 1])) {
if (abs(thematrix[i] - thematrix[i + 1]) > thenumber) {
thenumber = i
}
}
}
This looks like it should work but whenever I run it
Error in if (!is.na(thematrix[i]) & !is.na(thematrix[i + 1])) { :
argument is of length zero
I tried this thing but with a random number in the brackets instead of i and it works. For some reason it only doesn't work when I use the i specified in the beginning of the for-loop. It doesn't recognize that i represents a number. Why doesn't R recognize i?
Also, if there's a better way to do this task I'd appreciate it greatly if you could explain it to me
You are pretty close but when you call i in 1:nrow(thematrix) - 1 R evaluates this to make i = 0 which is what causes this issue. I would suggest either calling i in 1:nrow(thematrix) or i in 2:nrow(thematrix) - 1 to start your loop at i = 1. I think your approach is generally pretty intuitive but one suggestion would be to frequently use the print() function to evaluate how i changes over the course of your function.
The issue is that the : operator has higher precedence than -; you just need to use parentheses around (nrow(thematrix)-1). For example,
thematrix <- matrix(1:10, nrow = 5)
##
wrong <- 1:nrow(thematrix) - 1
right <- 1:(nrow(thematrix) - 1)
##
R> wrong
#[1] 0 1 2 3 4
R> right
#[1] 1 2 3 4
Where the error message is coming from trying to access the zero-th element of thematrix:
R> thematrix[0]
integer(0)
The other two answers address your question directly, but I must say this is about the worst possible way to solve this problem in R.
set.seed(1) # for reproducible example
x <- sample(1:10,10) # numbers 1:10 in random order
x
# [1] 3 4 5 7 2 8 9 6 10 1
which.max(abs(diff(x)))
# [1] 9
The diff(...) function calculates sequential differences, and which.max(...) identifies the element number of the maximum value in a vector.

Why would an R function not write to the environment?

I'm trying to write a relatively simple AR(1) representation in R. I cannot find any glaring issues with this code, and furthermore I am returning not errors, it simple isn't writing to the environment, or recognizing areone2 as a function. Any suggestions would be much appreciated.
areone2<-function(y,N,p,d){
yvec<-c(rep(y, times = N))
for(i in 1:N){
yvec[i+1]<-
((1+p*(yvec[i]-d))
+ d)
}
plot(yvec, type='l', xlab="N", ylab="yeild")
}
areone2(.3,10,.9,.2)
It doesn't trigger an error or warning because you broke the line in the middle of a binary operation, but that binary operation wasn't recognized by the parser. It's perfectly legal to begin a line with + 3 It's just 3, which is not what you want.
For example, 2 + 3 is 5, we would expect. But +3 on a new line does not add it to the previous line
> 2 ## break the line here and R returns 2
[1] 2
> +3 ## adding three next is not recognized as a continuation of a call
[1] 3
But you can still break the line if you wrap the call in parentheses (not brackets)
(2
+ 3)
# [1] 5 ## correct
{2
+ 3}
# [1] 3 ## incorrect
Bringing your yvec[]<- assignment call up onto one line is the cleaner and safer way to go.
yvec[i+1] <- ((1+p*(yvec[i]-d)) + d)

How do I run error detection on this binary messsage using polynomial/CRC?

"Show the new message to be sent by a sender after performing the CRC calculation >using the generator X3+1 on the message: 101110110:"
I have the following done but I am not sure if it is correct, some help would be appreciated:
I worked out the generator using the following steps:
Step one:
x³+1 . x³ = 1 . there is no x^2 so x^2 = 0 . There is no x^0 so x^0 = 0
x³ + 1 = 1001
generator = 1001
Step two:
I divide the message 101110110 by 1001 I get the remainder of 0101
The new message is 101110101 ??
Is this correct and which part is the CRC?
Note: because the polynomial you are using is of degree 3, the remainder has only 3 bits. So, the message you have to transmit is the original appended by the 3 bit remainder. In this case, the transmitted message is: 101110110101 where the last 3 bits is the remainder you found (correctly!).

Resources