joserse46
Newbie level 4
- Joined
- Nov 6, 2010
- Messages
- 7
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,347
It will only return the syndrome and not k(error in kth position)
I wrote a test function to return two values and it work, but for some reason it's not returning the 2 values I want.
thanks in advance. example msg r1 = [1 0 1 1 1 0 1 0 1 0 0 0 1 0 1] should return s = [0 1 0 1] (which it does) and k = 11
- - - Updated - - -
well an hour later I solved my own problem I was calling the function getsyndm(r1) instead of [s,k] = getsyndm(r1), I know it was easy.
I wrote a test function to return two values and it work, but for some reason it's not returning the 2 values I want.
thanks in advance. example msg r1 = [1 0 1 1 1 0 1 0 1 0 0 0 1 0 1] should return s = [0 1 0 1] (which it does) and k = 11
Code:
function[s,k] = getsyndm(msg)
h_t = [1 0 0 0 ;
0 1 0 0 ;
0 0 1 0 ;
0 0 0 1 ;
1 0 0 1 ;
1 1 0 1 ;
1 1 1 1 ;
1 1 1 0 ;
0 1 1 1 ;
1 0 1 0 ;
0 1 0 1 ;
1 0 1 1 ;
1 1 0 0 ;
0 1 1 0 ;
0 0 1 1 ];
s = mod(msg*h_t,2);
if s(1) == 0 && s(2) == 0 && s(3) == 0 && s(4) == 0
k = 0;
elseif s(1) == 0 && s(2) == 0 && s(3) == 1 && s(4) == 1
k = 15;
elseif s(1) == 0 && s(2) == 1 && s(3) == 1 && s(4) == 0
k=14;
elseif s(1) == 1 && s(2) == 1 && s(3) == 0 && s(4) == 0
k=13;
elseif s(1) == 1 && s(2) == 0 && s(1) == 1 && s(4) == 1
k=12;
elseif s(1) == 0 && s(2) == 1 && s(3) == 0 && s(4) == 1
k=11;
elseif s(1) == 1 && s(2) == 0 && s(3) == 1 && s(4) == 0
k=10;
elseif s(1) == 0 && s(2) == 1 && s(3) == 1 && s(4) == 1
k=9;
elseif s(1) == 1 && s(2) == 1 && s(3) == 1 && s(4) == 0
k=8;
elseif s(1) == 1 && s(2) == 1 && s(3) == 1 && s(4) == 1
k=7;
elseif s(1) == 1 && s(2) == 1 && s(3) == 0 && s(4) == 1
k=6;
elseif s(1) == 1 && s(2) == 0 && s(3) == 0 && s(4) == 1
k=5;
elseif s(1) == 0 && s(2) == 0 && s(3) == 0 && s(4) == 1
k=4;
elseif s(1) == 0 && s(2) == 0 && s(3) == 1 && s(4) == 0
k=3;
elseif s(1) == 0 && s(2) == 1 && s(3) == 0 && s(4) == 0
k=2;
else
k=1;
end
end
- - - Updated - - -
well an hour later I solved my own problem I was calling the function getsyndm(r1) instead of [s,k] = getsyndm(r1), I know it was easy.