GNU Radio Manual and C++ API Reference  3.7.9.2
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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  public:
38 
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){
53  return input_bit (sample < 0 ? 0 : 1);
54  }
55 
56  //! input sample, return correlation (0,511)
57  // Result is the number of wrong bits.
58  // E.g., 0 -> perfect match; 511 -> all bits are wrong
59 
60  int input_float (float sample){
61  return input_bit (sample < 0 ? 0 : 1);
62  }
63 
64  void reset () { input.reset (); }
65 
66  private:
67 
68  typedef unsigned long srblock;
69  static const int bits_per_char = 8;
70  static const int srblock_bitsize = sizeof (srblock) * bits_per_char;
71  static const int NSRBLOCKS = (511 + srblock_bitsize - 1) / srblock_bitsize;
72 
73  class shift_reg {
74  public:
75  shift_reg () { reset (); }
76  void reset () { memset (d, 0, sizeof (d)); }
77  void shift_in (int bit);
78  srblock d[NSRBLOCKS];
79  };
80 
81  shift_reg mask; // pattern we're looking for
82  shift_reg input; // current input window
83  shift_reg and_mask; // bits to consider
84 };
85 
86 #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:60
look for the PN 511 field sync pattern
Definition: sliding_correlator_impl.h:36
void reset()
Definition: sliding_correlator_impl.h:64