GNU Radio 3.5.3.2 C++ API
fsm.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2002,2011 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_TRELLIS_FSM_H
24 #define INCLUDED_TRELLIS_FSM_H
25 
26 #include <trellis_api.h>
27 #include <vector>
28 #include <iosfwd>
29 
30 /*!
31  * \brief Finite State Machine Specification class.
32  *
33  * An instance of this class represents a finite state machine specification (FSMS)
34  * rather than the FSM itself. It particular the state of the FSM
35  * is not stored within an instance of this class.
36  */
38 private:
39  // Input alphabet cardinality.
40  int d_I;
41  // Number of states.
42  int d_S;
43  // Output alphabet cardinality.
44  int d_O;
45  // NS means Next State.
46  // next_state = d_NS[current_state * d_I + input_symbol]
47  std::vector<int> d_NS;
48  // OS means Output Symbol.
49  // output_symbol = d_OS[current_state * d_I + input_symbol]
50  std::vector<int> d_OS;
51  // PS means Previous State.
52  std::vector< std::vector<int> > d_PS;
53  // PI means Previous Input Symbol.
54  // d_PS[current_state][k] and d_PI[current_state][k], is a pair of the form
55  // (previous_state, previous_input_symbol) that could have produced the
56  // current state.
57  std::vector< std::vector<int> > d_PI;
58  // TM means Termination matrix.
59  // d_TMl[s*d_S+es] is the shortest number of steps to get from state s to
60  // state es.
61  std::vector<int> d_TMl;
62  // d_TMi[s*d_S+es] is the input symbol required to set off on the shortest
63  // path from state s to es.
64  std::vector<int> d_TMi;
65  void generate_PS_PI ();
66  void generate_TM ();
67  bool find_es(int es);
68 public:
69  /*!
70  * \brief Constructor to create an uninitialized FSMS.
71  */
72  fsm();
73  /*!
74  * \brief Constructor to copy an FSMS.
75  */
76  fsm(const fsm &FSM);
77  /*!
78  * \brief Constructor to to create an FSMS.
79  *
80  * \param I The number of possible input symbols.
81  * \param S The number of possible FSM states.
82  * \param O The number of possible output symbols.
83  * \param NS A mapping from (current state, input symbol) to next state.
84  * next_state = NS[current_state * I + input_symbol]
85  * \param OS A mapping from (current state, input symbol) to output symbol.
86  * output_symbol = OS[current_state * I + input_symbol]
87  *
88  */
89  fsm(int I, int S, int O, const std::vector<int> &NS, const std::vector<int> &OS);
90  /*!
91  * \brief Constructor to create an FSMS from file contents.
92  *
93  * \param name filename
94  *
95  */
96  fsm(const char *name);
97  /*!
98  * \brief Creates an FSMS from the generator matrix of a (n, k) binary convolutional code.
99  *
100  * \param k ???
101  * \param n ???
102  * \param G ???
103  *
104  */
105  fsm(int k, int n, const std::vector<int> &G);
106  /*!
107  * \brief Creates an FSMS describing ISI.
108  *
109  * \param mod_size modulation size
110  * \param ch_length channel length
111  *
112  */
113  fsm(int mod_size, int ch_length);
114  /*!
115  * \brief Creates an FSMS describing the trellis for a CPM.
116  *
117  * \param P ???? h=K/P (relatively prime)
118  * \param M alphabet size
119  * \param L pulse duration
120  *
121  * This FSM is based on the paper by B. Rimoldi
122  * "A decomposition approach to CPM", IEEE Trans. Info Theory, March 1988
123  * See also my own notes at http://www.eecs.umich.edu/~anastas/docs/cpm.pdf
124  */
125  fsm(int P, int M, int L);
126  /*!
127  * \brief Creates an FSMS describing the joint trellis of two FSMs.
128  *
129  * \param FSM1 first FSMS
130  * \param FSM2 second FSMS
131  */
132  fsm(const fsm &FSM1, const fsm &FSM2);
133  /*!
134  * \brief Creates an FSMS representing n stages through the originial FSM (AKA radix-n FSM).
135  *
136  * \param FSM Original FSMs
137  * \param n Number of stages.
138  */
139  fsm(const fsm &FSM, int n);
140  int I () const { return d_I; }
141  int S () const { return d_S; }
142  int O () const { return d_O; }
143  const std::vector<int> & NS () const { return d_NS; }
144  const std::vector<int> & OS () const { return d_OS; }
145  const std::vector< std::vector<int> > & PS () const { return d_PS; }
146  const std::vector< std::vector<int> > & PI () const { return d_PI; }
147  const std::vector<int> & TMi () const { return d_TMi; }
148  const std::vector<int> & TMl () const { return d_TMl; }
149  /*!
150  * \brief Creates an svg image of the trellis representation.
151  *
152  * \param filename filename
153  * \param number_stages ????
154  *
155  */
156  void write_trellis_svg(std::string filename ,int number_stages);
157  /*!
158  * \brief Write the FSMS to a file.
159  *
160  * \param filename filename
161  *
162  */
163  void write_fsm_txt(std::string filename);
164 };
165 
166 #endif