GNU Radio 3.6.5 C++ API

fsm.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2002,2011 Free Software Foundation, Inc.
00004  *
00005  * This file is part of GNU Radio
00006  *
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  *
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 
00023 #ifndef INCLUDED_TRELLIS_FSM_H
00024 #define INCLUDED_TRELLIS_FSM_H
00025 
00026 #include <trellis_api.h>
00027 #include <vector>
00028 #include <iosfwd>
00029 
00030 /*!
00031  * \brief  Finite State Machine Specification class.
00032  * \ingroup trellis_coding_blk
00033  *
00034  * An instance of this class represents a finite state machine specification (FSMS)
00035  * rather than the FSM itself.  It particular the state of the FSM
00036  * is not stored within an instance of this class.
00037  */
00038 class TRELLIS_API fsm {
00039 private:
00040   // Input alphabet cardinality.
00041   int d_I;
00042   // Number of states.
00043   int d_S;
00044   // Output alphabet cardinality.
00045   int d_O;
00046   // NS means Next State.
00047   // next_state = d_NS[current_state * d_I + input_symbol]
00048   std::vector<int> d_NS;
00049   // OS means Output Symbol.
00050   // output_symbol = d_OS[current_state * d_I + input_symbol]
00051   std::vector<int> d_OS;
00052   // PS means Previous State.
00053   std::vector< std::vector<int> > d_PS;
00054   // PI means Previous Input Symbol.
00055   // d_PS[current_state][k] and d_PI[current_state][k], is a pair of the form
00056   // (previous_state, previous_input_symbol) that could have produced the
00057   // current state.
00058   std::vector< std::vector<int> > d_PI;
00059   // TM means Termination matrix.
00060   // d_TMl[s*d_S+es] is the shortest number of steps to get from state s to
00061   // state es.
00062   std::vector<int> d_TMl;
00063   // d_TMi[s*d_S+es] is the input symbol required to set off on the shortest
00064   // path from state s to es.
00065   std::vector<int> d_TMi;
00066   void generate_PS_PI ();
00067   void generate_TM ();
00068   bool find_es(int es);
00069 public:
00070  /*!
00071    * \brief Constructor to create an uninitialized FSMS.
00072    */
00073   fsm();
00074  /*!
00075    * \brief Constructor to copy an FSMS.
00076    */
00077   fsm(const fsm &FSM);
00078  /*!
00079    * \brief Constructor to to create an FSMS.
00080    *
00081    * \param I           The number of possible input symbols.
00082    * \param S           The number of possible FSM states.
00083    * \param O           The number of possible output symbols.
00084    * \param NS          A mapping from (current state, input symbol) to next state.
00085    *                    next_state = NS[current_state * I + input_symbol]
00086    * \param OS          A mapping from (current state, input symbol) to output symbol.
00087    *                    output_symbol = OS[current_state * I + input_symbol]
00088    *
00089    */
00090   fsm(int I, int S, int O, const std::vector<int> &NS, const std::vector<int> &OS);
00091  /*!
00092    * \brief Constructor to create an FSMS from file contents.
00093    *
00094    * \param name        filename
00095    *
00096    */
00097   fsm(const char *name);
00098  /*!
00099    * \brief Creates an FSMS from the generator matrix of a (n, k) binary convolutional code.
00100    *
00101    * \param k      ???
00102    * \param n      ???
00103    * \param G      ???
00104    *
00105    */
00106   fsm(int k, int n, const std::vector<int> &G);
00107   /*!
00108    * \brief Creates an FSMS describing ISI.
00109    *
00110    * \param mod_size    modulation size
00111    * \param ch_length   channel length
00112    *
00113    */
00114   fsm(int mod_size, int ch_length);
00115   /*!
00116    * \brief Creates an FSMS describing the trellis for a CPM.
00117    *
00118    * \param P    ???? h=K/P (relatively prime)
00119    * \param M    alphabet size
00120    * \param L    pulse duration
00121    *
00122    * This FSM is based on the paper by B. Rimoldi
00123    * "A decomposition approach to CPM", IEEE Trans. Info Theory, March 1988
00124    * See also my own notes at http://www.eecs.umich.edu/~anastas/docs/cpm.pdf
00125    */
00126   fsm(int P, int M, int L);
00127   /*!
00128    * \brief Creates an FSMS describing the joint trellis of two FSMs.
00129    *
00130    * \param FSM1  first FSMS
00131    * \param FSM2  second FSMS
00132    */
00133   fsm(const fsm &FSM1, const fsm &FSM2);
00134   /*!
00135    * \brief Creates an FSMS representing n stages through the originial FSM (AKA radix-n FSM).
00136    *
00137    * \param FSM      Original FSMs
00138    * \param n        Number of stages.
00139    */
00140   fsm(const fsm &FSM, int n);
00141   int I () const { return d_I; }
00142   int S () const { return d_S; }
00143   int O () const { return d_O; }
00144   const std::vector<int> & NS () const { return d_NS; }
00145   const std::vector<int> & OS () const { return d_OS; }
00146   const std::vector< std::vector<int> > & PS () const { return d_PS; }
00147   const std::vector< std::vector<int> > & PI () const { return d_PI; }
00148   const std::vector<int> & TMi () const { return d_TMi; }
00149   const std::vector<int> & TMl () const { return d_TMl; }
00150   /*!
00151    * \brief Creates an svg image of the trellis representation.
00152    *
00153    * \param filename         filename
00154    * \param number_stages    ????
00155    *
00156    */
00157   void write_trellis_svg(std::string filename ,int number_stages);
00158   /*!
00159    * \brief Write the FSMS to a file.
00160    *
00161    * \param filename   filename
00162    *
00163    */
00164   void write_fsm_txt(std::string filename);
00165 };
00166 
00167 #endif