GNU Radio Manual and C++ API Reference  3.7.9.2
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cc_encoder.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2013-2014 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef INCLUDED_FEC_CC_ENCODER_H
24 #define INCLUDED_FEC_CC_ENCODER_H
25 
26 #include <gnuradio/fec/api.h>
27 #include <gnuradio/fec/encoder.h>
28 #include <gnuradio/fec/cc_common.h>
29 #include <map>
30 #include <string>
31 
32 namespace gr {
33  namespace fec {
34  namespace code {
35 
36  /*!
37  * \brief Convolutional Code Encoding class.
38  * \ingroup error_coding_blk
39  *
40  * \details
41  * This class performs convolutional encoding for unpacked bits
42  * for frames of a constant length. This class is general in its
43  * application of the convolutional encoding and allows us to
44  * specify the constraint length, the coding rate, and the
45  * polynomials used in the coding process.
46  *
47  * The parameter \p k sets the constraint length directly. We
48  * set the coding rate by setting \p rate to R given a desired
49  * rate of 1/R. That is, for a rate 1/2 coder, we would set \p
50  * rate to 2. And the polynomial is specified as a vector of
51  * integers, where each integer represents the coding polynomial
52  * for a different arm of the code. The number of polynomials
53  * given must be the same as the value \p rate.
54  *
55  * The encoding object holds a shift register that takes in each
56  * bit from the input stream and then ANDs the shift register
57  * with each polynomial, and places the parity of the result
58  * into the output stream. The output stream is therefore also
59  * unpacked bits.
60  *
61  * The encoder is set up with a number of bits per frame in the
62  * constructor. When not being used in a tagged stream mode,
63  * this encoder will only process frames of the length provided
64  * here. If used in a tagged stream block, this setting becomes
65  * the maximum allowable frame size that the block may process.
66  *
67  * The \p mode is a cc_mode_t that specifies how the convolutional
68  * encoder will behave and under what conditions.
69  *
70  * \li 'CC_STREAMING': mode expects an uninterrupted flow of
71  * samples into the encoder, and the output stream is
72  * continually encoded.
73  *
74  * \li 'CC_TERMINATED': is a mode designed for packet-based
75  * systems. This mode adds rate*(k-1) bits to the output as a
76  * way to help flush the decoder.
77  *
78  * \li 'CC_TAILBITING': is another packet-based method. Instead of
79  * adding bits onto the end of the packet, this mode will
80  * continue the code between the payloads of packets by
81  * pre-initializing the state of the new packet based on the
82  * state of the last packet for (k-1) bits.
83  *
84  * \li 'CC_TRUNCATED': a truncated code always resets the registers
85  * to the \p start_state between frames.
86  *
87  * A common convolutional encoder uses K=7, Rate=1/2,
88  * Polynomials=[109, 79]. This is the Voyager code from NASA:
89  * \li 109: b(1101101) --> 1 + x + x^3 + x^4 + x^6
90  * \li 79: b(1001111) --> 1 + x^3 + x^4 + x^5 + x^6
91  *
92  * Another encoder class is provided with gr-fec called the
93  * gr::fec::code::ccsds_encoder, which implements the above code
94  * that is more highly optimized for just those specific
95  * settings.
96  */
97  class FEC_API cc_encoder : virtual public generic_encoder
98  {
99  public:
100 
101  /*!
102  * Build a convolutional code encoding FEC API object.
103  *
104  * \param frame_size Number of bits per frame. If using in the
105  * tagged stream style, this is the maximum allowable
106  * number of bits per frame.
107  * \param k Constraint length (K) of the encoder.
108  * \param rate Inverse of the coder's rate
109  * (rate=2 means 2 output bits per 1 input).
110  * \param polys Vector of polynomials as integers.
111  * \param start_state Initialization state of the shift register.
112  * \param mode cc_mode_t mode of the encoding.
113  * \param padded true if the encoded frame should be padded
114  * to the nearest byte.
115  */
116  static generic_encoder::sptr make
117  (int frame_size, int k, int rate,
118  std::vector<int> polys, int start_state = 0,
119  cc_mode_t mode=CC_STREAMING, bool padded=false);
120 
121  /*!
122  * Sets the uncoded frame size to \p frame_size. If \p
123  * frame_size is greater than the value given to the
124  * constructor, the frame size will be capped by that initial
125  * value and this function will return false. Otherwise, it
126  * returns true.
127  */
128  virtual bool set_frame_size(unsigned int frame_size) = 0;
129 
130  /*!
131  * Returns the coding rate of this encoder.
132  */
133  virtual double rate() = 0;
134  };
135 
136  } /* namespace code */
137  } /* namespace fec */
138 } /* namespace gr */
139 
140 #endif /* INCLUDED_FEC_CC_ENCODER_H */
enum _cc_mode_t cc_mode_t
Include this header to use the message passing features.
Definition: logger.h:131
Definition: generic_encoder.h:34
boost::shared_ptr< generic_encoder > sptr
Definition: generic_encoder.h:49
#define FEC_API
Definition: gr-fec/include/gnuradio/fec/api.h:30
Definition: cc_common.h:27
Convolutional Code Encoding class.
Definition: cc_encoder.h:97