Hamming soft decoding algorithm matlab bit error rate simulation based on spherical decoding

Table of contents

1. Theoretical basis

2. Core program

3. Simulation conclusion


1. Theoretical basis

      Hamming soft decoding is a commonly used error-correcting code decoding technology, which can effectively identify and correct errors during data transmission. Spherical decoding is a decoding technique based on spherical geometry, which can transform the decoding problem of Hamming code into the decoding problem on a spherical surface. This paper will introduce the basic principle of Hamming soft decoding based on sphere decoding in detail.

1.1 The basic principle of Hamming code

Hamming code is a binary-based linear error-correcting code proposed by Richard Hamming in 1950. In the Hamming code, the original data is encoded according to certain rules, and then some redundant information is added to form the Hamming code. Hamming codes are capable of detecting many-bit errors and correcting small numbers of errors. The basic principle of Hamming code is as follows:

  1. Encoding: Encode the original data according to certain rules, and then add redundant information to obtain the Hamming code.

  2. Transmission: transmit the Hamming code to the receiver.

  3. Decoding: After receiving the Hamming code, the receiving end performs a decoding operation to detect whether there is an error and try to correct the error.

  4. Decoding: Decode the information obtained after decoding to obtain the original data.

1.2 The basic principle of sphere decoding

Spherical decoding is a decoding technique based on spherical geometry, which can transform the decoding problem of Hamming code into the decoding problem on a spherical surface. The basic principle of sphere decoding is as follows:

  1. Constructing a spherical surface: Considering each binary bit in the Hamming code as a point on the spherical surface, a point set on the spherical surface can be obtained.

  2. Constructing a sphere: The point set on the spherical surface forms a sphere, the center point of the sphere is the origin, and the radius is $\sqrt{N}$, where $N$ is the length of the Hamming code.

  3. Construct spherical area: Divide the sphere into several spherical areas, the size of each spherical area is $2^k$, where $k$ is the number of error bits in the Hamming code.

  4. Locate the spherical area: After receiving the Hamming code, regard the error bits as points on the spherical surface, and then find the spherical area closest to these points on the spherical surface.

  5. Determine binary bits: In the found spherical area, determine which binary bits are wrong and perform error correction operations.

  6. Decoding: Decode the error-corrected information to obtain the original data.

1.3 Basic principle of Hamming soft decoding based on sphere decoding

Hamming soft decoding based on spherical decoding is a technology that applies spherical decoding technology to the soft decoding problem of Hamming codes. In soft decoding, it is assumed that each binary bit in the Hamming code has a certain probability of error, so it is necessary to estimate the probability of each binary bit and calculate the most likely original data.

The basic principle of Hamming soft decoding based on spherical decoding is as follows:

  1. Constructing a spherical surface: Considering each binary bit in the Hamming code as a point on the spherical surface, a point set on the spherical surface can be obtained.

  2. Constructing a sphere: The point set on the spherical surface forms a sphere, the center point of the sphere is the origin, and the radius is $\sqrt{N}$, where $N$ is the length of the Hamming code.

  3. Construct spherical area: Divide the sphere into several spherical areas, the size of each spherical area is $2^k$, where $k$ is the number of error bits in the Hamming code.

  4. Locating the spherical area: After receiving the Hamming code, each binary bit is regarded as a point on a sphere, and the probability distribution of each point is estimated. Then find the closest spherical area to these points on the sphere.

  5. Determine the binary bits: In the found spherical area, determine which binary bits are wrong according to the probability estimation, and perform error correction operations.

  6. Decoding: Decode the error-corrected information to obtain the original data.

        Hamming soft decoding based on spherical decoding is a technology that applies spherical decoding technology to the soft decoding problem of Hamming codes. This technology can effectively identify and correct errors in the data transmission process and is widely used.

2. Core program


clc;
clear;
close all;
warning off;
addpath(genpath(pwd));
Kc=5;           %Number of Parity bits
Nframes=3;      %Number of Frames
M=3;            %maximium bit error number M (Size of Sphere)
%M=1 means hard decision
%M=2 means soft decision with up to 2 bit errors
%M=3 means soft decision with up to 3 bit errors
% Demonstration of Soft-Hamming-Decoding based on Sphere-Decoding
ExtHammCode=1;  % 1 for extended Hamming-Code

%K_loop for more runs at higher SNR
SNRdB=0:1:7; 
K_loop=round((SNRdB-min(SNRdB)+3).^4.8);

%G: Generator Matrix, H: Paritycheck Matrix
G=bem_hammgen(Kc);

% Change Generator Matrix to extended Hamming Code
if ExtHammCode==1
    G=extHammG(G);
end

kc=size(G,1);               % Number of information bits
nc=size(G,2); Kc=nc-kc;     % Code word length

Rc=(kc)/(nc);               % Code rate Rc
EbN0=SNRdB-10*log10(Rc);    % Eb/N0

H = gen2par(G);             % generate H from G
HT=H.';                     % Transpose

%Permutation of 1,2 and 3 bit errors
[e1, e2, e3]=permute_e(nc,M);
e=[e1;e2;e3];

%syndrom calculation
syn=NaN(size(e,1),Kc);
for k=1:size(e,1)
    syn(k,:)=mod(e(k,:)*HT,2);
end

%sort rows of syndroms associated error pattern e
[s_sort,s_idx] = sortrows(syn);     % sort syn to s_sort
e_sort=e(s_idx,:);                  % sort e to e_sort in the same way as syn

e_sort=e_sort(sum(s_sort,2)>0,:);   % delete zero rows
s_sort=s_sort(sum(s_sort,2)>0,:);   % delete zero rows
 
s_de=bem_bi2de(s_sort);             % calculate decimal values from s_sort

s_pdf=hist(s_de,1:2^Kc-1);          % calculate which value occurs how often
 

%Loops for BER calculation
tic
sigma = sqrt(10.^(-SNRdB./10));         % standard diviation of noise
BER_dec_mean=zeros(1,length(SNRdB));    % mean of BER for coded system
BER_mean=zeros(1,length(SNRdB));        % mean of BER for uncoded system
for zzz=1:length(SNRdB)
    %disp(num2str(zzz))
    for kkk=1:K_loop(zzz)
        %% random bits
        x_msg=round(rand(Nframes,kc));
        
        %% channel coding
        x_code=mod(x_msg*G,2);
        
        %% Modulation and Noise
        x_mod = -(x_code-0.5)*2+1i*1E-99;
        noi=1/sqrt(2)*(randn(Nframes,nc)+1i*randn(Nframes,nc))*sigma(zzz);
        x_r=x_mod+noi;
        
        %% Demodulation
        x_llr = real(x_r)*4/sigma(zzz).^2;  % Calculate Log-Likelihood Ratios
        x_code_r=(sign(-x_llr)+1)/2;        % Received bit stream
        
        %% BER uncoded
        bit_err=abs(x_code-x_code_r);
        BER=sum(bit_err(:))/(Nframes*nc);
        BER_mean(zzz)=BER_mean(zzz)+BER;
        
        %% Decoding
        [x_decode,x_llr_new] = hamm_soft_out(HT,e_sort,s_pdf,x_llr);
        %[x_decode] = hamm_soft_really_fast(HT,e_sort,s_sort,x_llr,Kc);
        
        %% BER coded
        dec_err=abs(x_code-x_decode);
        BER_dec=sum(dec_err(:))/(Nframes*nc);
        BER_dec_mean(zzz)=BER_dec_mean(zzz)+BER_dec;
    end
    BER_mean(zzz)=BER_mean(zzz)/K_loop(zzz);
    BER_dec_mean(zzz)=BER_dec_mean(zzz)/K_loop(zzz);
    zzz
end
toc

DN='displayname';
Co='Color';
Ma='Marker';
if length(SNRdB)>1
    figure(99);hold off
    semilogy(SNRdB,BER_mean,Co,[1 0 0],Ma,'o',DN,'uncoded');
    hold on; grid on;
    semilogy(EbN0,BER_dec_mean,Co,[0 0 1],Ma,'.',...
        DN,[num2str(nc) ',' num2str(kc) '-Hamming code, ' 'M=' num2str(M)]);
    xlabel('E_b/N_0 in dB')
    ylabel('BER')
    legend show
end
UP178

3. Simulation conclusion

 

Guess you like

Origin blog.csdn.net/ccsss22/article/details/130664811