0

I have a output matrix (3,63) of a encoder BCH but this matrix is a Galois Field and i need convert this Galois field in a matrix binary, because matlab treats the elements the Galois field as string and i need treats this values as binary numbers.

---------------------------------------------------------------------------
ENCODE
----------------------------------------------------------------------------
M = 6;                    %
n = 2^M-1;                % Codeword length
k=36;                     % Message length
rows2=3;
msg=reshape(matrix2,[rows2,k]);
gfmsg=gf(msg);
[genploy,t]=bchgenpoly(n,k);
code=bchenc(gfmsg,n,k);
noisycode = code + randerr(rows2,n,1:t);

I need to compare the columns of code with 000,010,... with a switch case or with an if but the rows of code matrix are in Galois field format The code that i have problem is the follow an the matlab error is SWITCH expression must be a scalar or a character vector.

for i=1:63
   test =code(1:3,i)
   switch test
      case 000
          symbol=R(1:500,1);
      case 100
          symbol=R(1:500,2);
      case 010
          symbol=R(1:500,3);
      case 110
          symbol=R(1:500,4);
      case 001
          symbol=R(1:500,5);
      case 101
          symbol=R(1:500,6);
      case 011
          symbol=R(1:500,7);
      case 111
          symbol=R(1:500,8);
   end
   symbol=(symboltx(:,i))
end
Ander Biguri
  • 35,140
  • 11
  • 74
  • 120
zurbaranf
  • 201
  • 2
  • 3

1 Answers1

0

You can convert the code from GF(2) to numeric array, and from there it's simple:

After test = code(1:3,i);, the class of test is GF(2) array.

  • Convert test from GF(2) array to logical array:

    numeric_test = (test == ones(nwords, 1));
    
  • Convert numeric_test to string:

    str_test = (char(numeric_test + '0'))';
    
  • Convert string from binary to decimal:

    decimal_test = bin2dec(str_test);
    
  • Use switch case on the decimal value, or just use it as an index:

    switch decimal_test
        case 0
            symbol=R(1:500,1);
        case 1
            symbol=R(1:500,2);
    

Instead of a switch you can do:

symbol = R(1:500, decimal_test+1);

...

Here is a complete code sample:

%Build data set:
M = 6;
n = 2^M-1;   % Codeword length
k = 36;      % Message length
nwords = 3; % Number of words to encode
gfmsg = gf(randi([0 1],nwords,k));
[genploy,t]=bchgenpoly(n,k);
code = bchenc(gfmsg,n,k);

%Assume we are inside the for loop 
%for i=1:63 
i = 1;
test = code(1:3, i);

%True answer code begins here:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Convert test from GF(2) array to logical array
numeric_test = (test == ones(nwords, 1));

%Convert to string:
str_test = (char(numeric_test + '0'))';

%Convert from string to decimal:  
decimal_test = bin2dec(str_test);

%Now you can use switch case on the decimal value, or just use it as an index.  
switch decimal_test
    case 0
        symbol=R(1:500,1);
    case 1
        symbol=R(1:500,2);
    case 2
        symbol=R(1:500,3);
    case 3
        symbol=R(1:500,4);
    case 4
        symbol=R(1:500,5);
    case 5
        symbol=R(1:500,6);
    case 6
        symbol=R(1:500,7);
    case 7
        symbol=R(1:500,8);
end
Rotem
  • 30,366
  • 4
  • 32
  • 65