I hope someone can help me here and i hope i post it on the right place haha

i made a function to decode hamming and a function to encode hamming. I used (11,7) hamming(to understand hamming, i don't want to use the standard matlab function) First i encoded the 7 bit sequence after that i added noise by making use of awgn function in matlab and after that i decoded the hamming.

for example 1001101 becomes: 011100101010 the last parity bit is checking even parity

The problem is with decoding i used 5 parity bits for checking errors. After multiplying the parity checking matrix with the 11 bit matrix i get a 5 bit matrix. The last bit is checking even parity. If so, no error occured. If it's not even parity then there is an error. The first 4 bits are giving the place were the error is. The strange thing is that sometimes it says the error is at place 15 for example? and then i get an error like index exceeds matrix dimensions.

i don't know how to fix this. here i gave a piece of the code with the input(with added noise) were it goes wrong.

i made a function to decode hamming and a function to encode hamming. I used (11,7) hamming(to understand hamming, i don't want to use the standard matlab function) First i encoded the 7 bit sequence after that i added noise by making use of awgn function in matlab and after that i decoded the hamming.

for example 1001101 becomes: 011100101010 the last parity bit is checking even parity

The problem is with decoding i used 5 parity bits for checking errors. After multiplying the parity checking matrix with the 11 bit matrix i get a 5 bit matrix. The last bit is checking even parity. If so, no error occured. If it's not even parity then there is an error. The first 4 bits are giving the place were the error is. The strange thing is that sometimes it says the error is at place 15 for example? and then i get an error like index exceeds matrix dimensions.

i don't know how to fix this. here i gave a piece of the code with the input(with added noise) were it goes wrong.

Code:

```
input=[1;1;1;0;1;0;0;0;0;1;0;0]
paritycheck =[1 0 1 0 1 0 1 0 1 0 1 0;0 1 1 0 0 1 1 0 0 1 1 0;0 0 0 1 1 1 1 0 0 0 0 0;0 0 0 0 0 0 0 1 1 1 1 0; 1 1 1 1 1 1 1 1 1 1 1 1];
y = mod(paritycheck*input,2);
err = y(1,i)+2*y(2,i)+4*y(3,i)+8*y(4,i)
%nonerror
if err == 0 && y(5,i) == 0
corr = input;
%doubele err
elseif err > 0 && y(5,i) == 0
corr = input;
%single err
elseif y(5,i) == 1 && err > 0
%change value of bit
if input(err,i) == 1
input(err,i) = 0;
else
input(err,i) = 1;
end
corr = input;
%err in last parity bit
elseif err == 0 && y(5,i) == 1
corr = input;
else
corr = input;
end
```

Last edited: