2

I have a binary matrix A (only 1 and 0), and a vector D in Galois field (256) The vector C is calculated as:

  C = (A^^-1)*D

where A^^-1 denotes the inverse matrix of matrix A in GF(2), * is multiplication operation. The result vector C must be in GF(256).

However, I only have a matrix A1 is non-square matrix. The above matrix A in the equation is created by delete some dependence rows of A1. In same manner, the vector D is constructed by delete some element corresponding the deleted rows in A1. Hence, we can solve above equation. My question is that can we have any function in MATLAB to do above steps?

For example, I have A1 is 16x14 matrix, D1 is 16x1 vector

A1 =[1     0     0     1     1     0     0     0     0     0     0     0     0     0
     1     1     0     0     0     1     0     0     0     0     0     0     0     0
     1     1     1     0     0     0     1     0     0     0     0     0     0     0
     0     1     1     1     0     0     0     1     0     0     0     0     0     0
     0     0     1     1     0     0     0     0     1     0     0     0     0     0
     1     1     0     1     1     0     0     1     0     1     0     0     0     0
     1     0     1     1     0     1     0     0     1     0     1     0     0     0
     1     1     1     0     0     0     1     1     1     0     0     1     0     0
     0     1     1     1     1     1     1     0     0     0     0     0     1     0
     0     0     0     0     1     1     1     1     1     0     0     0     0     1
     0     1     1     1     1     0     1     1     1     0     1     1     1     0
     0     0     0     1     0     0     0     1     0     0     0     0     0     0
     0     0     1     0     0     0     0     1     0     0     0     0     0     0
     1     1     1     1     0     0     0     0     0     0     0     0     0     0
     0     0     1     1     0     0     0     0     1     1     0     0     0     0
     0     0     1     0     0     0     0     0     0     0     0     0     0     1 ]

D1=[0; 0; 0;  0 ; 0;   0 ;  0;   0 ;  0 ;  0 ;  103 ;  198 ;  105 ;  115;   175  ;  14]

In above example, we need to delete two dependence rows/cols from A1 to obtain A is 14x14 matrix and D1 also delete 2 elements to obtain D, and then my expected result is

C=A^^-1*D
C= [  103;   187 ;  125;   210 ;  181;   220 ;  161   ; 20 ;  175;   175;  187;   187 ;  220 ;  115]

This is what I tried

%%A1=gf(A1,8);
%%D1=gf(D1,8); %%2^8=256
%% Do something and last step is
%%C=inv(A)*D
[C,vld] = gflineq(A1,D1,8)
Or 
C=gf(A1,8) \ gf(D1,8)

However, these ways did not return the my expected C vector. I found that Gaussian Elimination can be worked, but I don't know how can I apply for my case. Could you give me a correct solution?

sheilak
  • 5,833
  • 7
  • 34
  • 43
user3051460
  • 1,455
  • 22
  • 58
  • it does not work for Galois field matrix – user3051460 Nov 27 '15 at 09:03
  • I think that matlab will support some function to solve above problem. In general case, I found that Gaussian Elimination can be do it. But for my problem, I don't see any way for it – user3051460 Nov 27 '15 at 09:10
  • 1
    I have *no idea* what any of this Galois field stuff is... but if this were normal linear algebra, it sounds like you're possibly asking for something like `C = (A1'*A1)\(A1'*D1)` or equivalently `C = inv(A1'*A1)*(A1'*D1)`? That's the solution in a least squares sense to an overdetermined system. Good chance though I'm completely off base. – Matthew Gunn Nov 27 '15 at 09:16
  • @MatthewGunn: No, It is not correct. I have A1 and D1. By some way to remove dependence rows/cols in A1, I have a independence A and D (D is constructed by remove positions similar in A1), I will have A, D and apply A^^-1*D, I can obtain C – user3051460 Nov 27 '15 at 09:23
  • How about `C=A1\D1`? That's what [docs appear to say here](http://www.mathworks.com/help/comm/ug/error-detection-and-correction.html#fp6410)? – Matthew Gunn Nov 27 '15 at 09:55
  • It is not work. Could you tried with my above data. I think the function http://kr.mathworks.com/help/comm/ref/gflineq.html is more suitable, but it still not work for GF(8) – user3051460 Nov 27 '15 at 09:59
  • Can you elaborate? Do you get any error? Or does it just not give you a solution? Or a wrong solution? Or something not in GF(256)? – BillBokeey Nov 27 '15 at 10:04
  • I cannot find the solution as C. – user3051460 Nov 27 '15 at 10:06
  • The ouput must be C= [ 103; 187 ; 125; 210 ; 181; 220 ; 161 ; 20 ; 175; 175; 187; 187 ; 220 ; 115] – user3051460 Nov 27 '15 at 10:07
  • What is the output of `C=A1\D1`? – BillBokeey Nov 27 '15 at 10:08
  • Sir, If I work in GF(256), then C=A1\D1, is not correct. You can tried with above example – user3051460 Nov 27 '15 at 11:12
  • 2
    Does my answer on [How to perform inverse in GF(2) and multiply in GF(256) in Matlab](http://stackoverflow.com/questions/33527625/how-to-perform-inverse-in-gf2-and-multiply-in-gf256-in-matlab) work for you? At a quick glance this looks like an identical question. – IKavanagh Nov 27 '15 at 11:34
  • Hello IKavanagh again, This question is for encoding part. I am working in decoding which A is nonsquare matrix. To solve it, general way looks like gaussian elimination will be work. – user3051460 Nov 27 '15 at 11:44
  • @user3051460 Sorry I don't understand. I've not looked at this too in-depth versus the previous as I don't have much time. What is the difference between the 2 questions and the specific error/issue you have? Its not clear from the question. – IKavanagh Nov 27 '15 at 11:46
  • Yes, I will explain in shortly. The equation C=A^^-1*D is similar with your ans. However, in here I have a new matrix A1 which created from A with some combination of row and cols, so A1 is dependence matrix. We must remove two cols or rows to create a independence matrix A, then we can apply the inv(A) . – user3051460 Nov 27 '15 at 11:52
  • This is one example in Example: Solving Linear Equations. http://kr.mathworks.com/help/comm/ug/error-detection-and-correction.html#fp6410 – user3051460 Nov 27 '15 at 11:59
  • Do you tried it with GF(256)?My target is GF(256), not GF(2) – user3051460 Nov 27 '15 at 12:56
  • See my edited answer if you want to see what's going on. It works now, had to redefine sum in GF(2^8) as I don't have access to the toolbox – BillBokeey Nov 27 '15 at 15:24
  • Are you trying to do some error detection and correction scheme? Is matrix `A` the syndrome? – Ben Voigt Nov 27 '15 at 17:04
  • @BenVoigt: I am using a error correction for channel coding. The name is Raptor FEC . You can see it at https://tools.ietf.org/html/rfc5053 – user3051460 Nov 28 '15 at 01:11
  • 1
    Well, the algorithm is described right there is the RFC – Ben Voigt Nov 28 '15 at 01:47
  • Yes, sir. Do you have any idea for that standard. I read it so long time but I did not understand all details – user3051460 Nov 28 '15 at 03:10

2 Answers2

4

First of all, I don't have access to the "Communication system toolbox", so in order to operate in GF(2) I have to add mod(stuff,2) calls in the code, and in order to operate in GF(2^8) I had to implement a function that sums in this field. Just define your variables with gf and remove these calls if you have access to the toolbox.

Prerequisite : Summing in GF(2^8) :

Summing in GF(2^8) is not trivial, as it behaves like (Z/2Z)^8. In order to sum in this field, I have the following function.

Basically, elements in GF(2^8) are 8-tuples, each element taking a value in {0,1}. For example, (1,1,0,0,0,1,1,0) is one of them. In order to sum two tuples in this field, ones has, for each element to take the sum in Z/2Z. For example, if we want the sum of (0,0,0,1,0,0,0,1) and (1,1,1,1,1,1,1,1) : (Remember that in Z/2Z, 0+0=0 , 0+1=1 , 1+0=1 and 1+1=0)

First elements of these tuple are 0 and 1, so the first element of the sum will be 0+1=1. Do this with all elements and you obtain :

(0,0,0,1,0,0,0,1)+(1,1,1,1,1,1,1,1)=(1,1,1,0,1,1,1,0)

The function operates the same way :

1) Transform inputs into binary numbers

2) Compare each digit. If they're equal they sum up to 0 (0+0=0 , 1+1=0), if not they sum up to 1 (0+1=1 and 1+0=1).

3) Transform result back into decimal numbers

function [D] = SumInGF256(D1,D2)
%UNTITLED3 Summary of this function goes here
%   Detailed explanation goes here


A=size(D1);
P=numel(D1);
D=zeros(A);

D1=dec2bin(D1,8);
D2=dec2bin(D2,8);

% TmpD=cell(A);

for jj=1:P

    TmpD1=D1(jj,:);
    TmpD2=D2(jj,:);



    out='';

    for ii=1:8

        if isequal(TmpD1(ii),TmpD2(ii))

            out=strcat(out,'0');

        else

            out=strcat(out,'1');

        end    


    end

    D(jj)=bin2dec(out);

end

Gaussian elimination in GF(2) works exactly the same way in essance than in R or C, except it's much easier due to the fact that 1+1=0. Here's the code :

A1 =[1     0     0     1     1     0     0     0     0     0     0     0     0     0;...
     1     1     0     0     0     1     0     0     0     0     0     0     0     0;...
     1     1     1     0     0     0     1     0     0     0     0     0     0     0;...
     0     1     1     1     0     0     0     1     0     0     0     0     0     0;...
     0     0     1     1     0     0     0     0     1     0     0     0     0     0;...
     1     1     0     1     1     0     0     1     0     1     0     0     0     0;...
     1     0     1     1     0     1     0     0     1     0     1     0     0     0;...
     1     1     1     0     0     0     1     1     1     0     0     1     0     0;...
     0     1     1     1     1     1     1     0     0     0     0     0     1     0;...
     0     0     0     0     1     1     1     1     1     0     0     0     0     1;...
     0     1     1     1     1     0     1     1     1     0     1     1     1     0;...
     0     0     0     1     0     0     0     1     0     0     0     0     0     0;...
     0     0     1     0     0     0     0     1     0     0     0     0     0     0;...
     1     1     1     1     0     0     0     0     0     0     0     0     0     0;...
     0     0     1     1     0     0     0     0     1     1     0     0     0     0;...
     0     0     1     0     0     0     0     0     0     0     0     0     0     1 ];


D1=[0; 0; 0;  0 ; 0;   0 ;  0;   0 ;  0 ;  0 ;  103 ;  198 ;  105 ;  115;   175  ;  14];





for ii=1:14

   % Find ii-th pivot index between row ii and last row
   PivIndex=find(A1(ii:end,ii),1)+ii-1;

   % Switch ii-th row with Pivot row
   A1([ii PivIndex],:)=A1([PivIndex ii],:);
   D1([ii PivIndex])=D1([PivIndex ii]);

   % Find all rows other than row ii containing a 1 in column ii
   RowIndexes=find(A1(:,ii));
   RowIndexes(RowIndexes==ii)==[];

   % Add row ii to all rows in RowIndexes, do the same in D
   A1(RowIndexes,:)=mod(A1(RowIndexes,:)+repmat(A1(ii,:),numel(RowIndexes),1),2);

%% Problem with my answer was here, as the sum in GF(256) doesn t work like that. (GF(256),+) behaves like ((Z/2Z)^8,+)... See prequisite for summing in GF(256)

   % D1(RowIndexes)=mod(D1(RowIndexes)+repmat(D1(ii),numel(RowIndexes),1),256);

   D1(RowIndexes)=SumInGF256(D1(RowIndexes),repmat(D1(ii),numel(RowIndexes),1));

end

% Now A1 is diagonal, with both last rows being zero. Problem is D
% has to be 0 aswell on the 2 last positions to get 0=0..
% Check if D(15:16)==[0;0] if not the system has no solution

if isequal(D1(15:16),[0;0])

A2=A1(1:14,:);
C=D1(1:14)


else

    disp('No solution')

end

Here the output is as you wanted :

C =

103 187 125 210 181 220 161 20 175 175 187 187 220 115

BillBokeey
  • 3,168
  • 14
  • 28
0

First of all, I would like thank BillBokeey for your work. However, I am working in GF(256), it is more complex than GF(2). After google, I find a good solution for my case. This is source code for rfc-6330. In that source code, he had a function that is rfc6330_gaussian. For my question above, it is easy to apply it by

C=rfc6330_gaussian( A1, D1 )

So the result will be similar my expected result

C=[ 103
   187
   125
   210
   181
   220
   161
    20
   175
   175
   187
   187
   220
   115]

This ans. will be useful for anyone who has similar my issue.

user3051460
  • 1,455
  • 22
  • 58