GNU Radio 3.6.5 C++ API

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 #ifndef _ATSC_SLIDING_CORRELATOR_H_
00023 #define _ATSC_SLIDING_CORRELATOR_H_
00024 
00025 #include <atsc_api.h>
00026 #include <string.h>
00027 
00028 #include <atsci_pnXXX.h>
00029 //extern const unsigned char atsc_pn511[511];
00030 //extern const unsigned char atsc_pn63[63];
00031 
00032 /*!
00033  * \brief look for the PN 511 field sync pattern
00034  */
00035 class ATSC_API atsci_sliding_correlator {
00036  public:
00037 
00038   atsci_sliding_correlator ();
00039   ~atsci_sliding_correlator (){};
00040 
00041   //! input hard decision bit, return correlation (0,511)
00042   // Result is the number of wrong bits.
00043   // E.g., 0 -> perfect match; 511 -> all bits are wrong
00044 
00045   int input_bit (int bit);
00046 
00047   //! input sample, return correlation (0,511)
00048   // Result is the number of wrong bits.
00049   // E.g., 0 -> perfect match; 511 -> all bits are wrong
00050 
00051   int input_int (int sample){
00052     return input_bit (sample < 0 ? 0 : 1);
00053   }
00054 
00055   //! input sample, return correlation (0,511)
00056   // Result is the number of wrong bits.
00057   // E.g., 0 -> perfect match; 511 -> all bits are wrong
00058 
00059   int input_float (float sample){
00060     return input_bit (sample < 0 ? 0 : 1);
00061   }
00062 
00063   void reset () { input.reset (); }
00064 
00065  private:
00066 
00067   typedef unsigned long srblock;
00068   static const int bits_per_char = 8;
00069   static const int srblock_bitsize = sizeof (srblock) * bits_per_char;
00070   static const int NSRBLOCKS = (511 + srblock_bitsize - 1) / srblock_bitsize;
00071 
00072   class shift_reg {
00073   public:
00074     shift_reg ()  { reset (); }
00075     void reset () { memset (d, 0, sizeof (d)); }
00076     void shift_in (int bit);
00077     srblock     d[NSRBLOCKS];
00078   };
00079 
00080   shift_reg     mask;           // pattern we're looking for
00081   shift_reg     input;          // current input window
00082   shift_reg     and_mask;       // bits to consider
00083 };
00084 
00085 #endif /* _ATSC_SLIDING_CORRELATOR_H_ */