atsci_sliding_correlator.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2002 Free Software Foundation, Inc.
00004  * 
00005  * This file is part of GNU Radio
00006  * 
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  * 
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 #include <string>
00023 #include <string.h>
00024 
00025 #ifndef _ATSC_SLIDING_CORRELATOR_H_
00026 #define _ATSC_SLIDING_CORRELATOR_H_
00027 
00028 extern const unsigned char atsc_pn511[511];
00029 extern const unsigned char atsc_pn63[63];
00030 
00034 class atsci_sliding_correlator {
00035  public:
00036 
00037   atsci_sliding_correlator ();
00038   ~atsci_sliding_correlator (){};
00039 
00041   // Result is the number of wrong bits.  
00042   // E.g., 0 -> perfect match; 511 -> all bits are wrong
00043 
00044   int input_bit (int bit);
00045 
00047   // Result is the number of wrong bits.  
00048   // E.g., 0 -> perfect match; 511 -> all bits are wrong
00049 
00050   int input_int (int sample){
00051     return input_bit (sample < 0 ? 0 : 1);
00052   }
00053 
00055   // Result is the number of wrong bits.  
00056   // E.g., 0 -> perfect match; 511 -> all bits are wrong
00057 
00058   int input_float (float sample){
00059     return input_bit (sample < 0 ? 0 : 1);
00060   }
00061 
00062   void reset () { input.reset (); }
00063   
00064  private:
00065 
00066   typedef unsigned long srblock;
00067   static const int bits_per_char = 8;
00068   static const int srblock_bitsize = sizeof (srblock) * bits_per_char;
00069   static const int NSRBLOCKS = (511 + srblock_bitsize - 1) / srblock_bitsize;
00070 
00071   class shift_reg {
00072   public:
00073     shift_reg ()  { reset (); }
00074     void reset () { memset (d, 0, sizeof (d)); }
00075     void shift_in (int bit);
00076     srblock     d[NSRBLOCKS];
00077   };
00078 
00079   shift_reg     mask;           // pattern we're looking for
00080   shift_reg     input;          // current input window
00081   shift_reg     and_mask;       // bits to consider
00082 };
00083 
00084 #endif /* _ATSC_SLIDING_CORRELATOR_H_ */

Generated on Mon Oct 6 23:22:29 2008 for GNU Radio 3.1.2 by  doxygen 1.5.7.1