GNU Radio Manual and C++ API Reference  3.7.14.0
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
sliding_correlator_impl.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2002 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 _ATSC_SLIDING_CORRELATOR_H_
24 #define _ATSC_SLIDING_CORRELATOR_H_
25 
26 #include <gnuradio/atsc/api.h>
27 #include <string.h>
28 
30 // extern const unsigned char atsc_pn511[511];
31 // extern const unsigned char atsc_pn63[63];
32 
33 /*!
34  * \brief look for the PN 511 field sync pattern
35  */
37 {
38 public:
41 
42  //! input hard decision bit, return correlation (0,511)
43  // Result is the number of wrong bits.
44  // E.g., 0 -> perfect match; 511 -> all bits are wrong
45 
46  int input_bit(int bit);
47 
48  //! input sample, return correlation (0,511)
49  // Result is the number of wrong bits.
50  // E.g., 0 -> perfect match; 511 -> all bits are wrong
51 
52  int input_int(int sample) { return input_bit(sample < 0 ? 0 : 1); }
53 
54  //! input sample, return correlation (0,511)
55  // Result is the number of wrong bits.
56  // E.g., 0 -> perfect match; 511 -> all bits are wrong
57 
58  int input_float(float sample) { return input_bit(sample < 0 ? 0 : 1); }
59 
60  void reset() { input.reset(); }
61 
62 private:
63  typedef unsigned long srblock;
64  static const int bits_per_char = 8;
65  static const int srblock_bitsize = sizeof(srblock) * bits_per_char;
66  static const int NSRBLOCKS = (511 + srblock_bitsize - 1) / srblock_bitsize;
67 
68  class shift_reg
69  {
70  public:
71  shift_reg() { reset(); }
72  void reset() { memset(d, 0, sizeof(d)); }
73  void shift_in(int bit);
74  srblock d[NSRBLOCKS];
75  };
76 
77  shift_reg mask; // pattern we're looking for
78  shift_reg input; // current input window
79  shift_reg and_mask; // bits to consider
80 };
81 
82 #endif /* _ATSC_SLIDING_CORRELATOR_H_ */
#define ATSC_API
Definition: gr-atsc/include/gnuradio/atsc/api.h:30
~atsci_sliding_correlator()
Definition: sliding_correlator_impl.h:40
int input_int(int sample)
input sample, return correlation (0,511)
Definition: sliding_correlator_impl.h:52
int input_float(float sample)
input sample, return correlation (0,511)
Definition: sliding_correlator_impl.h:58
look for the PN 511 field sync pattern
Definition: sliding_correlator_impl.h:36
void reset()
Definition: sliding_correlator_impl.h:60