Changeset 14800 for fact/tools/rootmacros/SpikeRemoval.C
- Timestamp:
- 01/31/13 09:02:26 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/rootmacros/SpikeRemoval.C
r13535 r14800 7 7 vector<float> * computeN1mean( vector<float> &src) 8 8 { 9 9 vector<float> * dest = new vector<float>; 10 10 11 11 dest->push_back(src[1]); 12 12 13 13 for(unsigned int i = 1; i < src.size() - 1; i++){ 14 14 /* if (i == 0){ // use right sample es mean 15 16 17 18 19 20 21 22 15 N1mean[i] = Ameas[i+1]; 16 } 17 else if ( i == Samples-1 ){ //use left sample as mean 18 N1mean[i] = Ameas[i-1]; 19 } 20 else{ 21 N1mean[i] = ( Ameas[i-1] + Ameas[i+1] ) / 2.; 22 } 23 23 */ 24 25 24 dest->push_back( ( src[i-1] + src[i+1] ) / 2. ); 25 } 26 26 27 28 27 dest->push_back(src[src.size() - 1]); 28 return dest; 29 29 } // end of computeN1mean computation 30 30 31 31 void removeSpikes( 32 33 34 35 36 32 vector<float> &src, 33 vector<float> &dest, 34 const float CandidateTHR, 35 const float nextDiffTHR, 36 const float nextNextDiffTHR 37 37 ){ 38 vector<float> * NextNeighborMean = computeN1mean(src); 38 //vector with Mean values of both neighbor samples of a sample 39 vector<float> * NextNeighborMean = computeN1mean(src); 39 40 40 if (src.size() != NextNeighborMean->size()) 41 //TODO .. if verbositylevel .. say something, use the return code to tell the caller.. 42 dest.clear(); 43 dest = src; 41 if (src.size() != NextNeighborMean->size()) 42 { 43 //TODO .. if verbositylevel .. say something, use the return code to tell the caller.. 44 dest.clear(); 45 } 46 dest = src; 44 47 45 48 float diff, nextDiff, nextNextDiff; 46 49 47 50 // find the spike and replace it by mean value of neighbors 48 51 for (unsigned int i = 0; i < src.size(); i++) { 49 52 50 diff = src[i] - (*NextNeighborMean)[i]; 53 //calculate difference of sample value and average of both it's neighbors 54 diff = src[i] - (*NextNeighborMean)[i]; 51 55 52 if ( diff < CandidateTHR ){ // a spike candidate 53 // check consistency with a single channel spike 56 //compare sample value to average of both neighbors 57 if ( diff < CandidateTHR ){ // a spike candidate 58 // check consistency with a single channel spike 54 59 55 if ( src[i+2] - ( src[i] + src[i+3] )/2. > 10. ) 56 { 57 dest[i+1] = ( src[i] + src[i+3] )/2.; 58 dest[i+2] = ( src[i] + src[i+3] )/2.; 59 i = i + 3; 60 } 61 else 62 { 63 nextDiff = src[i+1] - (*NextNeighborMean)[i+1]; 64 nextNextDiff = src[i+2] - (*NextNeighborMean)[i+2]; 60 // check if the nectneighbor is a spike candidate too 61 if ( src[i+2] - ( src[i] + src[i+3] )/2. > 10. ) 62 { 63 dest[i+1] = ( src[i] + src[i+3] )/2.; 64 dest[i+2] = ( src[i] + src[i+3] )/2.; 65 65 66 if ( ( nextDiff > nextDiffTHR * diff ) && ( nextNextDiff < nextNextDiffTHR ) ){ 67 dest[i+1] = (*NextNeighborMean)[i+1]; 68 (*NextNeighborMean)[i+2] = (src[i+1] - src[i+3] / 2.); 69 i = i + 2;//do not care about the next sample it was the spike 70 } 71 // treatment for the end of the pipeline must be added !!! 72 } 73 } 74 } // end of spike search and correction 75 delete NextNeighborMean; 76 return; 66 i = i + 3; 67 } 68 else 69 { 70 //calculate difference of sample value and average of both it's neighbors of next sample 71 nextDiff = src[i+1] - (*NextNeighborMean)[i+1]; 72 //calculate difference of sample value and average of both it's neighbors of over-next sample 73 nextNextDiff = src[i+2] - (*NextNeighborMean)[i+2]; 74 75 if ( ( nextDiff > nextDiffTHR * diff ) && ( nextNextDiff < nextNextDiffTHR ) ) 76 { 77 dest[i+1] = (*NextNeighborMean)[i+1]; 78 (*NextNeighborMean)[i+2] = (src[i+1] - src[i+3] / 2.); 79 80 i = i + 2;//do not care about the next sample it was the spike 81 } 82 // treatment for the end of the pipeline must be added !!! 83 } 84 } 85 } // end of spike search and correction 86 delete NextNeighborMean; 87 return; 77 88 }
Note:
See TracChangeset
for help on using the changeset viewer.