00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
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
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) {
00115
00116 pattern_count++;
00117
00118 if (pattern_count == 1){
00119
00120 old_result = 0.0;
00121 weight_sign = -1.0;
00122 max = 0;
00123 }
00124
00125 if (pattern_count == low_interval + 1){
00126
00127 weight_sign = 1.0;
00128 }
00129
00130 if (pattern_count == low_interval + high_interval + 1) {
00131
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 {
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
00163
00164 *o[0]++ = (oType) (2.0 * result);
00165 }
00166
00167 } else {
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
00187 for(unsigned int i=0;i<numberInputs;i++) {
00188 inputs[i].index=output.index*decimation+ differential_offset;
00189 inputs[i].size=output.size*decimation + history-1;
00190
00191
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