GNU Radio C++ API
gr_simple_correlator.h
Go to the documentation of this file.
1
/* -*- c++ -*- */
2
/*
3
* Copyright 2004 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 <
gr_core_api.h
>
27
#include <
gr_block.h
>
28
#include <assert.h>
29
30
//#define DEBUG_SIMPLE_CORRELATOR
31
32
class
gr_simple_correlator
;
33
typedef
boost::shared_ptr<gr_simple_correlator>
gr_simple_correlator_sptr
;
34
35
GR_CORE_API
gr_simple_correlator_sptr
gr_make_simple_correlator
(
int
payload_bytesize);
36
37
/*!
38
* \brief inverse of gr_simple_framer (more or less)
39
* \ingroup sync_blk
40
*/
41
class
GR_CORE_API
gr_simple_correlator
:
public
gr_block
42
{
43
static
const
int
OVERSAMPLE = 8;
44
enum
state_t { ST_LOOKING, ST_UNDER_THRESHOLD, ST_LOCKED };
45
46
int
d_payload_bytesize;
47
state_t d_state;
48
unsigned
int
d_osi;
// over sample index [0,OVERSAMPLE-1]
49
unsigned
int
d_transition_osi;
// first index where Hamming dist < thresh
50
unsigned
int
d_center_osi;
// center of bit
51
unsigned
long
long
int
d_shift_reg[OVERSAMPLE];
52
int
d_bblen;
// length of bitbuf
53
unsigned
char
*d_bitbuf;
// demodulated bits
54
unsigned
char
*d_pktbuf;
// temp packet buf
55
int
d_bbi;
// bitbuf index
56
57
static
const
int
AVG_PERIOD = 512;
// must be power of 2 (for freq offset correction)
58
int
d_avbi;
59
float
d_avgbuf[AVG_PERIOD];
60
float
d_avg;
61
float
d_accum;
62
63
#ifdef DEBUG_SIMPLE_CORRELATOR
64
FILE *d_debug_fp;
// binary log file
65
#endif
66
67
friend
GR_CORE_API
gr_simple_correlator_sptr
gr_make_simple_correlator
(
int
payload_bytesize);
68
gr_simple_correlator
(
int
payload_bytesize);
69
70
71
inline
int
slice (
float
x)
72
{
73
return
x >= d_avg ? 1 : 0;
74
}
75
76
void
update_avg(
float
x);
77
78
void
enter_locked ();
79
void
enter_under_threshold ();
80
void
enter_looking ();
81
82
static
int
add_index (
int
a,
int
b)
83
{
84
int
t = a + b;
85
if
(t >= OVERSAMPLE)
86
t -= OVERSAMPLE;
87
assert (t >= 0 && t < OVERSAMPLE);
88
return
t;
89
}
90
91
static
int
sub_index (
int
a,
int
b)
92
{
93
int
t = a - b;
94
if
(t < 0)
95
t += OVERSAMPLE;
96
assert (t >= 0 && t < OVERSAMPLE);
97
return
t;
98
}
99
100
101
public
:
102
~
gr_simple_correlator
();
103
104
int
general_work
(
int
noutput_items,
105
gr_vector_int
&ninput_items,
106
gr_vector_const_void_star
&input_items,
107
gr_vector_void_star
&output_items);
108
};
109
110
111
#endif
/* INCLUDED_GR_SIMPLE_CORRELATOR_H */
gnuradio-core
src
lib
general
gr_simple_correlator.h
Generated on Thu Jul 12 2012 00:06:23 for GNU Radio C++ API by
1.8.1.1