Statistics
| Branch: | Tag: | Revision:

root / gr-atsc / src / lib / atsci_sliding_correlator.h @ ea9c9ca4

History | View | Annotate | Download (2.4 kB)

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