📜  使用MATLAB的线性块代码

📅  最后修改于: 2021-04-16 08:16:26             🧑  作者: Mango

代码字的任何线性混合同样仅是代码字。因此,在编码中,线性码是纠错码。尽管可以将turbo码视为这两种类型的一半,但线性码通常分为块码和卷积码。与不同的代码相比,线性代码考虑到更有效的编码和解密计算。

线性代码用于前向错误调整中,并应用于在通信信道上发送符号(例如位)的技术方法中,因此,如果通信中发生错误,则消息的受益人可以修改或识别某些错误堵塞。线性分组代码中的代码字是使用比要发送的第一激励更大数量的符号来编码的符号块。

让我们看一下线性块代码的MATLAB代码。

% Given H Matrix
H = [1 0 1 1 1 0 0;
     1 1 0 1 0 1 0;
     0 1 1 1 0 0 1]
  
k = 4;
n = 7;
  
% Generating G Matrix
  
% Taking the H Matrix Transpose
P = H';  
  
% Making a copy of H Transpose Matrix
L = P;  
  
% Taking the last 4 rows of L and storing
L((5:7), : ) = [];  
  
% Creating a Identity matrix of size K x K
I = eye(k);  
  
% Making a 4 x 7 Matrix
G = [I L]  
  
% Generate U data vector, denoting all information sequences
no = 2 ^ k
  
% Iterate through an Unit-Spaced Vector
for i = 1 : 2^k  
  
  % Iterate through Vector with Specified Increment 
  % or in simple words here we are decrementing 4 till we get 1    
  for j = k : -1 : 1 
    if rem(i - 1, 2 ^ (-j + k + 1)) >= 2 ^ (-j + k)
      u(i, j) = 1;
    else
      u(i, j) = 0;
    end
      
    % To avoid displaying each iteration/loop value
    echo off; 
  end
end
  
echo on;
u
  
% Generate CodeWords
c = rem(u * G, 2)
  
% Find the min distance
w_min = min(sum((c(2 : 2^k, :))'))
  
% Given Received codeword
r = [0 0 0 1 0 0 0];
r
  
p = [G(:, n - k + 2 : n)];
  
%Find Syndrome
ht = transpose(H)
  
s = rem(r * ht, 2)
  
for i = 1 : 1 : size(ht)
  if(ht(i,1:3)==s)
    r(i) = 1-r(i);
    break;
  end
end
  
disp('The Error is in bit:')
disp(i)
  
disp('The Corrected Codeword is :')
disp(r)

输出:

H =

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

G =

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

no =  16
u =

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

c =

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

w_min =  3

r
r =

   0   0   0   1   0   0   0

ht =

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


s =

   1   1   1


The Error is in bit:
 4

The Corrected Codeword is :
   0   0   0   0   0   0   0