3 * Copyright 2002 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.
25 #ifndef _ATSC_SLIDING_CORRELATOR_H_
26 #define _ATSC_SLIDING_CORRELATOR_H_
28 extern const unsigned char atsc_pn511[511];
29 extern const unsigned char atsc_pn63[63];
32 * \brief look for the PN 511 field sync pattern
34 class atsci_sliding_correlator {
37 atsci_sliding_correlator ();
38 ~atsci_sliding_correlator (){};
40 //! input hard decision bit, return correlation (0,511)
41 // Result is the number of wrong bits.
42 // E.g., 0 -> perfect match; 511 -> all bits are wrong
44 int input_bit (int bit);
46 //! input sample, return correlation (0,511)
47 // Result is the number of wrong bits.
48 // E.g., 0 -> perfect match; 511 -> all bits are wrong
50 int input_int (int sample){
51 return input_bit (sample < 0 ? 0 : 1);
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
58 int input_float (float sample){
59 return input_bit (sample < 0 ? 0 : 1);
62 void reset () { input.reset (); }
66 typedef unsigned long srblock;
67 static const int bits_per_char = 8;
68 static const int srblock_bitsize = sizeof (srblock) * bits_per_char;
69 static const int NSRBLOCKS = (511 + srblock_bitsize - 1) / srblock_bitsize;
73 shift_reg () { reset (); }
74 void reset () { memset (d, 0, sizeof (d)); }
75 void shift_in (int bit);
79 shift_reg mask; // pattern we're looking for
80 shift_reg input; // current input window
81 shift_reg and_mask; // bits to consider
84 #endif /* _ATSC_SLIDING_CORRELATOR_H_ */