Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

VrCorr.h

Go to the documentation of this file.
00001 /* -*- Mode: c++ -*- 00002 * 00003 * Copyright 1997 Massachusetts Institute of Technology 00004 * 00005 * Permission to use, copy, modify, distribute, and sell this software and its 00006 * documentation for any purpose is hereby granted without fee, provided that 00007 * the above copyright notice appear in all copies and that both that 00008 * copyright notice and this permission notice appear in supporting 00009 * documentation, and that the name of M.I.T. not be used in advertising or 00010 * publicity pertaining to distribution of the software without specific, 00011 * written prior permission. M.I.T. makes no representations about the 00012 * suitability of this software for any purpose. It is provided "as is" 00013 * without express or implied warranty. 00014 * 00015 */ 00016 00017 00018 #ifndef _VrCORR_H_ 00019 #define _VrCORR_H_ 00020 00021 #define SIZE 4096 00022 00023 #include <VrDecimatingSigProc.h> 00024 #include <fstream> 00025 00026 00027 // ******************************************************** 00028 00029 00030 template<class iType,class oType> 00031 class VrCorr : public VrDecimatingSigProc<iType,oType> { 00032 protected: 00033 00034 float result, old_result, *sqr, weight_sign, max; 00035 u_int first, first_high, first_low, current, mask; 00036 int corr_on, differential_offset; 00037 int low_interval, high_interval, max_id; 00038 int sync_period, corr_period, corr_count, pattern_length, pattern_count, corr_init; 00039 00040 public: 00041 virtual const char *name() { return "VrCorr"; } 00042 virtual int forecast(VrSampleRange output, 00043 VrSampleRange inputs[]); 00044 virtual int work(VrSampleRange output, void *o[], 00045 VrSampleRange inputs[], void *i[]); 00046 virtual void initialize(); 00047 virtual void setSync_Period(int per) { sync_period = per;} 00048 virtual void setCorr_Period(int per) { corr_period = per + pattern_length;} 00049 00050 VrCorr(int, int, int, int); 00051 ~VrCorr(); 00052 }; 00053 00054 template<class iType,class oType> int 00055 VrCorr<iType,oType>::work(VrSampleRange output, void *ao[], 00056 VrSampleRange inputs[], void *ai[]) { 00057 00058 00059 00060 /* Correlator that looks for "low-high-low" shape in symbol sequence 00061 * 00062 * |------------| 00063 * | | 00064 * | | 00065 * | | 00066 * |--------------------------------| |----------| 00067 * 00068 * ^ ^ ^ 00069 * | Initialize | Produce output values | OFF 00070 * 00071 * |--pattern length-| <---- desired number of outputs ---->| 00072 * 00073 * 00074 * |<-- corr_init -->| 00075 * |<----- corr_on --------------------------------------->| 00076 00077 */ 00078 00079 00080 iType **i = (iType **)ai; 00081 oType **o = (oType **)ao; 00082 int size; 00083 iType input; 00084 float x, y, sign; 00085 00086 size = output.size; 00087 //cout << "Corr with size: "<< size << endl; 00088 00089 while(size--) { 00090 00091 input = *i[0]++; 00092 00093 corr_count++; 00094 00095 if (corr_count > sync_period-1) { 00096 corr_count = 0; 00097 corr_on = 1; 00098 corr_init = 1; 00099 } 00100 00101 if (corr_count == corr_period) { 00102 corr_on = 0; 00103 cout << "Max is " << max << " at " << max_id << endl; 00104 } 00105 00106 if (corr_on){ 00107 00108 x = real(input); 00109 y = imag(input); 00110 sign = (float) (2 * (x>0.0))-1; 00111 00112 sqr[(current)&mask] = sign*(x*x + y*y); 00113 00114 if (corr_init) { // initialize array used for correlation 00115 00116 pattern_count++; 00117 00118 if (pattern_count == 1){ 00119 //cout << "count =1 " << pattern_count << endl; 00120 old_result = 0.0; 00121 weight_sign = -1.0; 00122 max = 0; 00123 } 00124 00125 if (pattern_count == low_interval + 1){ 00126 //cout << "count = low " << pattern_count << endl; 00127 weight_sign = 1.0; 00128 } 00129 00130 if (pattern_count == low_interval + high_interval + 1) { 00131 //cout << "count = high " << pattern_count << endl; 00132 weight_sign = -1.0; 00133 } 00134 00135 old_result += weight_sign * sign*(x*x + y*y); 00136 00137 *o[0]++ = (oType)0.0; 00138 current++; 00139 00140 if (pattern_count == pattern_length){ 00141 pattern_count = 0; 00142 corr_init = 0; 00143 first = current-pattern_length; 00144 first_high = first + low_interval; 00145 first_low = first_high + high_interval; 00146 } 00147 00148 } else { // now start producing output values 00149 00150 result = old_result; 00151 00152 result += sqr[(first++)&mask]; 00153 result -= (2 * sqr[(first_high++)&mask]); 00154 result += (2 * sqr[(first_low++)&mask]); 00155 result -= sqr[(current++)&mask]; 00156 00157 if (result > max) { 00158 max = result; 00159 max_id = corr_count; 00160 } 00161 old_result = result; 00162 //cout << 2.0* result << " written to " << (int) o[0] << endl; 00163 00164 *o[0]++ = (oType) (2.0 * result); 00165 } 00166 00167 } else { // output zero when not performing correlation 00168 00169 *o[0]++ = (oType) 0.0; 00170 } 00171 } 00172 return output.size; 00173 00174 } 00175 00176 template<class iType,class oType> 00177 VrCorr<iType,oType>::VrCorr(int dec, int pts_per_symbol, int low_int, int high_int) 00178 :VrDecimatingSigProc<iType,oType>(1,dec),low_interval(low_int * pts_per_symbol), 00179 high_interval(high_int * pts_per_symbol) 00180 { 00181 } 00182 00183 template<class iType, class oType> int 00184 VrCorr<iType,oType>::forecast(VrSampleRange output, 00185 VrSampleRange inputs[]) { 00186 /* dec:1 ratio with history */ 00187 for(unsigned int i=0;i<numberInputs;i++) { 00188 inputs[i].index=output.index*decimation+ differential_offset; /* ! do not subtract history ! */ 00189 inputs[i].size=output.size*decimation + history-1; 00190 //jca printf ("VrCorr forecast[i] ts %lld size %ld output.index %lld dec %d off %d\n", inputs[i].index, inputs[i].size, 00191 //jca output.index, decimation, differential_offset); 00192 } 00193 return 0; 00194 } 00195 00196 00197 template<class iType,class oType> 00198 void VrCorr<iType,oType>::initialize() 00199 { 00200 00201 sqr = new float[SIZE]; 00202 mask = (u_int) (SIZE-1); 00203 differential_offset = 0; 00204 00205 00206 first = 0; 00207 first_high = low_interval; 00208 first_low = first_high + high_interval; 00209 #if 0 00210 current = first_low + low_interval; 00211 #endif 00212 00213 current = 0; 00214 corr_on = 1; 00215 corr_init = 1; 00216 corr_count = 0; 00217 sync_period = 500; 00218 corr_period = 400; 00219 pattern_length = low_interval + high_interval + low_interval; 00220 pattern_count = 0; 00221 } 00222 00223 template<class iType,class oType> 00224 VrCorr<iType,oType>::~VrCorr() 00225 { 00226 delete sqr; 00227 } 00228 00229 #endif 00230 00231 00232 00233 00234 00235 00236 00237 00238

Generated on Wed Aug 4 02:22:05 2004 for GNU Radio by doxygen 1.3.8