GNU Radio 3.5.3.1 C++ API
atsci_sliding_correlator.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 #ifndef _ATSC_SLIDING_CORRELATOR_H_
23 #define _ATSC_SLIDING_CORRELATOR_H_
24 
25 #include <atsc_api.h>
26 #include <string.h>
27 
28 #include <atsci_pnXXX.h>
29 //extern const unsigned char atsc_pn511[511];
30 //extern const unsigned char atsc_pn63[63];
31 
32 /*!
33  * \brief look for the PN 511 field sync pattern
34  */
36  public:
37 
40 
41  //! input hard decision bit, return correlation (0,511)
42  // Result is the number of wrong bits.
43  // E.g., 0 -> perfect match; 511 -> all bits are wrong
44 
45  int input_bit (int bit);
46 
47  //! input sample, return correlation (0,511)
48  // Result is the number of wrong bits.
49  // E.g., 0 -> perfect match; 511 -> all bits are wrong
50 
51  int input_int (int sample){
52  return input_bit (sample < 0 ? 0 : 1);
53  }
54 
55  //! input sample, return correlation (0,511)
56  // Result is the number of wrong bits.
57  // E.g., 0 -> perfect match; 511 -> all bits are wrong
58 
59  int input_float (float sample){
60  return input_bit (sample < 0 ? 0 : 1);
61  }
62 
63  void reset () { input.reset (); }
64 
65  private:
66 
67  typedef unsigned long srblock;
68  static const int bits_per_char = 8;
69  static const int srblock_bitsize = sizeof (srblock) * bits_per_char;
70  static const int NSRBLOCKS = (511 + srblock_bitsize - 1) / srblock_bitsize;
71 
72  class shift_reg {
73  public:
74  shift_reg () { reset (); }
75  void reset () { memset (d, 0, sizeof (d)); }
76  void shift_in (int bit);
77  srblock d[NSRBLOCKS];
78  };
79 
80  shift_reg mask; // pattern we're looking for
81  shift_reg input; // current input window
82  shift_reg and_mask; // bits to consider
83 };
84 
85 #endif /* _ATSC_SLIDING_CORRELATOR_H_ */