Hamming Codes

Import Python Libraries: 5G-Toolkit and NumPy

tk = py.importlib.import_module('toolkit5G');
np = py.importlib.import_module('numpy');

Import Modules for Simulations: Demapper | Mapper | HammingEncoder | HammingDecoder

Demapper       = tk.SymbolMapping.Demapper;
Mapper         = tk.SymbolMapping.Mapper;
HammingEncoder = tk.ChannelCoder.HammingEncoder;
HammingDecoder = tk.ChannelCoder.HammingDecoder;

Hamming Code Configurations

m = 3;
k = int32(2^m - m - 1);
n = int32(2^m - 1);

Payload Generation

numBatches = int32(100000);
bits       = randi(2,numBatches,k)-1;
bits       = np.array(bits);

Hamming Encoder

encoder = HammingEncoder(k,n);
encBits = encoder(bits);
codeword = encBits; % No Rate-matching

Symbol Mapping

constellation_type  = "bpsk";
num_bits_per_symbol = 1;
mapperObject        = Mapper(constellation_type, num_bits_per_symbol);
symbols             = mapperObject(codeword);

Performance Evaluation: SNR vs BLER

% Plot the Results of the Simulations
close all;
figure(1)
semilogy(SNRdB, uncodedBER, LineStyle="-", LineWidth = 1.5, Marker= "o", MarkerSize=8)
hold on
semilogy(SNRdB, codedBERhard, LineStyle="--", LineWidth = 1.5, Marker= "P", MarkerSize=8)
semilogy(SNRdB, codedBERsoft, LineStyle=":", LineWidth = 1.5, Marker= "+", MarkerSize=10)
ylim([0.0001,0.2])
legend('Uncoded-BER', 'Hard Decoding', 'Soft Decoding')
grid on
figure_0.png