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!
Related
In the code below, snapshot should be 0 if TrimCY = TrimBYS.
df <- df %>%
mutate(snapshot = case_when(Trend_direction != 2 ~ (TrimCY-TrimBYS)*sign(Trend_direction)*10/abs(Target_Snap-TrimBYS),
TRUE ~ 10-((abs(TrimCY-Target_Snap)*10)/abs(Target_Snap-TrimBYS))))
When I execute this code on the data displayed below, this is not always the case. See snapshot values.
Trend_direction Target_Snap TrimCY TrimBYS snapshot
1 56 53 53 0.000000e+00
1 56 54 54 -3.552714e-14
1 56 55 55 -7.105427e-14
Does anyone know why I am getting these very small non-zero results? When I copy the arithmetic function into the console and execute using the values above, it always comes out to 0.
These are floating point errors. To get the basic idea of what's going on, work out 1 - 1/3 - 1/3 - 1/3 = ? on a piece of paper, but only work to 3 decimal places. The equation looks like 1 - 0.333 - 0.333 - 0.333 = 0.001. Even though it should be zero, it's not. The computer is basically doing this, but to lots more decimal places and in binary.
For a more detailed explanation there are lots of resources around: for example: https://floating-point-gui.de/
You can get around it by rounding the answer, or (as akrun suggests) setting your options so these numbers display as zero.
This is why it's good practice to never test for x == 0 when x has been subject to these sorts of floating point calculations, and always do something like abs(x) < 1e-10 instead.
I'd like to split a sequence into k parts, and optimize the homogeneity of these sub-parts.
Example : 0 0 0 0 0 1 1 2 3 3 3 2 2 3 2 1 0 0 0
Result : 0 0 0 0 0 | 1 1 2 | 3 3 3 2 2 3 2 | 1 0 0 0 when you ask for 4 parts (k = 4)
Here, the algorithm did not try to split in fixed-length parts, but instead tried to make sure elements in the same parts are as homogeneous as possible.
What algorithm should I use ? Is there an implementation of it in R ?
Maybe you can use Expectation-maximization algorithm. Your points would be (value, position). In your example, this would be something like:
With the E-M algorithm, the result would be something like (by hand):
This is the desired output, so you can consider using this, and if it really works in all your scenarios. An annotation, you must assign previously the number of clusters you want, but I think it's not a problem for you, as you have set out your question.
Let me know if this worked ;)
Edit:
See this picture, is what you talked about. With k-means you should control the delta value, this is, how the position increment, to have its value to the same scale that value. But with E-M this doesn't matter.
Edit 2:
Ok I was not correct, you need to control the delta value. It is not the same if you increment position by 1 or by 3: (two clusters)
Thus, as you said, this algorithm could decide to cluster points that are not neighbours if their position is far but their value is close. You need to guarantee this not to happen, with a high increment of delta. I think that with a increment of 2 * (max - min) values of your sequence this wouldn't happen.
Now, your points would have the form (value, delta * position).
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.
"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!).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
Can anyone recommend some good starting points for understanding Transformation Matrices for dummies like me with poor math skills.
I'm willing to learn the math, and I'm not a complete idiot (I hope) but the examples I'm finding seem to require a huge leap from what I know, to what I need to know.
I wrote a web program that can be used to play around with transformation matrices. It allows preset types and custom ones.
Play with it online or grab the source.
It should be easy to play with the numbers and instantly see how it affects the house drawing. Look at the code available online to determine what it's doing, and you should be able to understand what's going on.
If you're having trouble, realise that the 3×3 matrix is simply being multiplied by each vertex (X & Y coordinate) in the house shape. Matrix multiplication with the vertex (we will now refer to it as a vector) and a transformation matrix looks like so...
1 0 0 1
0 1 0 * 2
0 0 1 0
On the left is an identity matrix (an idempotent matrix that doesn't affect the vector) and a vector of 1, 2, 0 (assume this maps to position X1 and Y2 in the program mentioned above's graph and ignore the final 0).
Matrix multiplication can be visualised like so...
a b c x a * x + b * y + c * z
d e f + y = d * x + e * y + f * z
g h i z g * x + h * y + i * z
So, in our example, that would be...
1 0 0 1 1 * 1 + 0 * 2 + 0 * 0
0 1 0 * 2 = 0 * 1 + 1 * 2 + 0 * 0
0 0 1 0 0 * 1 + 0 * 2 + 1 * 0
Do that math and we get the final vector...
1
2
0
Since we said our identity matrix shouldn't modify the values, we can see above that that is the case as the resulting vector matched the original.
To explain further, consider when you need to translate the vector. Let's say we want to translate the house by 5 pixels along the X axis. We want to start with the identity matrix, but change the top right number to 5 and make the extra dimension in the vector 1 (you will see why briefly).
1 0 5 1 1 * 1 + 0 * 2 + 5 * 1
0 1 0 * 2 = 0 * 1 + 1 * 2 + 0 * 1
0 0 1 1 0 * 1 + 0 * 2 + 1 * 1
We do the math again...
6
2
1
We can see that the first number (X in our coordinates) has been translated along the X axis by 5. Try it in the program linked above.
The reason we made the third value 1 is so when the math was performed, the translation was considered. Had it been 0, it will be ignored, as any number multiplied by 0 results in 0.
If you're still having trouble, check out videos online (this one, for example) which can help explain it in a more visual fashion.
Remember: pretty much anyone can drive a car, and pretty much anyone can learn this, despite any self-evaluated poor understanding of math. Just keep at it: persistence is key. Good luck.
Like duffymo has pointed out, Matrix Transformations is nothing more but (pre)multiplying a vector (like a 3d point) by a matrix. However, that is pure mathematics, and hard for some people to visualise.
The best way to understand transformation matrices (at least for me) is to get an example code, get it running, and play around with the numbers. Try to see if you can place an object farther away, or rotated by 45 degrees. Try putting the transformations in different order and see what the results are.
All working? Good.
Once you get a feel of that, and if you're brave enough to tackle the maths, you could take these steps:
First, understand how matrix multiplications work. Some links:
http://en.wikipedia.org/wiki/Matrix_multiplication
http://www.gamedev.net/reference/list.asp?categoryid=28#259
Also borrow highschool math textbooks from any of your friends.
Google is your friend.
Once you are comfortable with multiplying a matrix by hand, you will get a feel of why transformations are written that way. As you use them, the understanding of matrices will eventually come to you.
Secondly, I always recommend spending an afternoon trying to implement your own Matrix class and define a few common operations like mul(Vector v), transpose() or even createTranslationMatrix(float x, float y, float z). Put in a few tests and see if the results are the same with what you did by hand.
If you've come that far, try implementing your own Perspective Transformation! It's the most amazing thing we never come to appreciate. A useful explanation here:
Deriving Projection Matrices
You will be very proud of yourself once you have accomplished one of the most labourous, yet under-appreciated tasks of implementing a matrix object. Good luck!
A transformation is nothing more than a matrix multiplying a vector to produce the transformed vector, so if you don't understand matrix multiplication and addition you can't get very far.
Start with matricies and linear algebra. There are lots of books out there, but realize that based on the statement that I made above you don't need to read that whole book. You won't need eigenvalues or Gaussian elimination or vector spaces or any of the other stuff that will be advanced and difficult.
You just need to know how to extend what you know about multiplying and adding numbers to matricies.
Getting the entries in that transformation matrix is another matter altogether. You'll need a good book on mathematics and computer graphics. You won't find that in a linear algebra textbook.