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