root/experimental/components/SymbolSyncPoly/branches/SymbolSyncPoly-metadata/src/FrameSynchronizerDSP.h @ 5472

Revision 5472, 6.2 KB (checked in by jgaeddert, 6 years ago)

splitting functionality of frame synchronization into separate methods

  • Property svn:eol-style set to native
Line 
1/****************************************************************************
2
3Copyright 2007 Virginia Polytechnic Institute and State University
4
5This file is part of the OSSIE FrameSynchronizer.
6
7OSSIE FrameSynchronizer is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12OSSIE FrameSynchronizer is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OSSIE FrameSynchronizer; if not, write to the Free Software
19Foundation, 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)    \
40bool 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 */
58class FrameSynchronizerDSP : public MultirateSynchronizerDSP
59{
60  public:
61    /// Initializing constructor
62    FrameSynchronizerDSP();
63
64    /// Destructor
65    ~FrameSynchronizerDSP();
66
67    /// \brief Uses a CostasLoop to lock to the carrier, correlates with P/N sequence
68    FRAME_SYNCHRONIZER_DEFINE_API(FindFrameHeaderCostasLoop)
69
70    // Finds the frame header P/N sync code
71    FRAME_SYNCHRONIZER_DEFINE_API(FindFrameHeader)
72
73    /// \brief Extracts the frame header data
74    FRAME_SYNCHRONIZER_DEFINE_API(ExtractFrameHeader)
75
76    /// \brief Decodes the frame header information
77    bool DecodeFrameHeader();
78
79    /// \brief Extracts the frame header data
80    FRAME_SYNCHRONIZER_DEFINE_API(ExtractFrameSymbols)
81
82    FRAME_SYNCHRONIZER_DEFINE_API(ExtractFrameSymbolsFixedLength)
83
84    /// \brief Main signal processing loop (overridden method)
85    ///
86    /// This method performs simultaneous synchronization and decimation.  It
87    /// assumes that the calling platform takes care of memory management.
88    /// N_out initially stores the number of memory elements allocated to
89    /// I_out and Q_out, and assumes that this number is sufficiently large
90    /// to run the algorithm.  The method returns N_out as the actual number
91    /// of elements stored in I_out and Q_out.  This is approximately
92    /// \f$ N_{out} \approx N_{in}/k \f$
93    ///
94    /// \param[in]      I_in  In-phase input signal
95    /// \param[in]      Q_in  Quadrature input signal
96    /// \param[in]      N_in  Number of input samples
97    /// \param[out]     I_out In-phase output signal
98    /// \param[out]     Q_out Quadrature output signal
99    /// \param[in,out]  N_out Number of (maximum) output samples
100    void SynchronizeAndDecimate(short * I_in,
101            short * Q_in,
102            unsigned int N_in,
103            short * I_out,
104            short * Q_out,
105            unsigned int & N_out);
106
107  protected:
108    /// Operational mode
109    enum {
110        EXTRACT_PN_FRAME_SYNC_CODE,
111        EXTRACT_CONTROL_CODES,
112        DECODE_FRAME_HEADER,
113        EXTRACT_FRAME,
114        EXTRACT_EOM_CODE
115    } operationalMode;
116
117    ///
118    unsigned int DecodeControlSequence( unsigned int _i1, unsigned int _i2 );
119
120    ///
121    int * controlCode;
122
123    /// Circular input buffer
124    SigProc::CircularBuffer <short> inputBuffer;
125
126    /// Correlate input sequence with PN code
127    int CorrelateSequence( char * _pncode, unsigned int _N );
128
129    /// correlator output
130    int r;
131
132    unsigned int numControlCodesReceived;
133
134    unsigned int numFrameSymbolsReceived;
135
136    unsigned int frameSize;
137
138    unsigned int r_frame_sync;
139
140    // Phase lock detect variables
141    float e_i;
142    float e_q;
143    float lock_zeta;
144    float lock_detect;
145    bool header_phase_locked;
146    unsigned int header_phase_lock_delay;
147    unsigned int header_phase_lock_delay_counter;
148
149    // Costas loop methods
150
151    void UpdateCostasLoopFilterCoefficients(float _BT_cl) {
152        BT_cl = _BT_cl;
153        float k1(1.0f);
154        float XI(0.707106781186547f);
155
156        beta_cl = 2*BT_cl/(XI+1/(4*XI))/k1;
157        alpha_cl = 2*XI*beta_cl;
158
159        printf("\n\nbeta_cl = %f\n\n\n", beta_cl);
160        printf("\n\nalpha_cl = %f\n\n\n", alpha_cl);
161
162        ///\todo this is necessary because of the delay introduced by the filter
163        //beta_cl /= 30.0f;
164    };
165
166    float GenerateCostasLoopPhaseError(short I, short Q) {
167        return ( I > 0 ) ? (float) Q : (float) -Q;
168    }
169
170    void AdvanceCostasLoopFilter() {
171        q_prime_cl = pd2_cl*beta_cl + tmp2_cl;
172        q_hat_cl = alpha_cl*pd2_cl + q_prime_cl;
173        tmp2_cl = q_prime_cl;
174       
175        // store filtered error signal in external variable
176        q_hat_c = q_hat_cl;
177    }
178   
179    // Costas loop variables
180    float BT_cl;        ///< Bandwidth-time product of Costas loop filter
181    float alpha_cl;     ///< Costas loop filter feedback coefficient
182    float beta_cl;      ///< Costas loop filter feedforward coefficient
183
184    float pd2_cl;       ///<
185    float tmp2_cl;      ///<
186    float q_hat_cl;     ///<
187    float q_prime_cl;   ///<
188
189  private:
190    /// Disallow copy constructor
191    FrameSynchronizerDSP(FrameSynchronizerDSP&);
192
193#ifdef FS_LOGGING
194    std::ofstream input_log;
195#endif
196
197};
198
199#endif
200
Note: See TracBrowser for help on using the browser.