GNU Radio 3.5.3.2 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  *
00033  * An instance of this class represents a finite state machine specification (FSMS)
00034  * rather than the FSM itself.  It particular the state of the FSM
00035  * is not stored within an instance of this class.
00036  */
00037 class TRELLIS_API fsm {
00038 private:
00039   // Input alphabet cardinality.
00040   int d_I;
00041   // Number of states.
00042   int d_S;
00043   // Output alphabet cardinality.
00044   int d_O;
00045   // NS means Next State.
00046   // next_state = d_NS[current_state * d_I + input_symbol]
00047   std::vector<int> d_NS;
00048   // OS means Output Symbol.
00049   // output_symbol = d_OS[current_state * d_I + input_symbol]          
00050   std::vector<int> d_OS;
00051   // PS means Previous State.
00052   std::vector< std::vector<int> > d_PS;
00053   // PI means Previous Input Symbol.
00054   // d_PS[current_state][k] and d_PI[current_state][k], is a pair of the form
00055   // (previous_state, previous_input_symbol) that could have produced the
00056   // current state.
00057   std::vector< std::vector<int> > d_PI;
00058   // TM means Termination matrix.
00059   // d_TMl[s*d_S+es] is the shortest number of steps to get from state s to
00060   // state es.
00061   std::vector<int> d_TMl;
00062   // d_TMi[s*d_S+es] is the input symbol required to set off on the shortest
00063   // path from state s to es.
00064   std::vector<int> d_TMi;
00065   void generate_PS_PI ();
00066   void generate_TM ();
00067   bool find_es(int es);
00068 public:
00069  /*!
00070    * \brief Constructor to create an uninitialized FSMS.
00071    */
00072   fsm();
00073  /*!
00074    * \brief Constructor to copy an FSMS.
00075    */
00076   fsm(const fsm &FSM);
00077  /*!
00078    * \brief Constructor to to create an FSMS.
00079    *
00080    * \param I           The number of possible input symbols.
00081    * \param S           The number of possible FSM states.
00082    * \param O           The number of possible output symbols.
00083    * \param NS          A mapping from (current state, input symbol) to next state.
00084    *                    next_state = NS[current_state * I + input_symbol]
00085    * \param OS          A mapping from (current state, input symbol) to output symbol.
00086    *                    output_symbol = OS[current_state * I + input_symbol]          
00087    *
00088    */
00089   fsm(int I, int S, int O, const std::vector<int> &NS, const std::vector<int> &OS);
00090  /*!
00091    * \brief Constructor to create an FSMS from file contents.
00092    *
00093    * \param name        filename
00094    *
00095    */
00096   fsm(const char *name);
00097  /*!
00098    * \brief Creates an FSMS from the generator matrix of a (n, k) binary convolutional code.
00099    *
00100    * \param k      ???
00101    * \param n      ???
00102    * \param G      ???
00103    *
00104    */
00105   fsm(int k, int n, const std::vector<int> &G);
00106   /*!
00107    * \brief Creates an FSMS describing ISI.
00108    *
00109    * \param mod_size    modulation size
00110    * \param ch_length   channel length
00111    *
00112    */
00113   fsm(int mod_size, int ch_length);
00114   /*!
00115    * \brief Creates an FSMS describing the trellis for a CPM.
00116    *
00117    * \param P    ???? h=K/P (relatively prime)
00118    * \param M    alphabet size
00119    * \param L    pulse duration
00120    *
00121    * This FSM is based on the paper by B. Rimoldi
00122    * "A decomposition approach to CPM", IEEE Trans. Info Theory, March 1988
00123    * See also my own notes at http://www.eecs.umich.edu/~anastas/docs/cpm.pdf
00124    */
00125   fsm(int P, int M, int L);
00126   /*!
00127    * \brief Creates an FSMS describing the joint trellis of two FSMs.
00128    *
00129    * \param FSM1  first FSMS
00130    * \param FSM2  second FSMS
00131    */
00132   fsm(const fsm &FSM1, const fsm &FSM2);
00133   /*!
00134    * \brief Creates an FSMS representing n stages through the originial FSM (AKA radix-n FSM).
00135    *
00136    * \param FSM      Original FSMs
00137    * \param n        Number of stages.
00138    */
00139   fsm(const fsm &FSM, int n);
00140   int I () const { return d_I; }
00141   int S () const { return d_S; }
00142   int O () const { return d_O; }
00143   const std::vector<int> & NS () const { return d_NS; }
00144   const std::vector<int> & OS () const { return d_OS; }
00145   const std::vector< std::vector<int> > & PS () const { return d_PS; }
00146   const std::vector< std::vector<int> > & PI () const { return d_PI; }
00147   const std::vector<int> & TMi () const { return d_TMi; }
00148   const std::vector<int> & TMl () const { return d_TMl; }
00149   /*!
00150    * \brief Creates an svg image of the trellis representation.
00151    *
00152    * \param filename         filename
00153    * \param number_stages    ????
00154    *
00155    */  
00156   void write_trellis_svg(std::string filename ,int number_stages);
00157   /*!
00158    * \brief Write the FSMS to a file.
00159    *
00160    * \param filename   filename
00161    *
00162    */
00163   void write_fsm_txt(std::string filename);
00164 };
00165 
00166 #endif