| 1 | /**************************************************************************** |
|---|
| 2 | |
|---|
| 3 | Copyright 2007 Virginia Polytechnic Institute and State University |
|---|
| 4 | |
|---|
| 5 | This file is part of the OSSIE FrameSynchronizer. |
|---|
| 6 | |
|---|
| 7 | OSSIE FrameSynchronizer 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 2 of the License, or |
|---|
| 10 | (at your option) any later version. |
|---|
| 11 | |
|---|
| 12 | OSSIE FrameSynchronizer 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 OSSIE FrameSynchronizer; if not, write to the Free Software |
|---|
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | |
|---|
| 21 | ****************************************************************************/ |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | #ifndef FRAMESYNCHRONIZERDSP_IMPL_H |
|---|
| 25 | #define FRAMESYNCHRONIZERDSP_IMPL_H |
|---|
| 26 | |
|---|
| 27 | #include <stdlib.h> |
|---|
| 28 | #include "MultirateSynchronizer.h" |
|---|
| 29 | #include "PNCodes.h" |
|---|
| 30 | |
|---|
| 31 | #define FRAME_SYNC_BUFFER_SIZE 255 ///< size of frame sync buffer |
|---|
| 32 | #define NUM_CONTROL_CODES 8 ///< number of control codes |
|---|
| 33 | |
|---|
| 34 | #define FRAME_SIZE_1 2048 ///< Frame size option 1 |
|---|
| 35 | #define FRAME_SIZE_2 4096 ///< Frame size option 2 |
|---|
| 36 | #define FRAME_SIZE_3 8192 ///< Frame size option 3 |
|---|
| 37 | #define FRAME_SIZE_4 16384 ///< Frame size option 4 |
|---|
| 38 | |
|---|
| 39 | #define FRAME_SYNCHRONIZER_DEFINE_API(X) \ |
|---|
| 40 | bool X( \ |
|---|
| 41 | short * I_in, \ |
|---|
| 42 | short * Q_in, \ |
|---|
| 43 | unsigned int input_length, \ |
|---|
| 44 | unsigned int &num_read, \ |
|---|
| 45 | short * I_out, \ |
|---|
| 46 | short * Q_out, \ |
|---|
| 47 | unsigned int output_length, \ |
|---|
| 48 | unsigned int &num_written); |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | #undef FS_LOGGING |
|---|
| 52 | |
|---|
| 53 | /** \brief Digital signal processing for the symbol synchronizer component |
|---|
| 54 | * implemented with the polyphase filter bank |
|---|
| 55 | * |
|---|
| 56 | * |
|---|
| 57 | */ |
|---|
| 58 | class FrameSynchronizerDSP : public MultirateSynchronizerDSP |
|---|
| 59 | { |
|---|
| 60 | public: |
|---|
| 61 | /// Initializing constructor |
|---|
| 62 | FrameSynchronizerDSP(); |
|---|
| 63 | |
|---|
| 64 | /// Destructor |
|---|
| 65 | ~FrameSynchronizerDSP(); |
|---|
| 66 | |
|---|
| 67 | // Finds the frame header P/N sync code |
|---|
| 68 | FRAME_SYNCHRONIZER_DEFINE_API(FindFrameHeader) |
|---|
| 69 | |
|---|
| 70 | /// \brief Extracts the frame header data |
|---|
| 71 | FRAME_SYNCHRONIZER_DEFINE_API(ExtractFrameHeader) |
|---|
| 72 | |
|---|
| 73 | /// \brief Decodes the frame header information |
|---|
| 74 | bool DecodeFrameHeader(); |
|---|
| 75 | |
|---|
| 76 | /// \brief Extracts the frame header data |
|---|
| 77 | FRAME_SYNCHRONIZER_DEFINE_API(ExtractFrameSymbols) |
|---|
| 78 | |
|---|
| 79 | FRAME_SYNCHRONIZER_DEFINE_API(ExtractFrameSymbolsFixedLength) |
|---|
| 80 | |
|---|
| 81 | /// \brief Main signal processing loop (overridden method) |
|---|
| 82 | /// |
|---|
| 83 | /// This method performs simultaneous synchronization and decimation. It |
|---|
| 84 | /// assumes that the calling platform takes care of memory management. |
|---|
| 85 | /// N_out initially stores the number of memory elements allocated to |
|---|
| 86 | /// I_out and Q_out, and assumes that this number is sufficiently large |
|---|
| 87 | /// to run the algorithm. The method returns N_out as the actual number |
|---|
| 88 | /// of elements stored in I_out and Q_out. This is approximately |
|---|
| 89 | /// \f$ N_{out} \approx N_{in}/k \f$ |
|---|
| 90 | /// |
|---|
| 91 | /// \param[in] I_in In-phase input signal |
|---|
| 92 | /// \param[in] Q_in Quadrature input signal |
|---|
| 93 | /// \param[in] N_in Number of input samples |
|---|
| 94 | /// \param[out] I_out In-phase output signal |
|---|
| 95 | /// \param[out] Q_out Quadrature output signal |
|---|
| 96 | /// \param[in,out] N_out Number of (maximum) output samples |
|---|
| 97 | void SynchronizeAndDecimate(short * I_in, |
|---|
| 98 | short * Q_in, |
|---|
| 99 | unsigned int N_in, |
|---|
| 100 | short * I_out, |
|---|
| 101 | short * Q_out, |
|---|
| 102 | unsigned int & N_out); |
|---|
| 103 | |
|---|
| 104 | protected: |
|---|
| 105 | /// Operational mode |
|---|
| 106 | enum { |
|---|
| 107 | EXTRACT_PN_FRAME_SYNC_CODE, |
|---|
| 108 | EXTRACT_CONTROL_CODES, |
|---|
| 109 | DECODE_FRAME_HEADER, |
|---|
| 110 | EXTRACT_FRAME, |
|---|
| 111 | EXTRACT_EOM_CODE |
|---|
| 112 | } operationalMode; |
|---|
| 113 | |
|---|
| 114 | /// |
|---|
| 115 | unsigned int DecodeControlSequence( unsigned int _i1, unsigned int _i2 ); |
|---|
| 116 | |
|---|
| 117 | /// |
|---|
| 118 | int * controlCode; |
|---|
| 119 | |
|---|
| 120 | /// Circular input buffer |
|---|
| 121 | SigProc::CircularBuffer <short> inputBuffer; |
|---|
| 122 | |
|---|
| 123 | /// Correlate input sequence with PN code |
|---|
| 124 | int CorrelateSequence( char * _pncode, unsigned int _N ); |
|---|
| 125 | |
|---|
| 126 | /// correlator output |
|---|
| 127 | int r; |
|---|
| 128 | |
|---|
| 129 | unsigned int numControlCodesReceived; |
|---|
| 130 | |
|---|
| 131 | unsigned int numFrameSymbolsReceived; |
|---|
| 132 | |
|---|
| 133 | unsigned int frameSize; |
|---|
| 134 | |
|---|
| 135 | unsigned int r_frame_sync; |
|---|
| 136 | |
|---|
| 137 | // Phase lock detect variables |
|---|
| 138 | float e_i; |
|---|
| 139 | float e_q; |
|---|
| 140 | float lock_zeta; |
|---|
| 141 | float lock_detect; |
|---|
| 142 | bool header_phase_locked; |
|---|
| 143 | unsigned int header_phase_lock_delay; |
|---|
| 144 | unsigned int header_phase_lock_delay_counter; |
|---|
| 145 | |
|---|
| 146 | private: |
|---|
| 147 | /// Disallow copy constructor |
|---|
| 148 | FrameSynchronizerDSP(FrameSynchronizerDSP&); |
|---|
| 149 | |
|---|
| 150 | #ifdef FS_LOGGING |
|---|
| 151 | std::ofstream input_log; |
|---|
| 152 | #endif |
|---|
| 153 | |
|---|
| 154 | }; |
|---|
| 155 | |
|---|
| 156 | #endif |
|---|
| 157 | |
|---|