GNU Radio Manual and C++ API Reference  3.9.0.0
The Free & Open Software Radio Ecosystem
fsm.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2002,2011-2012 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * SPDX-License-Identifier: GPL-3.0-or-later
8  *
9  */
10 
11 #ifndef INCLUDED_TRELLIS_FSM_H
12 #define INCLUDED_TRELLIS_FSM_H
13 
14 #include <gnuradio/trellis/api.h>
15 #include <iosfwd>
16 #include <vector>
17 
18 namespace gr {
19 namespace trellis {
20 
21 /*!
22  * \brief Finite State Machine Specification class.
23  * \ingroup trellis_coding_blk
24  *
25  * \details
26  * An instance of this class represents a finite state machine
27  * specification (FSMS) rather than the FSM itself. It particular
28  * the state of the FSM is not stored within an instance of this
29  * class.
30  */
32 {
33 private:
34  // Input alphabet cardinality.
35  int d_I;
36 
37  // Number of states.
38  int d_S;
39 
40  // Output alphabet cardinality.
41  int d_O;
42 
43  // NS means Next State.
44  // next_state = d_NS[current_state * d_I + input_symbol]
45  std::vector<int> d_NS;
46 
47  // OS means Output Symbol.
48  // output_symbol = d_OS[current_state * d_I + input_symbol]
49  std::vector<int> d_OS;
50 
51  // PS means Previous State.
52  std::vector<std::vector<int>> d_PS;
53 
54  // PI means Previous Input Symbol.
55  // d_PS[current_state][k] and d_PI[current_state][k], is a pair of the form
56  // (previous_state, previous_input_symbol) that could have produced the
57  // current state.
58  std::vector<std::vector<int>> d_PI;
59 
60  // TM means Termination matrix.
61  // d_TMl[s*d_S+es] is the shortest number of steps to get from state s to
62  // state es.
63  std::vector<int> d_TMl;
64 
65  // d_TMi[s*d_S+es] is the input symbol required to set off on the shortest
66  // path from state s to es.
67  std::vector<int> d_TMi;
68  void generate_PS_PI();
69  void generate_TM();
70  bool find_es(int es);
71 
72 public:
73  /*!
74  * \brief Constructor to create an uninitialized FSMS.
75  */
76  fsm();
77 
78  /*!
79  * \brief Constructor to copy an FSMS.
80  */
81  fsm(const fsm& FSM);
82 
83  /*!
84  * \brief Constructor to to create an FSMS.
85  *
86  * \param I The number of possible input symbols.
87  * \param S The number of possible FSM states.
88  * \param O The number of possible output symbols.
89  * \param NS A mapping from (current state, input symbol) to next state.
90  * next_state = NS[current_state * I + input_symbol]
91  * \param OS A mapping from (current state, input symbol) to output symbol.
92  * output_symbol = OS[current_state * I + input_symbol]
93  *
94  */
95  fsm(int I, int S, int O, const std::vector<int>& NS, const std::vector<int>& OS);
96 
97  /*!
98  * \brief Constructor to create an FSMS from file contents.
99  *
100  * \param name filename
101  *
102  */
103  fsm(const char* name);
104 
105  /*!
106  * \brief Creates an FSMS from the generator matrix of a (n, k) binary convolutional
107  * code.
108  *
109  * \param k ???
110  * \param n ???
111  * \param G ???
112  *
113  */
114  fsm(int k, int n, const std::vector<int>& G);
115 
116  /*!
117  * \brief Creates an FSMS describing ISI.
118  *
119  * \param mod_size modulation size
120  * \param ch_length channel length
121  *
122  */
123  fsm(int mod_size, int ch_length);
124 
125  /*!
126  * \brief Creates an FSMS describing the trellis for a CPM.
127  *
128  * \param P ???? h=K/P (relatively prime)
129  * \param M alphabet size
130  * \param L pulse duration
131  *
132  * This FSM is based on the paper by B. Rimoldi
133  * "A decomposition approach to CPM", IEEE Trans. Info Theory, March 1988
134  * See also my own notes at http://www.eecs.umich.edu/~anastas/docs/cpm.pdf
135  */
136  fsm(int P, int M, int L);
137 
138  /*!
139  * \brief Creates an FSMS describing the joint trellis of two FSMs.
140  *
141  * \param FSM1 first FSMS
142  * \param FSM2 second FSMS
143  */
144  fsm(const fsm& FSM1, const fsm& FSM2);
145 
146 
147  /*!
148  * \brief Creates an FSMS describing the trellis of two serially concatenated FSMs.
149  *
150  * \param FSMo outer FSMS
151  * \param FSMi inner FSMS
152  * \param serial set it to true to distinguish from the previous constructor
153  */
154  fsm(const fsm& FSMo, const fsm& FSMi, bool serial);
155 
156  /*!
157  * \brief Creates an FSMS representing n stages through the original FSM (AKA radix-n
158  * FSM).
159  *
160  * \param FSM Original FSMs
161  * \param n Number of stages.
162  */
163  fsm(const fsm& FSM, int n);
164  int I() const { return d_I; }
165  int S() const { return d_S; }
166  int O() const { return d_O; }
167  const std::vector<int>& NS() const { return d_NS; }
168  const std::vector<int>& OS() const { return d_OS; }
169  const std::vector<std::vector<int>>& PS() const { return d_PS; }
170  const std::vector<std::vector<int>>& PI() const { return d_PI; }
171  const std::vector<int>& TMi() const { return d_TMi; }
172  const std::vector<int>& TMl() const { return d_TMl; }
173 
174  /*!
175  * \brief Creates an svg image of the trellis representation.
176  *
177  * \param filename filename
178  * \param number_stages ????
179  */
180  void write_trellis_svg(std::string filename, int number_stages);
181 
182  /*!
183  * \brief Write the FSMS to a file.
184  *
185  * \param filename filename
186  */
187  void write_fsm_txt(std::string filename);
188 };
189 
190 } /* namespace trellis */
191 } /* namespace gr */
192 
193 #endif /* INCLUDED_TRELLIS_FSM_H */
Finite State Machine Specification class.
Definition: fsm.h:32
const std::vector< std::vector< int > > & PS() const
Definition: fsm.h:169
void write_fsm_txt(std::string filename)
Write the FSMS to a file.
void write_trellis_svg(std::string filename, int number_stages)
Creates an svg image of the trellis representation.
fsm(const fsm &FSM, int n)
Creates an FSMS representing n stages through the original FSM (AKA radix-n FSM).
const std::vector< int > & TMl() const
Definition: fsm.h:172
fsm(const fsm &FSMo, const fsm &FSMi, bool serial)
Creates an FSMS describing the trellis of two serially concatenated FSMs.
const std::vector< int > & NS() const
Definition: fsm.h:167
fsm(int P, int M, int L)
Creates an FSMS describing the trellis for a CPM.
fsm()
Constructor to create an uninitialized FSMS.
const std::vector< int > & OS() const
Definition: fsm.h:168
fsm(const fsm &FSM1, const fsm &FSM2)
Creates an FSMS describing the joint trellis of two FSMs.
int I() const
Definition: fsm.h:164
int O() const
Definition: fsm.h:166
int S() const
Definition: fsm.h:165
fsm(int k, int n, const std::vector< int > &G)
Creates an FSMS from the generator matrix of a (n, k) binary convolutional code.
fsm(const fsm &FSM)
Constructor to copy an FSMS.
fsm(int mod_size, int ch_length)
Creates an FSMS describing ISI.
fsm(const char *name)
Constructor to create an FSMS from file contents.
fsm(int I, int S, int O, const std::vector< int > &NS, const std::vector< int > &OS)
Constructor to to create an FSMS.
const std::vector< std::vector< int > > & PI() const
Definition: fsm.h:170
const std::vector< int > & TMi() const
Definition: fsm.h:171
#define TRELLIS_API
Definition: gr-trellis/include/gnuradio/trellis/api.h:18
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:29
#define S(x)
Definition: rpcserver_thrift.h:26