Contenuto principale

Hamming Encoder

Create Hamming code from binary vector data

  • Hamming Encoder block

Libraries:
Communications Toolbox / Error Detection and Correction / Block

Description

The Hamming Encoder block creates a Hamming code with message length K and codeword length N. For more information, see Hamming Coding.

Examples

expand all

This example shows how to model a simple encoder and decoder using appropriate vector lengths for the code and message.

The cm_hamming model includes these blocks:

  • Bernoulli Binary Generator block with Samples per frame set to 4 to match the Hamming encoder message length

  • Hamming Encoder block with default parameter values

  • Hamming Decoder block with default parameter values

  • Error Rate Calculation block with Output data set to Port

  • Display block connected to the output port of the Error Rate Calculation block

To display the vector length of signals in the model, go to Debug > Diagnostics > Information Overlays > Signals and select Signal Dimensions. The connector lines show the signal attributes. To compile the model, press Ctrl+D. Run the model to display the error rate statistics.

This example shows how to adjust the Eb/N0 setting for the AWGN channel to account for the coding rate when your simulation uses coding.

The slex_hamming_check.slx model performs forward error correction (FEC) coding on a BPSK-modulated signal that gets filtered through an AWGN channel. The model uses BPSK Modulator Baseband, AWGN Channel, and BPSK Demodulator Baseband discrete blocks to simulate a binary symmetric channel. To account for difference between the coded and uncoded Eb/N0, the AWGN channel block computes the coded Eb/N0 as Eb/N0 + 10log10(K/N) dB, where K/N is the code rate and Eb/N0 is the uncoded Eb/N0. The Hamming Encoder block has an input bit period of 1 second and the output bit period decreases, by a factor of the K/N code rate, to 4/7 seconds. Due to the coding rate, the Binary Symmetric Channel has a bit period of 4/7 seconds.

The model initializes variables used to configure block parameters by using the PreLoadFcn callback function. For more information, see Model Callbacks (Simulink).

model = 'slex_hamming_check';
open_system(model);

The AWGN channel block must also configure the Number of bits per symbol and Input signal power, referenced to 1 ohm (watts) parameter settings based on the modulated signal. This example uses BPSK modulation, so the AWGN Channel block has the number of bits per symbol set to 1. The model includes a Power Meter block that measures the signal power at the AWGN input to confirm the setting required for the input signal power of the AWGN Channel block.

To compare simulation with theory, produce error rate results and a plot. The theoretical channel error probability for the coded signal is Q(sqrt(2*Ebc/N0)), where Q() is the standard Q function and Ebc/N0 is the coded Eb/N0 in linear units (not in dB). Compute the theoretical BER upper limit bound of a linear, rate 4/7 block code with a minimum distance of 3, and hard decision decoding for a BPSK-modulated signal in AWGN over a range of Eb/N0 values by using the bercoding function. Simulate the slex_hamming_check model over the same range of Eb/N0 values.

EbNoVec = 0:2:10;
theorBER = bercoding(EbNoVec,'block','hard',7,4,3);

berVecBSC  = zeros(length(EbNoVec),3);
for n   = 1:length(EbNoVec)
    EbNo = EbNoVec(n);
    sim(model);
    berVecBSC(n,:) = berBSC(end,1);
end

Plot the results by using the semilogy function to show the nearly identical results. The model has the Error Rate Calculation block configured to run each Eb/N0 point until 200 errors occur or the block receives 10^6 bits.

semilogy( ...
    EbNoVec,berVecBSC(:,1),'d', ...
    EbNoVec,theorBER,'-');
legend('BSC BER','Theoretical BER', ...
    Location="southwest");
xlabel("Eb/N0 (dB)");
ylabel("Error Probability");
title("Bit Error Probability");
grid on;

Ports

Input

expand all

Message to encode, specified as a column vector input signal containing K elements. The Message length K, or M-degree primitive polynomial parameter determines K. This port is unnamed on the block mask.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | Boolean

Output

expand all

Encoded message, returned as a binary column vector containing N elements and having the same data type as the input port, In. The Codeword length, N parameter determines N. This port is unnamed on the block mask.

Parameters

expand all

To edit block parameters interactively, use the Property Inspector. From the Simulink® Toolstrip, on the Simulation tab, in the Prepare gallery, select Property Inspector.

Codeword length, specified as a positive integer of the form N = 2M – 1, where M is an integer greater than or equal to 3. For more information, see Hamming Coding. The codeword length is also the output vector length.

Message length of the Hamming code or an M-degree primitive polynomial.

  • When this parameter is an integer, the value must equal (NM), where N is the Codeword length, N parameter value and M is the degree of a primitive polynomial.

  • When this parameter is a vector, the vector must represent a primitive polynomial for GF(2M). For more information, see Hamming Coding.

Block Characteristics

Data Types

Boolean | double | fixed point | integer | single

Multidimensional Signals

no

Variable-Size Signals

no

More About

expand all

Extended Capabilities

expand all

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced before R2006a