How to make a parity check matrix from non-systematic to systematic in Matlab? thanks

2.4k Views Asked by At

I am trying to make a parity check matrix from non-systematic to systematic. Hence, I am attaching my code below. Somewhat it is correct, but there are some problems. It would be really great if someone could help me in this.

Subject: Information theory and coding. I am working on LDPC coding and decoding. Please check the code below

MATLAB CODE:

H = [1 0 1 1 0; 0 0 1 0 1; 1 0 0 1 0; 1 0 1 1 1]

[m,n] = size(H);
k = n-m;
for i = k+1:n
%H(:,i)
ind = find(H(:,i),1,'last');
% exchanging (ind)th row and (i-k)th row
if ind < i-k
    continue;
end
if ind ~= i-k
    temp = H(ind,:);
    H(ind,:) = H(i-k,:);
    H(i-k,:) = temp;
end
I = find(H(:,i));
% Guassian elimination
for j = 1:length(I)
    if I(j) ~= i-k
        H(I(j),:) = mod(H(I(j),:)+H(i-k,:),2);
    end
end
end
Hsys = H

For e.g.

This is my H matrix:

H =

    1     0     1     1     0
    0     0     1     0     1
    1     0     0     1     0
    1     0     1     1     1

I want to have an identity matrix inside the matrix. The dimension on H matrix here is (mxn) which is (4x5).

Generally we use Gaussian elimination method to make the Identity matrix.hence, we make operations between rows. This is how we make it systematic. I should have matrix as this in the result:

Hsys =

       0     1     0     0     0
       0     0     1     0     0
       1     0     0     1     0
       0     0     0     0     1

enter image description here

I should have an identity matrix of dimension m.

1

There are 1 best solutions below

0
On

Here is how I'd do it (using Gauss-Jordan elimination):

% Not your matrix since it does not have any ones in the second column.
H=[1 1 0 1 1 0 0 1 0 0;
   0 1 1 0 1 1 1 0 0 0;
   0 0 0 1 0 0 0 1 1 1;
   1 1 0 0 0 1 1 0 1 0;
   0 0 1 0 0 1 0 1 0 1];


rows = size(H, 1);
cols = size(H, 2);

r = 1;
for c = cols - rows + 1:cols
    if H(r,c) == 0
        % Swap needed
        for r2 = r + 1:rows
            if H(r2,c) ~= 0
                tmp = H(r, :);
                H(r, :) = H(r2, :);
                H(r2, :) = tmp;
            end
        end
    end

    % Ups...
    if H(r,c) == 0
        error('H is singular');
    end

    % Forward substitute
    for r2 = r + 1:rows
        if H(r2, c) == 1
            H(r2, :) = xor(H(r2, :), H(r, :));
        end
    end

    % Back Substitution
    for r2 = 1:r - 1
        if H(r2, c) == 1
            H(r2, :) = xor(H(r2, :), H(r, :));
        end
    end

    % Next row
    r = r + 1;
end