Changeset 14101 for trunk/Mars
- Timestamp:
- 06/07/12 11:01:27 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/mcore/DrsCalib.h
r14080 r14101 208 208 vec[i] = double(v)*scalegain/div; 209 209 } 210 } 211 212 static double FindStep(const size_t ch0, const float *vec, int16_t roi, const int16_t pos, const uint16_t *map) 213 { 214 if (pos<=1 || pos>=roi) 215 return 0; 216 217 double step = 0; // before 218 219 // Exclude TM channel 220 for (int p=0; p<8; p++) 221 { 222 const size_t hw = ch0+p; 223 const size_t sw = map[hw]*roi + pos; 224 225 step += vec[sw]-vec[sw-1]; 226 } 227 228 return step/8; 229 } 230 231 static void SubtractStep(const size_t ch0, const double avg, float *vec, int16_t roi, uint32_t dist, const uint16_t *map) 232 { 233 const int begin = avg>0 ? dist : 0; 234 const int end = avg>0 ? roi : dist; 235 236 const double sub = fabs(avg); 237 238 for (int p=0; p<9; p++) 239 { 240 for (int j=begin; j<end; j++) 241 { 242 const size_t hw = ch0+p; 243 const size_t sw = map[hw]*roi + j; 244 245 vec[sw] -= sub; 246 } 247 } 248 } 249 250 struct Step 251 { 252 Step() : avg(0), rms(0), pos(0), cnt(0) { } 253 double avg; 254 double rms; 255 double pos; 256 uint16_t cnt; 257 }; 258 259 static Step CorrectStep(float *vec, uint16_t nch, uint16_t roi, 260 const int16_t *prev, const int16_t *start, 261 const int16_t offset, const uint16_t *map) 262 { 263 Step rc; 264 265 for (size_t ch=0; ch<nch; ch += 9) 266 { 267 if (prev[ch]<0 || start[ch]<0) 268 continue; 269 270 const int16_t dist = (prev[ch]-start[ch]+1024+offset)%1024; 271 const double step = FindStep(ch, vec, roi, dist, map); 272 if (step==0) 273 continue; 274 275 rc.pos += dist; 276 rc.avg += step; 277 rc.rms += step*step; 278 rc.cnt++; 279 } 280 281 if (rc.cnt==0 || rc.avg==0) 282 return Step(); 283 284 rc.pos /= rc.cnt; 285 rc.avg /= rc.cnt; 286 rc.rms /= rc.cnt; 287 288 rc.rms = sqrt(rc.rms-rc.avg*rc.avg); 289 290 for (size_t ch=0; ch<nch; ch += 9) 291 { 292 const int16_t dist = (prev[ch]-start[ch]+1024+offset)%1024; 293 SubtractStep(ch, rc.avg, vec, roi, dist, map); 294 } 295 296 return rc; 210 297 } 211 298
Note:
See TracChangeset
for help on using the changeset viewer.