WHY the result I calculated is different from what matlab calculated?

146 views Asked by At

Here's matlab's answer:

x=[1,0,1,1]

x_encode=encode(x,7,4)

>>x_encode [1,0,0,1,0,1,1]

I calculated the hamming code from definition of hamming code, here's my calculation process:

2^r≥k+r+1
Here,k=4
2^r≥5+r
r=3
n=k+r=7
encode:[r1,r2,1,r3,0,1,1]
r1->[r1,1,0,1]、r2->[r2,1,1,1]、r3->[r3,0,1,1]

If I use odd parity bit, so it would be like:

r1=1,r2=0,r3=1
>>x_encode [1,0,1,1,0,1,1]

But else if I use even parity bit, it would be like:

r1=0,r2=1,r3=0
>>x_encode [0,1,1,0,0,1,1]

none of above equals the result that matlab calculated. I wonder why, I will appericate it if someone can answer my question. Thanks!

1

There are 1 answers

2
Alessandro On

You can open the encode function in Matlab. Accordingly, the function computes the following steps:

m = n-k;
h = hammgen(m);
gen = gen2par(h);
code = rem(x * gen, 2);

Try to check step-by-step what those commands do and where they differ with respect to the classical Hamming code.