root/SigProc/trunk/SigProc/SigProc.h @ 3087

Revision 3087, 8.4 KB (checked in by jgaeddert, 6 years ago)

implementing PushInput?(), ComputeOutput?() methods for PPFB; needs testing

  • Property svn:eol-style set to native
Line 
1/****************************************************************************
2
3Copyright 2005,2006 Virginia Polytechnic Institute and State University
4
5This file is part of the OSSIE Decimator.
6
7OSSIE Decimator 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 Decimator 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 Decimator; 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 SIG_PROC_H
25#define SIG_PROC_H
26
27#include <iostream>
28#include <fstream>
29#include <string>
30
31#ifdef FPM
32#include "fixed.h"
33#endif
34
35namespace SigProc {
36
37//-----------------------------------------------------------------------------
38//
39// Design root raised-cosine filter
40//
41//-----------------------------------------------------------------------------
42void DesignRRCFilter(
43  unsigned int k,      // samples per symbol
44  unsigned int m,      // delay
45  float beta,          // rolloff factor ( 0 < beta <= 1 )
46  float *& h,          // pointer to filter coefficients
47  unsigned int & h_len // length of filter (len = 2*m*k+1)
48);
49
50//-----------------------------------------------------------------------------
51//
52// P/N Sequence
53//
54//-----------------------------------------------------------------------------
55
56/// P/N Sequence
57class PNSequence
58{
59  public:
60    /// default constructor
61    PNSequence();
62
63    /// destructor
64    ~PNSequence();
65
66  private:
67    // g: generator polynomial
68    // a: initial polynomial state
69};
70
71//-----------------------------------------------------------------------------
72//
73// Automatic Gain Control class
74//
75//-----------------------------------------------------------------------------
76/** \brief Automatic gain control signal processor
77 *
78 */
79class AutomaticGainControl
80{
81  public:
82    /// default constructor
83    AutomaticGainControl();
84
85    /// Destructor
86    ~AutomaticGainControl();
87
88    /// Set signal processing values
89    void SetValues(
90            float _elo,
91            float _ehi,
92            float _ka,
93            float _kr,
94            float _gmin,
95            float _gmax);
96
97    /// Get signal processing values
98    void GetValues(
99            float & _elo,
100            float & _ehi,
101            float & _ka,
102            float & _kr,
103            float & _gmin,
104            float & _gmax);
105   
106    /// Get status
107    void GetStatus(float & _gain, float & _energy);
108   
109    /// track signal energy and apply gain (real)
110    void ApplyGain(short & I);
111
112    /// track signal energy and apply gain (complex)
113    void ApplyGain(short & I, short & Q);
114
115  private:
116    /// disallow copy constructor
117    AutomaticGainControl(AutomaticGainControl &);
118
119    /// compute necessary gain value from measured energy
120    void ComputeGain();
121
122    /// low energy threshold
123    float energy_lo;
124
125    /// high energy threshold
126    float energy_hi;
127
128    /// attack time constant
129    float ka;
130
131    /// release time constant
132    float kr;
133
134    /// minimum gain value
135    float gmin;
136
137    /// maximum gain value
138    float gmax;
139
140    /// actual tracking gain value
141    float gain;
142
143    /// actual tracking average energy value
144    float energy;
145
146    /// low-pass filter coefficient for estimating average energy
147    float zeta;
148
149    /// average energy threshold for smoother tracking
150    float energy_av;
151
152};
153
154class phase_detect {
155
156 public:
157    phase_detect(float scale_factor);
158 
159    void do_work(short I_in, short Q_in, short I_nco, short Q_nco, short &out);
160
161 private:
162    phase_detect(const phase_detect &);
163
164    float scale_factor;
165};
166
167
168class nco {
169  public:
170    nco();
171    nco(unsigned int max_out);
172
173    void do_work(short control_voltage, short &sine, short &cosine);
174
175  private:
176    nco(const nco &);
177
178    int freq_index;
179    int max_out;
180};
181
182class gain {
183  public:
184    gain();
185
186    void do_work(float gain, short data_in, short &out);
187
188  private:
189    gain(const gain &);
190
191};
192
193class iir_filter {
194  public:
195    iir_filter(float a[], unsigned int len_a, float b[], unsigned int len_b);
196
197    void do_work(short x, short &y);
198
199  private:
200    iir_filter(const iir_filter &);
201
202    float *A;
203    float *B;
204    unsigned int len_A, len_B;
205
206    float *v;
207    unsigned int len_v;
208    unsigned int next_v;
209};
210
211
212//-----------------------------------------------------------------------------
213//
214// FIR polyphase filter bank
215//
216//-----------------------------------------------------------------------------
217/** \brief Finite impulse response (FIR) polyphase filter bank
218 *
219 * This class implementes a finite impulse response (FIR) polyphase filter
220 * bank useful for decimators that need to interpolate samples in digital
221 * receivers.
222 *
223 * Certain filter prototypes are supported, including
224 *   - raised-cosine
225 *   - root raised-cosine
226 *   - gaussian
227 *   - triangular
228 *   - hamming
229 *
230 * The user can also load coefficients...
231 *
232 */
233class FIRPolyphaseFilterBank {
234  public:
235    /// Initializing constructor
236    FIRPolyphaseFilterBank(
237            char * _type,       // type of filter
238            unsigned int _k,    // samples per symbol
239            unsigned int _m,    // delay
240            float _beta,        // excess bandwidth factor
241            unsigned int _Npfb  // number of filters
242            );
243
244    ///
245    FIRPolyphaseFilterBank(
246            unsigned int * _H,  // filter bank coefficients
247            unsigned int _h_len,//
248            unsigned int _Npfb  // number of filters
249            );
250
251    /// destructor
252    ~FIRPolyphaseFilterBank();
253
254    /// push input value into buffer
255    void PushInput(int _x);
256
257    /// compute filter output from current buffer state using specific filter
258    void ComputeOutput(
259            short &y,           // output sample
260            unsigned int _b     // filter bank index
261            );
262
263    /// reset filter buffer
264    void ResetBuffer();
265
266    /// prints filter bank coefficients to the screen
267    void PrintFilterBankCoefficients();
268
269  private:
270    /// disallow copy constructor
271    FIRPolyphaseFilterBank(const FIRPolyphaseFilterBank&);
272
273    /// type of filter; can be one of the following
274    ///   - 'rrcos'
275    ///   - 'gaussian'
276    char * type;
277
278    /// samples per symbol
279    unsigned int k;
280
281    /// symbol delay
282    unsigned int m;
283
284    /// excess bandwidth factor
285    float beta;
286
287    /// number of filters in bank
288    unsigned int Npfb;
289
290    /// filter bank coefficients
291    float *H;
292
293    /// length of each filter
294    unsigned int h_len;
295
296    /// circular input buffer (header ptr)
297    short *v;
298
299    /// input buffer read ptr
300    short *v_head_ptr;
301
302    /// input buffer length
303    unsigned int v_len;
304
305    /// transpose filter bank coefficient matrix
306    void TransposeCoefficientMatrix();
307
308    // ----- calculate filter bank coefficients -----
309
310    /// Calculate root raised-cosine coefficients
311    void CalculateRRCFilterCoefficients();
312
313    /// Calculate derivative root raised-cosine coefficients
314    void CalculateDerivativeRRCFilterCoefficients();
315
316    ///
317    void CalculateGaussianFilterCoefficients();
318
319    ///
320    void CalculateDerivativeGaussianFilterCoefficients();
321};
322
323
324
325class fir_filter {
326  public:
327    fir_filter(float a[], unsigned int len_a);
328
329    void do_work(bool run_filter, short in_sample, short &out_sample);
330    void reset();
331
332  private:
333    fir_filter(const fir_filter &);
334
335#ifdef FPM
336    mad_fixed_t *A;
337    mad_fixed_t *v;
338#else
339    float *A;
340    short *v;
341#endif
342    unsigned int len_A;
343
344    unsigned int len_v;
345    unsigned int next_v;
346};
347
348class dump_data {
349 public:
350  dump_data(const char *filename, long start_sample, long number_of_samples);
351  ~dump_data();
352
353  void write_data(float data, const char *msg = "");
354  void write_data(float a, float b, const char *msg = "");
355
356 private:
357  dump_data();
358  dump_data(const dump_data &);
359
360  std::ofstream *out_file;
361
362  long start_sample, stop_sample;
363  long current_sample;
364
365};
366
367class dc_block {
368  public:
369    dc_block(const float forget_factor);
370    ~dc_block();
371
372    void do_work(short in, short &out);
373
374  private:
375    dc_block();
376    dc_block(const dc_block &);
377
378    float forget_factor;
379    int prev_input, prev_output;
380
381};
382}
383
384#endif
Note: See TracBrowser for help on using the browser.