GNU Radio Manual and C++ API Reference
3.8.1.0
The Free & Open Software Radio Ecosystem
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/cc_common.h
>
28
#include <
gnuradio/fec/encoder.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 systems. This mode
75
* flushes the encoder with K-1 bits which adds rate*(K-1) bits to the output.
76
* This improves the protection of the last bits of a block and helps the
77
* decoder.
78
*
79
* \li 'CC_TAILBITING': is another packet-based method. Instead of adding bits
80
* onto the end of a packet (as with 'CC_TERMINATED'), this mode will
81
* pre-initialize the state of the encoder with a packet’s last (k-1) bits.
82
*
83
* \li 'CC_TRUNCATED': a truncated code always resets the registers
84
* to the \p start_state between frames.
85
*
86
* A common convolutional encoder uses K=7, Rate=1/2, and the polynomials
87
* \li 1 + x^2 + x^3 + x^5 + x^6
88
* \li 1 + x + x^2 + x^3 + x^6
89
* This is the Voyager code from NASA.
90
*
91
* Another encoder class is provided with gr-fec called the
92
* gr::fec::code::ccsds_encoder, which implements the above code
93
* that is more highly optimized for just those specific
94
* settings.
95
*/
96
class
FEC_API
cc_encoder
:
virtual
public
generic_encoder
97
{
98
public
:
99
/*!
100
* Build a convolutional code encoding FEC API object.
101
*
102
* \param frame_size Number of bits per frame; must be > 1. If using in the
103
* tagged stream style, this is the maximum allowable number of bits
104
* per frame.
105
* \param k Constraint length (K) of the encoder; must be in the range [2, 31].
106
* K = 1 implies a code without memory which does not make sense;
107
* upper limit is due the way the polynomials of the code are passed
108
* in \p polys.
109
* \param rate Inverse of the coder's rate; must be > 1.
110
* (rate=2 means 2 output bits per 1 input).
111
* \param polys Vector of polynomials as integers. The least significant bit
112
* (LSB) denotes the coefficient of exponent zero of the coding
113
* polynomial. The position of the most significant set bit
114
* (zero based counting) is \p K-1. Note: this representation
115
* is reversed compared to the common representation as found
116
* in most books and references. The common representation puts
117
* the coefficient of the highest exponent into the LSB and the
118
* coefficient of exponent zero is the highest set bit.
119
* Example: The common binary representation of the Voyager
120
* code polynomials (see above) is 1011011 and 1111001; the
121
* octal representation is 133 and 171. For this block, the
122
* binary representation must be reversed: 1101101 and 1001111;
123
* octal this is 155 and 117; decimal this is 109 and 79. Some
124
* standards (e.g. CCSDS 131.0-B-3) require the inversion of
125
* some outputs. This is supported by providing the negative
126
* value of the polynomial, e.g. -109.
127
* \param start_state Initialization state of the shift register; must be in
128
* range [0, 2^(K-1)-1] where K is the constraint length.
129
* The bits in \p start_state are also used to flush the
130
* encoder in mode 'CC_TERMINATED'.
131
* Note: Most books and references use a shift register
132
* shifting from left to right. This implementation,
133
* however, shifts from right to left. This means that
134
* the start state must be reversed. (The different shift
135
* direction is also the reason why the polynomials must
136
* be reversed as described above.)
137
* \param mode cc_mode_t mode of the encoding.
138
* \param padded true if the encoded frame should be padded
139
* to the nearest byte.
140
*/
141
static
generic_encoder::sptr
make(
int
frame_size,
142
int
k,
143
int
rate,
144
std::vector<int> polys,
145
int
start_state = 0,
146
cc_mode_t
mode =
CC_STREAMING
,
147
bool
padded =
false
);
148
149
/*!
150
* Sets the uncoded frame size to \p frame_size. If \p
151
* frame_size is greater than the value given to the
152
* constructor, the frame size will be capped by that initial
153
* value and this function will return false. Otherwise, it
154
* returns true.
155
*/
156
virtual
bool
set_frame_size(
unsigned
int
frame_size) = 0;
157
158
/*!
159
* Returns the coding rate of this encoder.
160
*/
161
virtual
double
rate() = 0;
162
};
163
164
}
/* namespace code */
165
}
/* namespace fec */
166
}
/* namespace gr */
167
168
#endif
/* INCLUDED_FEC_CC_ENCODER_H */
api.h
CC_STREAMING
Definition:
cc_common.h:27
cc_mode_t
enum _cc_mode_t cc_mode_t
gr::fec::code::cc_encoder
Convolutional Code Encoding class.
Definition:
cc_encoder.h:96
cc_common.h
FEC_API
#define FEC_API
Definition:
gr-fec/include/gnuradio/fec/api.h:30
gr::fec::generic_encoder::sptr
boost::shared_ptr< generic_encoder > sptr
Definition:
generic_encoder.h:49
gr
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition:
basic_block.h:43
encoder.h
gr::fec::generic_encoder
Definition:
generic_encoder.h:34
gr-fec
include
gnuradio
fec
cc_encoder.h
Generated by
1.8.16