GNU Radio 3.6.4 C++ API
digital_simple_correlator.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2004,2013 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio 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 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef INCLUDED_GR_SIMPLE_CORRELATOR_H
24 #define INCLUDED_GR_SIMPLE_CORRELATOR_H
25 
26 #include <digital_api.h>
27 #include <gr_block.h>
28 
31 
33 
34 /*!
35  * \brief inverse of simple_framer (more or less)
36  * \ingroup sync_blk
37  */
39 {
40  private:
41  static const int OVERSAMPLE = 8;
42  enum state_t { ST_LOOKING, ST_UNDER_THRESHOLD, ST_LOCKED };
43 
44  int d_payload_bytesize;
45  state_t d_state;
46  unsigned int d_osi; // over sample index [0,OVERSAMPLE-1]
47  unsigned int d_transition_osi; // first index where Hamming dist < thresh
48  unsigned int d_center_osi; // center of bit
49  unsigned long long int d_shift_reg[OVERSAMPLE];
50  int d_bblen; // length of bitbuf
51  unsigned char *d_bitbuf; // demodulated bits
52  unsigned char *d_pktbuf; // temp packet buf
53  int d_bbi; // bitbuf index
54 
55  static const int AVG_PERIOD = 512; // must be power of 2 (for freq offset correction)
56  int d_avbi;
57  float d_avgbuf[AVG_PERIOD];
58  float d_avg;
59  float d_accum;
60 
61 #ifdef DEBUG_SIMPLE_CORRELATOR
62  FILE *d_debug_fp; // binary log file
63 #endif
64 
66  digital_make_simple_correlator(int payload_bytesize);
67  digital_simple_correlator(int payload_bytesize);
68 
69  inline int slice(float x)
70  {
71  return x >= d_avg ? 1 : 0;
72  }
73 
74  void update_avg(float x);
75 
76  void enter_locked();
77  void enter_under_threshold();
78  void enter_looking();
79 
80  static int add_index(int a, int b)
81  {
82  int t = a + b;
83  if(t >= OVERSAMPLE)
84  t -= OVERSAMPLE;
85  assert(t >= 0 && t < OVERSAMPLE);
86  return t;
87  }
88 
89  static int sub_index(int a, int b)
90  {
91  int t = a - b;
92  if(t < 0)
93  t += OVERSAMPLE;
94  assert(t >= 0 && t < OVERSAMPLE);
95  return t;
96  }
97 
98  public:
100 
101  int general_work(int noutput_items,
102  gr_vector_int &ninput_items,
103  gr_vector_const_void_star &input_items,
104  gr_vector_void_star &output_items);
105 };
106 
107 #endif /* INCLUDED_GR_SIMPLE_CORRELATOR_H */