<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<doxygen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="compound.xsd" version="1.17.0" xml:lang="en-US">
  <compounddef id="page_fec" kind="page">
    <compoundname>page_fec</compoundname>
    <title>Forward Error Correction</title>
    <briefdescription>
    </briefdescription>
    <detaileddescription>
<sect1 id="page_fec_1fec_introduction">
<title>Introduction</title><para>This is the gr-fec package. It contains all of the forward error correction (FEC) blocks, utilities, and examples. To use the FEC blocks, the Python namespaces is in gnuradio.fec, which would be normally imported as:</para>
<para><programlisting><codeline><highlight class="normal">from<sp/><ref refid="namespacegnuradio" kindref="compound">gnuradio</ref><sp/></highlight><highlight class="keyword">import</highlight><highlight class="normal"><sp/>fec</highlight></codeline>
</programlisting></para>
<para>See the Doxygen documentation for details about the blocks available in this package.</para>
<para>A quick listing of the details can be found in Python after importing by using:</para>
<para><programlisting><codeline><highlight class="normal">help(fec)</highlight></codeline>
</programlisting></para>
</sect1>
<sect1 id="page_fec_1fec_using">
<title>Using the FEC API</title><para>FEC is a complex issue to implement in a generic, generally usable way. To help with these issues, the FEC API operates on two levels: the coder variables and the coder deployments. The variables implement the encoding and decoding methods whereas the deployments set up the variables, make sure the input data is formatted properly, run the coder variable, and then pass on the data for follow-on processing.</para>
<para>In a GNU Radio flowgraph, the deployments are GNU Radio blocks that we insert into the flowgraph. The deployments use the API of the coder variables to interact with the scheduler and set up the input/output item buffers that move data between blocks. The intent of the API is to be able to build the coding variables that are general enough for easy use in multiple situations. We then construct deployments to control the interaction between the data and the variable. GNU Radio provides deployments for a number of situations, but these should not be considered the only ways to deploy the decoders.</para>
<sect2 id="page_fec_1fec_deployments">
<title>Deployments</title><para>Generally speaking, encoder deployments take in bits and produce bits (i.e., unpacked bytes with 1 bit per byte). Decoder deployments take in floats and produce bits. The floats are generally meant to represent soft decisions. If the demodulator does not produce soft decisions, an easy alternative is to convert the hard decision 0&apos;s and 1&apos;s to -1 and +1 floats. The main departure from this model is when using a PDU-based modulator or demodulator, for which we can look at using the asynchronous message passing system. In this instance, passing bits is not natural, so we need to create a deployment that can handle packed bytes. GNU Radio has the gr::fec::asycn_encoder and <ref refid="classgr_1_1fec_1_1async__decoder" kindref="compound">gr::fec::async_decoder</ref> deployments that work in this mode.</para>
<para>Some coding variables handle inputs and outputs differently than the described deployments. Using the FEC API provides concepts of input and output conversion properties that help us create deployments to convert the data streams to the required format of the variable.</para>
<sect3 id="page_fec_1fec_deploy_simple">
<title>Streaming Deployments</title><para>For the encoder deployments, the <ref refid="classgr_1_1fec_1_1encoder" kindref="compound">gr::fec::encoder</ref> block is a relatively simple deployment for the encoding variables. It uses the encoding object information about the input/output sizes and input/output item sizes to set up the interaction with the scheduler. Typically, a coder will add redundancy to the stream making the output longer by some amount than the input stream. This block simply takes in an encoder object, specifically an object that derives from <ref refid="classgr_1_1fec_1_1generic__encoder" kindref="compound">gr::fec::generic_encoder</ref>. It also takes in the input and output items sizes that the encoder will expect, which we can just ask the encoder for. Typically, the encodes expect unpacked bytes in and unpacked bytes out.</para>
<para>The <ref refid="classgr_1_1fec_1_1decoder" kindref="compound">gr::fec::decoder</ref> block is a similarly simple deployment for the decoding variables. It uses the decoding variable information about the input/output sizes and input/output item sizes to set up the interaction with the scheduler. Since a decoder typically uses the redundancy from the input stream to correct for errors, the input stream will be longer than the output stream by the rate of the code. This block simply takes in an decoder object, specifically an object that derives from <ref refid="classgr_1_1fec_1_1generic__decoder" kindref="compound">gr::fec::generic_decoder</ref>. It also takes in the input and output items sizes that the decoder will expect, which we can just ask the encoder for. The deployment expects a floating point stream input, though the decoder variables may take a float input or a byte. If using a byte format, it could be a hard decision or a quantized soft decision, depending on how the decoder object behaves.</para>
<para>Normally, though, we don&apos;t work directly with these simple encoder() or decoder() deployments but a wrapper around those blocks. GNU Radio&apos;s gr-fec package comes with two Python deployments to make things easier: fec.extended_encoder and fec.extended_decoder. For one thing, these extended hier_block2 blocks take care of the puncturing and depuncturing operations often found in FEC codes. The other thing that these blocks do for us is read the API of the encoder/decoder variables to properly convert the data in or out, depending on how the coding object works.</para>
<para>For instance, a generic_decoder takes in floating point values (which should be soft decisions). However, a decoder might instead want to work on 8-bit quantized soft decisions and so expects unsigned chars. Specifying &apos;uchar&apos; as the <ref refid="classgr_1_1fec_1_1generic__decoder_1a0da070002d16590ec2f1277431ba2afb" kindref="member">gr::fec::generic_decoder::get_input_conversion()</ref> of the decoder block tells the fec.extended_decoder to convert the float to a byte.</para>
<para>In GRC, we would add an &quot;FEC Extended Encoder&quot; to our transmitter or an &quot;FEC Extended Decoder&quot; to the receiver. We would then use one of the encoder or decoder FEC variable blocks to define the parameters of the particular code we want to use. We can find these codes under the [Error Coding] category in GRC. The encoders are found under [Encoders] and similarly the decoders under the [Decoders] categories. Putting these onto the canvas creates a variable that we can then pass to the extended encoder or decoder deployment blocks.</para>
<para>Most of the parameters of the encoder and decoder definitions should be fairly obvious based on the type of code. See the documentation for each coding object for more details. In the following section <ref refid="page_fec_1fec_parallelism" kindref="member">Parallelism</ref>, we explain the Parallelism and Dimension properties.</para>
<para>See fec/fecapi_encoders.grc and fec/fecapi_decoders.grc in the installed examples for an example of how to work with these deployments given the three initial FEC coders available.</para>
</sect3>
<sect3 id="page_fec_1fec_deploy_tag_stream">
<title>Tagged Stream Deployments</title><para>GNU Radio&apos;s gr-fec also comes with simple deployments for <ulink url="https://wiki.gnuradio.org/index.php/Tagged_Stream_Blocks">Tagged Stream Blocks</ulink> blocks. These deployments work similarly to the normal streaming deployments but fit into a tagged stream system by setting a tagged stream tag to control the frame size. Like all tagged stream blocks, they expect the tag to be located in the stream in order to properly function.</para>
<para>The simplest form of the tagged stream deployments are just the C++ blocks <ref refid="classgr_1_1fec_1_1tagged__encoder" kindref="compound">gr::fec::tagged_encoder</ref> and <ref refid="classgr_1_1fec_1_1tagged__decoder" kindref="compound">gr::fec::tagged_decoder</ref>. These do not handle any input or output conversion. They expect the inputs to be already properly formatted for the encoding/decoding variables, and the outputs will be whatever the variable naturally produce.</para>
<para>In the tagged stream deployments, the frame size set for a variable is no longer the static frame size like we expected in the streaming data implementations. Instead, we look at the frame size of the encoder/decoder variable during construction of the deployment as the maximum frame size, or a maximum transmission unit (MTU). This allows us to set up some internal memory to handle up to the required maximum length. When a tagged stream comes into this block, the frame size is then set based on that tagged stream information. If the frame is larger than the established MTU, a warning is sent out and the deployment only handles up to the MTU of the given frame.</para>
<para>The extended Python tagged deployments, fec.extended_tagged_encoder and fec.extended_tagged_decoder, offer additional handling of the FEC API like we saw with the fec.extended_encoder and fec.extended_decoder. These extended deployments wrap up the puncturing and depuncturing as well as use the FEC API to do any input and output translation for the formatting of data streams. The fec.extended_tagged_encoder expects unpacked bits in and produces unpacked bits out. The fec.extended_tagged_decoder takes in floats (generally soft decisions from -1 to 1) and produces unpacked bits.</para>
<para>See fec/fecapi_tagged_encoders.grc and fec/fecapi_tagged_decoders.grc in the installed examples for an example of how to work with these deployments given the three initial FEC coders available.</para>
</sect3>
<sect3 id="page_fec_1fec_deploy_async">
<title>Asynchronous Deployments</title><para>The final standard deployment shipped with GNU Radio is for asynchronous <ulink url="https://wiki.gnuradio.org/index.php/Message_Passing">Message Passing</ulink> and handling PDUs: <ref refid="classgr_1_1fec_1_1async__encoder" kindref="compound">gr::fec::async_encoder</ref> and <ref refid="classgr_1_1fec_1_1async__decoder" kindref="compound">gr::fec::async_decoder</ref>.</para>
<para>Unlike the other deployments, these C++ deployments do not also have an extended Python deployment. Because this deployment uses message passing, we cannot easily build up a hierarchical block of message passing blocks to satisfy the input/output translations like we&apos;ve done with the other forms of deployment. Instead, the input/output formatting is taken care of inside this deployment itself. Further, because this form of moving data anticipates data being moved in packets, these deployments cannot work with any FEC code that requires a history (see generic_decoder::get_history). Right now, this means that the async message passing deployments cannot work with convolutional codes (<ref refid="classgr_1_1fec_1_1code_1_1cc__encoder" kindref="compound">gr::fec::code::cc_encoder</ref> and <ref refid="classgr_1_1fec_1_1code_1_1cc__decoder" kindref="compound">gr::fec::code::cc_decoder</ref>) in streaming mode because it would require data from the next frame to finish off decoding the current frame.</para>
<para>These deployments also work in two distinct modes. They can work in unpacked mode where inputs are messages of bits, or they may work in packed mode where messages are PDUs. The distinction is that the packed mode PDU&apos;s are the standard protocol data units (PDUs) that encompass full packets of data. This allows these async deployments to be used easily within PDU-based applications, such as encoding a packet with a CRC attached.</para>
<para>When in packed or PDU mode, the encoder deployment has the option of reversing the bits during unpacking and packing. Like the extended deployments for the other data modes, these deployments manipulate the input data to the format expected by the encoding or decoding variables using calls to the FEC API. Because most of the coders work off unpacked bits, the incoming PDUs must first be unpacked into bits and the repacked again into the original PDU. The <ref refid="classgr_1_1blocks_1_1kernel_1_1pack__k__bits" kindref="compound">gr::blocks::kernel::pack_k_bits</ref> and <ref refid="classgr_1_1blocks_1_1kernel_1_1unpack__k__bits" kindref="compound">gr::blocks::kernel::unpack_k_bits</ref> kernels are used here, and they can change the direction on how to pack and unpack. Because different data processing blocks, framing, deframing, and other operations may arbitrarily set the format of the bits and the ordering, we provide the options of unpacking and packing directions in the deployments. However, the <ref refid="classgr_1_1fec_1_1async__decoder" kindref="compound">gr::fec::async_decoder</ref> still expects the input to be soft decisions with one decision per item, so we only say whether this deployment outputs packed PDUs or not and the packing direction.</para>
<para>For an example of using the asynchronous in PDU mode, see fec/fecapi_async_packed_decoders.grc. See fec/fecapi_async_to_stream.grc for an example of mixing the packed PDU mode encoder with a tagged stream decoder. This example shows the PDU input having a CRC32 appended to the uncoded stream that is then checked after the packet is decoded.</para>
<para>For an example of the async deployment using unpacked bits, see fec/fecapi_async_encoders.grc and fec/fecapi_async_decoders.grc.</para>
</sect3>
</sect2>
<sect2 id="page_fec_1fec_coding_vars">
<title>Encoding/Decoding Variables</title><para>GNU Radio currently has a minor subset of coders available:</para>
<para>Coders:</para>
<para><itemizedlist>
<listitem><para><ref refid="classgr_1_1fec_1_1code_1_1dummy__encoder" kindref="compound">gr::fec::code::dummy_encoder</ref> </para>
</listitem>
<listitem><para><ref refid="classgr_1_1fec_1_1code_1_1repetition__encoder" kindref="compound">gr::fec::code::repetition_encoder</ref> </para>
</listitem>
<listitem><para><ref refid="classgr_1_1fec_1_1code_1_1cc__encoder" kindref="compound">gr::fec::code::cc_encoder</ref> </para>
</listitem>
<listitem><para><ref refid="classgr_1_1fec_1_1code_1_1ccsds__encoder" kindref="compound">gr::fec::code::ccsds_encoder</ref> </para>
</listitem>
<listitem><para><ref refid="classgr_1_1fec_1_1code_1_1polar__encoder" kindref="compound">gr::fec::code::polar_encoder</ref> </para>
</listitem>
<listitem><para><ref refid="classgr_1_1fec_1_1code_1_1ldpc__par__mtrx__encoder" kindref="compound">gr::fec::code::ldpc_par_mtrx_encoder</ref> </para>
</listitem>
<listitem><para><ref refid="classgr_1_1fec_1_1code_1_1ldpc__gen__mtrx__encoder" kindref="compound">gr::fec::code::ldpc_gen_mtrx_encoder</ref></para>
</listitem>
</itemizedlist>
Decoders: <itemizedlist>
<listitem><para><ref refid="classgr_1_1fec_1_1code_1_1dummy__decoder" kindref="compound">gr::fec::code::dummy_decoder</ref> </para>
</listitem>
<listitem><para><ref refid="classgr_1_1fec_1_1code_1_1repetition__decoder" kindref="compound">gr::fec::code::repetition_decoder</ref> </para>
</listitem>
<listitem><para><ref refid="classgr_1_1fec_1_1code_1_1cc__decoder" kindref="compound">gr::fec::code::cc_decoder</ref> </para>
</listitem>
<listitem><para><ref refid="classgr_1_1fec_1_1code_1_1polar__decoder__sc" kindref="compound">gr::fec::code::polar_decoder_sc</ref> </para>
</listitem>
<listitem><para><ref refid="classgr_1_1fec_1_1code_1_1polar__decoder__sc__list" kindref="compound">gr::fec::code::polar_decoder_sc_list</ref> </para>
</listitem>
<listitem><para><ref refid="classgr_1_1fec_1_1ldpc__decoder" kindref="compound">gr::fec::ldpc_decoder</ref> </para>
</listitem>
<listitem><para><ref refid="classgr_1_1fec_1_1code_1_1ldpc__bit__flip__decoder" kindref="compound">gr::fec::code::ldpc_bit_flip_decoder</ref></para>
</listitem>
</itemizedlist>
</para>
<sect3 id="page_fec_1fec_dummy">
<title>Dummy Encoder/Decoder</title><para>When building a new FECAPI encoder or decoder variable, the <ref refid="classgr_1_1fec_1_1code_1_1dummy__encoder" kindref="compound">gr::fec::code::dummy_encoder</ref> / <ref refid="classgr_1_1fec_1_1code_1_1dummy__decoder" kindref="compound">gr::fec::code::dummy_decoder</ref> blocks are a good place to start. This coding set does no processing on the data. For the encoder, each bit is simply passed through directly. For the dummy decoder, the input data are floats, so -1&apos;s become 0 and 1&apos;s stay as 1, but nothing else is done to the data. Mainly, these blocks are used for references and to make it easy to compare implementations with and without codes by easily dropping in these objects instead of restructuring the entire flowgraph. The ber_curve_gen.grc example file uses the dummy codes to show the curve to compare against the actual codes.</para>
</sect3>
<sect3 id="page_fec_1fec_repetition">
<title>Repetition Encoder/Decoder</title><para>The simplest example of FEC is the repetition code in <ref refid="classgr_1_1fec_1_1code_1_1repetition__encoder" kindref="compound">gr::fec::code::repetition_encoder</ref> and <ref refid="classgr_1_1fec_1_1code_1_1repetition__decoder" kindref="compound">gr::fec::code::repetition_decoder</ref>. The basic idea is to repeat the information several times so that even if parts of the received message are corrupted, the majority of the data is received correctly and the original message can be discerned. The repetition decoder is not particularly sophisticated and other coders offer better performance, but it is useful for comparison.</para>
</sect3>
<sect3 id="page_fec_1fec_cc">
<title>Convolutional Encoder/Decoder</title><para>Although mentioned in the convolutional coder and decoder classes, it is worth another mention. The <ref refid="classgr_1_1fec_1_1code_1_1cc__encoder" kindref="compound">gr::fec::code::cc_encoder</ref> is a generic convolutional encoder that can take any value of K, rate, and polynomials to encode a data stream. However, the <ref refid="classgr_1_1fec_1_1code_1_1cc__decoder" kindref="compound">gr::fec::code::cc_decoder</ref> is not as general, even though it is technically parameterized as such. The <ref refid="classgr_1_1fec_1_1code_1_1cc__decoder" kindref="compound">gr::fec::code::cc_decoder</ref> block currently <emphasis>only</emphasis> uses K=7, rate=2, and two polynomials (because the rate is two). We can, in fact, alter the polynomials, but a default of [109, 79] is typically. Eventually, we will make this block more generic for different rates and constraint lengths and take this particular code implementation as the set CCSDS decoder, much like we have the <ref refid="classgr_1_1fec_1_1code_1_1ccsds__encoder" kindref="compound">gr::fec::code::ccsds_encoder</ref> class.</para>
</sect3>
</sect2>
<sect2 id="page_fec_1fec_parallelism">
<title>Parallelism</title><para>The code variables in GNU Radio Companion have the ability to create multiple encoder/decoder variables by selecting the level of parallelism. It is up the encoder to understand how to handle the parallelism. The following discussion explains the difference between the two levels and how and when to use. Generally, normal applications will just use a single level of parallelism.</para>
<para>The GRC variable declarations for the different coders has a setting for <emphasis>Parallelism</emphasis>, which can be either 1 or 2. If set to 1, then the resulting variable is a list of coder blocks with the same settings. If set to 2, then the resulting variable is a list of lists of coder blocks. The code that accepts these variables must understand how to handle the parallelism. Most applications would set this to 1.</para>
<para>The standard fec.extended_encoder (&quot;FEC Extended Encoder&quot; in GRC) and fec.extended_decoder (&quot;FEC Extended Decoder&quot; in GRC) can handle a Parallelism of 1. They accept a list of coder variables as defined by Dimension 1 and can multithread the application based on the &quot;Threading Type&quot; setting:</para>
<para><itemizedlist>
<listitem><para><bold>None</bold>: does no parallel threading of the coders. Even if Dimension 1 is &gt; 1, the encoder/decoder will ignore this setting and only use the first object in the list.</para>
</listitem>
</itemizedlist>
<itemizedlist>
<listitem><para><bold>Ordinary</bold>: all &quot;Dimension 1&quot; number (N) of encoder/decoder blocks will be used in parallel. The hier_block2 will block deinterleave the packets into N streams (using <ref refid="classgr_1_1blocks_1_1deinterleave" kindref="compound">gr::blocks::deinterleave</ref> with a value of blocksize as the frame length and no relative rate changes) and pass these to each of the N coders to process the frames in parallel. The output of each coder is then interleaved back together to make a single output stream.</para>
</listitem>
</itemizedlist>
<itemizedlist>
<listitem><para><bold>Capillary</bold>: all &quot;Dimension 1&quot; number (N) of encoder/decoder blocks will be used in parallel, much like in the <bold>Ordinary</bold> mode. In this mode, however, the frames get split up in a tree-like fashion, where each branch launches 2 more branches. This means that N must be a factor of 2 for this mode to work. It tends to handle the load of the encoders/decoders better than the <bold>Ordinary</bold> mode.</para>
</listitem>
</itemizedlist>
Note that the threading modes only work when using constant-length frames. If using the coders in tagged stream mode where the frame lengths may change, the <bold>Ordinary</bold> and <bold>Capillary</bold> modes are not available.</para>
<para>The GRC example &quot;ber_curve_gen.grc&quot; uses a Parallelism of 2. This creates a list of lists of coders. The first dimension of the list corresponds to the number of Es/N0 values being used in the BER simulation. This allows the application to process all values of Es/N0 simultaneously. Dimension 2 in this case allows the same concept of parallelism discussed above with the <bold>None</bold>, <bold>Ordinary</bold>, and <bold>Capillary</bold> models of threading.</para>
</sect2>
</sect1>
<sect1 id="page_fec_1fec_api">
<title>The API of the FECAPI</title><para>The FECAPI defined by the parent generic_encoder and generic_decoder classes defines a set of virtual functions, some pure virtual, to allow the encoders/decoders to interact with the GNU Radio blocks. See the associated documentation of the generic_encoder and generic_decoder classes to know more about each of the API functions, some of which a child class is <emphasis>required</emphasis> to implement.</para>
<para>The functions of the encoder and decoder are:</para>
<para><itemizedlist>
<listitem><para>double <ref refid="classgr_1_1fec_1_1generic__encoder_1a0c47f99e01942d4316b5b24619aab58c" kindref="member">gr::fec::generic_encoder::rate()</ref> </para>
</listitem>
<listitem><para>int <ref refid="classgr_1_1fec_1_1generic__encoder_1a95db2880c3e02e52564ea6a04b6ee243" kindref="member">gr::fec::generic_encoder::get_input_size()</ref> </para>
</listitem>
<listitem><para>int <ref refid="classgr_1_1fec_1_1generic__encoder_1aa72462435284fc66d3b3a2a5b366f4ea" kindref="member">gr::fec::generic_encoder::get_output_size()</ref> </para>
</listitem>
<listitem><para>int gr::fec::generic_encoder::get_history() </para>
</listitem>
<listitem><para>float gr::fec::generic_encoder::get_shift() </para>
</listitem>
<listitem><para>const char* <ref refid="classgr_1_1fec_1_1generic__encoder_1adf46ba604e83c7b8e8ab3b6bd5bbb637" kindref="member">gr::fec::generic_encoder::get_input_conversion()</ref> </para>
</listitem>
<listitem><para>const char* <ref refid="classgr_1_1fec_1_1generic__encoder_1afdbb6e85bffb01a6366369d6df98b986" kindref="member">gr::fec::generic_encoder::get_output_conversion()</ref> </para>
</listitem>
<listitem><para>bool <ref refid="classgr_1_1fec_1_1generic__encoder_1ac6a41c2f21012253a43cebc7e7b98039" kindref="member">gr::fec::generic_encoder::set_frame_size(unsigned int frame_size)</ref></para>
</listitem>
</itemizedlist>
Note: there is no get_input_item_size (or output) as the encoders always expect to work on bits.</para>
<para><itemizedlist>
<listitem><para>double <ref refid="classgr_1_1fec_1_1generic__decoder_1a32869de99deaec078e6b3bdc01444795" kindref="member">gr::fec::generic_decoder::rate()</ref> </para>
</listitem>
<listitem><para>int <ref refid="classgr_1_1fec_1_1generic__decoder_1a68f0c06cc9b57e421d4d755fc7eb60d5" kindref="member">gr::fec::generic_decoder::get_input_size()</ref> </para>
</listitem>
<listitem><para>int <ref refid="classgr_1_1fec_1_1generic__decoder_1a0cad8d8b1977ebb9184b6c36ed73db9a" kindref="member">gr::fec::generic_decoder::get_output_size()</ref> </para>
</listitem>
<listitem><para>int <ref refid="classgr_1_1fec_1_1generic__decoder_1a9037426d33b865dda50055380f9b85c8" kindref="member">gr::fec::generic_decoder::get_history()</ref> </para>
</listitem>
<listitem><para>float <ref refid="classgr_1_1fec_1_1generic__decoder_1a7c46fd20d994c05ece2aa93dc8d3a926" kindref="member">gr::fec::generic_decoder::get_shift()</ref> </para>
</listitem>
<listitem><para>int <ref refid="classgr_1_1fec_1_1generic__decoder_1a1f4ba1fe5a0e9b3508724b48400ff537" kindref="member">gr::fec::generic_decoder::get_input_item_size()</ref> </para>
</listitem>
<listitem><para>int <ref refid="classgr_1_1fec_1_1generic__decoder_1a558263fff172b7867ed96afccb93078f" kindref="member">gr::fec::generic_decoder::get_output_item_size()</ref> </para>
</listitem>
<listitem><para>const char* <ref refid="classgr_1_1fec_1_1generic__decoder_1a0da070002d16590ec2f1277431ba2afb" kindref="member">gr::fec::generic_decoder::get_input_conversion()</ref> </para>
</listitem>
<listitem><para>const char* <ref refid="classgr_1_1fec_1_1generic__decoder_1ae42dd367cb736e35ea3058536597d559" kindref="member">gr::fec::generic_decoder::get_output_conversion()</ref> </para>
</listitem>
<listitem><para>bool <ref refid="classgr_1_1fec_1_1generic__decoder_1a6da8f43baf97fab0691e80355f2fbb74" kindref="member">gr::fec::generic_decoder::set_frame_size(unsigned int frame_size)</ref></para>
</listitem>
</itemizedlist>
Whenever an FECAPI object refers to the frame size, it always means the number of bits in the uncoded frame. This means the number of bits going into an encoder and the number of bits coming out of a decoder.</para>
</sect1>
<sect1 id="page_fec_1fec_examples">
<title>FEC Examples</title><para><itemizedlist>
<listitem><para>ber_curve_gen.grc </para>
</listitem>
<listitem><para>ber_curve_gen_ldpc.grc </para>
</listitem>
<listitem><para>ber_test.grc </para>
</listitem>
<listitem><para>fecapi_decoders.grc </para>
</listitem>
<listitem><para>fecapi_encoders.grc </para>
</listitem>
<listitem><para>fecapi_tagged_decoders.grc </para>
</listitem>
<listitem><para>fecapi_tagged_encoders.grc </para>
</listitem>
<listitem><para>fecapi_async_decoders.grc </para>
</listitem>
<listitem><para>fecapi_async_encoders.grc </para>
</listitem>
<listitem><para>fecapi_async_to_stream.grc</para>
</listitem>
</itemizedlist>
</para>
</sect1>
<sect1 id="page_fec_1fec_ldpc">
<title>LDPC Codes</title><para>GNU Radio supports a few different ways of handling LDPC codes. There are many types of encoders and decoders available, and defining the code can come in many different flavors. GNU Radio has two encoders and two decoders.</para>
<sect2 id="page_fec_1fec_alist">
<title>Describing the alist Files</title><para>We use an alist file format for storing the matrices in files. The alist format looks like:</para>
<para><verbatim>ncolumns nrows
max_col_weight max_row_weight
list_col_weights
list_row_weights
column_1_indices
row_1_indices
</verbatim></para>
<para>The ncolumns is the number of column in the matrix and nrows is the number of rows, so this would define a (nrows x ncolumns) matrix. The column and row weights are how many 1&apos;s are in each column or row, respectively. The alist format tracks the maximum weight for all columns and all rows as well as lists all of the weights for each column one one line and each row on another. Then, the alist format lists the indices of all 1&apos;s in the columns followed by a list of the indices of all 1&apos;s in the rows. The matrix can be constructed using either the column or row indices lists, and a check would be to make sure they create the same matrix. Because LDPC deals with sparse matrices, the weights should be small relative to the number of columns/rows. All of the indices are 1 based, not 0.</para>
<para>And example is the simple_g_matrix.alist file that comes with GNU Radio as a sample generator matrix. The generator matrix is in the form [I | P] where I is the (k x k) identity matrix and P is a (k x (n-k)) matrix representing the parity information. Together, G is a (k x n) matrix. The alist file looks like:</para>
<para><verbatim>8 4
3 4
1 1 1 1 3 3 3 3
4 4 4 4
1
2
3
4
2 3 4
1 3 4
1 2 4
1 2 3
1 6 7 8
2 5 7 8
3 5 6 8
4 5 6 7
</verbatim></para>
<para>So it has 8 columns and 4 rows. The maximum number of 1&apos;s in any column is 3 and the maximum number of 1&apos;s in any row is 4. The next two lines are the weights for each column and each row. Then we have 8 lines that are the indices of the 1&apos;s in the columns followed by 4 lines that are the indices of the 1&apos;s in the rows. Note that the number of items in any of these rows matches up with the numbers in the column and matrix weight lists. Let&apos;s use the either the column or rows to construct the matrix.</para>
<para><verbatim>1 0 0 0 0 1 1 1
0 1 0 0 1 0 1 1
0 0 1 0 1 1 0 1
0 0 0 1 1 1 1 0
</verbatim></para>
<para>Now go back and do it with the other set of of indices to verify. We can also count up the 1&apos;s along the columns and rows to verify the top few lines for even more check.</para>
<para>Some info on the alist files online can be found here:</para>
<para><itemizedlist>
<listitem><para><ulink url="http://www.inference.phy.cam.ac.uk/mackay/codes/alist.html">http://www.inference.phy.cam.ac.uk/mackay/codes/alist.html</ulink> </para>
</listitem>
<listitem><para><ulink url="http://www.inference.phy.cam.ac.uk/mackay/codes/">http://www.inference.phy.cam.ac.uk/mackay/codes/</ulink></para>
</listitem>
</itemizedlist>
</para>
</sect2>
<sect2 id="page_fec_1fec_ldpc_encoders">
<title>LDPC Encoders</title><para>There are two LDPC encoder variables but a few ways to set them up. They are:</para>
<para><itemizedlist>
<listitem><para><ref refid="classgr_1_1fec_1_1code_1_1ldpc__par__mtrx__encoder" kindref="compound">gr::fec::code::ldpc_par_mtrx_encoder</ref> </para>
</listitem>
<listitem><para><ref refid="classgr_1_1fec_1_1code_1_1ldpc__gen__mtrx__encoder" kindref="compound">gr::fec::code::ldpc_gen_mtrx_encoder</ref></para>
</listitem>
</itemizedlist>
Both encoders take in a matrix, but there are two different forms of the matrix that they work with. The <ref refid="classgr_1_1fec_1_1code_1_1ldpc__par__mtrx__encoder" kindref="compound">gr::fec::code::ldpc_par_mtrx_encoder</ref> takes a parity check matrix, H, which is in upper triangular form. The <ref refid="classgr_1_1fec_1_1code_1_1ldpc__gen__mtrx__encoder" kindref="compound">gr::fec::code::ldpc_gen_mtrx_encoder</ref> takes in a generator matrix, G.</para>
<para>A third coder exists, <ref refid="classgr_1_1fec_1_1ldpc__encoder" kindref="compound">gr::fec::ldpc_encoder</ref>, but this is deprecated and should not be used. It&apos;s functionally equivalent to <ref refid="classgr_1_1fec_1_1code_1_1ldpc__par__mtrx__encoder" kindref="compound">gr::fec::code::ldpc_par_mtrx_encoder</ref> and still exists for compatibility reasons.</para>
<para>There are two constructors for <ref refid="classgr_1_1fec_1_1code_1_1ldpc__par__mtrx__encoder" kindref="compound">gr::fec::code::ldpc_par_mtrx_encoder</ref>. The first one, &apos;make&apos;, takes in an alist file that represents the parity matrix in the alist format described above. The &apos;make_H&apos; function makes an LDPC encoder using a prebuilt <ref refid="classgr_1_1fec_1_1code_1_1ldpc__H__matrix" kindref="compound">gr::fec::code::ldpc_H_matrix</ref> object. When using the alist file, we also need to tell it the gap size in the matrix, which is not represented in the alist file format, but it should be known or part of the file name itself.</para>
<para>The format of the parity check matrix, H, in upper triangular form is described as:</para>
<para><verbatim>[ T A B ]
[ E C D ]

T: (n - k - g) x (n - k - g)
A: (n - k - g) x g
B: (n - k - g) x k
E: g x (n - k - g)
C: g x g
D: g x k
</verbatim></para>
<para>Where n is the size of the codeword, k is the size of the information word, and g is the size of the gap. See &quot;Open-source Forward Error
Correction using GNU Radio&quot; for more description about this matrix:</para>
<para><itemizedlist>
<listitem><para><ulink url="http://arc.aiaa.org/doi/abs/10.2514/6.2015-4655">http://arc.aiaa.org/doi/abs/10.2514/6.2015-4655</ulink></para>
</listitem>
</itemizedlist>
The other encoder is <ref refid="classgr_1_1fec_1_1code_1_1ldpc__gen__mtrx__encoder" kindref="compound">gr::fec::code::ldpc_gen_mtrx_encoder</ref>. This takes a generator matrix in systematic form G=[I P] which is (k x n). The codeword x is generated from the information word s via simple matrix multiplication: <formula id="42">$ x=G^T s $</formula>.</para>
<para>Unlike the encoder using the H matrix, the <ref refid="classgr_1_1fec_1_1code_1_1ldpc__gen__mtrx__encoder" kindref="compound">gr::fec::code::ldpc_gen_mtrx_encoder</ref> only has a single make function that takes in a prebuilt generator matrix object from the class <ref refid="classgr_1_1fec_1_1code_1_1ldpc__G__matrix" kindref="compound">gr::fec::code::ldpc_G_matrix</ref>.</para>
<para>In GRC, we have a handful of blocks for manipulating the LDPC encoders and matrices:</para>
<para><itemizedlist>
<listitem><para>LDPC Encoder Definition: creates a <ref refid="classgr_1_1fec_1_1code_1_1ldpc__par__mtrx__encoder" kindref="compound">gr::fec::code::ldpc_par_mtrx_encoder</ref> FEC variable using a provided alist file and specified matrix gap. </para>
</listitem>
<listitem><para>LDPC Encoder Definition (via Parity Check): receives a prebuilt H matrix from the &quot;LDPC Parity Check Matrix&quot;. </para>
</listitem>
<listitem><para>LDPC Encoder Definition (via Generator): receives a prebuilt G matrix from the &quot;LDPC Generator Matrix&quot;. </para>
</listitem>
<listitem><para>LDPC Parity Check Matrix: constructs a parity check matrix, H, from a given alist file and matrix gap. </para>
</listitem>
<listitem><para>LDPC Generator Matrix: constructs a generator matrix, G, from a given alist file.</para>
</listitem>
</itemizedlist>
The <ref refid="classgr_1_1fec_1_1code_1_1ldpc__par__mtrx__encoder" kindref="compound">gr::fec::code::ldpc_par_mtrx_encoder</ref> uses a reduced complexity algorithm. Compared to the <ref refid="classgr_1_1fec_1_1code_1_1ldpc__gen__mtrx__encoder" kindref="compound">gr::fec::code::ldpc_gen_mtrx_encoder</ref>, this requires orders of magnitude fewer operations at each encoding step. This is accomplished by completing a significant amount of the complex matrix manipulation (including inverse, multiplication, and Gaussian elimination operations) during preprocessing. The disadvantage of this encoder is that it requires a specially formatted matrix. There are some Python tools available from GNU Radio to format a standard parity check matrix appropriately for this encoder, as well as a small library of encoding-ready matrices for use.</para>
<para>NOTE: we need to document these tools better.</para>
<para>For uses of these codes, see the FEC examples:</para>
<para><itemizedlist>
<listitem><para>fecapi_ldpc_encoders.grc </para>
</listitem>
<listitem><para>fecapi_tagged_ldpc_encoders.grc </para>
</listitem>
<listitem><para>fecapi_async_ldpc_encoders.grc</para>
</listitem>
</itemizedlist>
Prebuilt alist files are also distributed and installed with GNU Radio. They can be found in $prefix/share/gnuradio/fec/ldpc. The files generally represent the H matrix and are specified with the number of rows and columns (n and k) and gap of the matrix. The files named &quot;gen_matrix&quot; or similar are the generator, G, matrices.</para>
</sect2>
<sect2 id="page_fec_1fec_ldpc_decoder">
<title>LDPC Decoders</title><para>The simplest LDPC decoder is probably the <ref refid="classgr_1_1fec_1_1code_1_1ldpc__bit__flip__decoder" kindref="compound">gr::fec::code::ldpc_bit_flip_decoder</ref>, a hard decision decoding scheme. The decoder seeks to find the codeword that was most likely sent, which must satisfy Hx&apos;= 0. If the received codeword does not satisfy this parity check, then the decoder computes the parity checks on all of the bits. The bit(s) associated with the most failed parity checks are flipped. The process repeats until a valid codeword is found, or a maximum number of iterations is reached, whichever comes first.</para>
<para>The <ref refid="classgr_1_1fec_1_1ldpc__decoder" kindref="compound">gr::fec::ldpc_decoder</ref> is a soft-decision decoder that uses belief propagation (also known as message passing). Designed for a memoryless AWGN channel, it assumes a noise variance entered in as &apos;Sigma&apos; in the block. This is a suboptimal, yet efficient method of decoding LDPC codes.</para>
<para>In GRC, we have the following blocks for doing LDPC decoding:</para>
<para><itemizedlist>
<listitem><para>LDPC Decoder Definition: constructs a <ref refid="classgr_1_1fec_1_1ldpc__decoder" kindref="compound">gr::fec::ldpc_decoder</ref> variable given the alist file name of the H matrix. </para>
</listitem>
<listitem><para>LDPC Bit Flip Decoder Definition: constructs a <ref refid="classgr_1_1fec_1_1code_1_1ldpc__bit__flip__decoder" kindref="compound">gr::fec::code::ldpc_bit_flip_decoder</ref>. This does not take in an alist file name but instead a predefined matrix object. This decoder is useful in that it can take either an H or a G matrix constructed by either the &quot;LDPC Parity Check Matrix&quot; or &quot;LDPC Generator Matrix,&quot; respectively.</para>
</listitem>
</itemizedlist>
For uses of these codes, see the FEC examples:</para>
<para><itemizedlist>
<listitem><para>fecapi_ldpc_decoders.grc </para>
</listitem>
<listitem><para>fecapi_tagged_ldpc_decoders.grc </para>
</listitem>
<listitem><para>fecapi_async_ldpc_decoders.grc </para>
</listitem>
</itemizedlist>
</para>
</sect2>
</sect1>
    </detaileddescription>
    <location file="/pbulk/work/ham/gnuradio-doxygen/work/gnuradio-3.10.12.0/gr-fec/docs/fec.dox"/>
  </compounddef>
</doxygen>
