3 * Copyright 2004 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
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)
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.
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.
23 #ifndef INCLUDED_GR_SIMPLE_CORRELATOR_H
24 #define INCLUDED_GR_SIMPLE_CORRELATOR_H
29 //#define DEBUG_SIMPLE_CORRELATOR
31 class gr_simple_correlator;
32 typedef boost::shared_ptr<gr_simple_correlator> gr_simple_correlator_sptr;
34 gr_simple_correlator_sptr gr_make_simple_correlator (int payload_bytesize);
37 * \brief inverse of gr_simple_framer (more or less)
40 class gr_simple_correlator : public gr_block
42 static const int OVERSAMPLE = 8;
43 enum state_t { ST_LOOKING, ST_UNDER_THRESHOLD, ST_LOCKED };
45 int d_payload_bytesize;
47 unsigned int d_osi; // over sample index [0,OVERSAMPLE-1]
48 unsigned int d_transition_osi; // first index where Hamming dist < thresh
49 unsigned int d_center_osi; // center of bit
50 unsigned long long int d_shift_reg[OVERSAMPLE];
51 int d_bblen; // length of bitbuf
52 unsigned char *d_bitbuf; // demodulated bits
53 int d_bbi; // bitbuf index
55 static const int AVG_PERIOD = 512; // must be power of 2 (for freq offset correction)
57 float d_avgbuf[AVG_PERIOD];
61 #ifdef DEBUG_SIMPLE_CORRELATOR
62 FILE *d_debug_fp; // binary log file
65 friend gr_simple_correlator_sptr gr_make_simple_correlator (int payload_bytesize);
66 gr_simple_correlator (int payload_bytesize);
69 inline int slice (float x)
71 return x >= d_avg ? 1 : 0;
74 void update_avg(float x);
77 void enter_under_threshold ();
78 void enter_looking ();
80 static int add_index (int a, int b)
85 assert (t >= 0 && t < OVERSAMPLE);
89 static int sub_index (int a, int b)
94 assert (t >= 0 && t < OVERSAMPLE);
100 ~gr_simple_correlator ();
102 int general_work (int noutput_items,
103 gr_vector_int &ninput_items,
104 gr_vector_const_void_star &input_items,
105 gr_vector_void_star &output_items);
109 #endif /* INCLUDED_GR_SIMPLE_CORRELATOR_H */