| 1 | // compute the mean of the left and right neighbors of a channel | 
|---|
| 2 | vector<float> * computeN1mean( vector<float> &src) | 
|---|
| 3 | { | 
|---|
| 4 | vector<float> * dest = new vector<float>; | 
|---|
| 5 |  | 
|---|
| 6 | dest->push_back(src[1]); | 
|---|
| 7 |  | 
|---|
| 8 | for(unsigned int i = 1; i < src.size() - 1; i++){ | 
|---|
| 9 | /*        if (i == 0){ // use right sample es mean | 
|---|
| 10 | N1mean[i] = Ameas[i+1]; | 
|---|
| 11 | } | 
|---|
| 12 | else if ( i == Samples-1 ){ //use left sample as mean | 
|---|
| 13 | N1mean[i] = Ameas[i-1]; | 
|---|
| 14 | } | 
|---|
| 15 | else{ | 
|---|
| 16 | N1mean[i] = ( Ameas[i-1] + Ameas[i+1] ) / 2.; | 
|---|
| 17 | } | 
|---|
| 18 | */ | 
|---|
| 19 | dest->push_back( ( src[i-1] + src[i+1] ) / 2. ); | 
|---|
| 20 | } | 
|---|
| 21 |  | 
|---|
| 22 | dest->push_back(src[src.size() - 1]); | 
|---|
| 23 | return dest; | 
|---|
| 24 | } // end of computeN1mean computation | 
|---|
| 25 |  | 
|---|
| 26 | void removeSpikes( | 
|---|
| 27 | vector<float> &src, | 
|---|
| 28 | vector<float> &dest, | 
|---|
| 29 | const float CandidateTHR, | 
|---|
| 30 | const float nextDiffTHR, | 
|---|
| 31 | const float nextNextDiffTHR | 
|---|
| 32 | ){ | 
|---|
| 33 | vector<float> * NextNeighborMean = computeN1mean(src); | 
|---|
| 34 |  | 
|---|
| 35 | if (src.size() != NextNeighborMean->size()) | 
|---|
| 36 | //TODO .. if verbositylevel .. say something, use the return code to tell the caller.. | 
|---|
| 37 | dest.clear(); | 
|---|
| 38 | dest = src; | 
|---|
| 39 |  | 
|---|
| 40 | float diff, nextDiff, nextNextDiff; | 
|---|
| 41 |  | 
|---|
| 42 | // find the spike and replace it by mean value of neighbors | 
|---|
| 43 | for (unsigned int i = 0; i < src.size(); i++) { | 
|---|
| 44 |  | 
|---|
| 45 | diff = src[i] - (*NextNeighborMean)[i]; | 
|---|
| 46 |  | 
|---|
| 47 | if ( diff < CandidateTHR ){ // a spike candidate | 
|---|
| 48 | // check consistency with a single channel spike | 
|---|
| 49 |  | 
|---|
| 50 | if ( src[i+2] - ( src[i] + src[i+3] )/2. > 10. ) | 
|---|
| 51 | { | 
|---|
| 52 | dest[i+1] = ( src[i] + src[i+3] )/2.; | 
|---|
| 53 | dest[i+2] = ( src[i] + src[i+3] )/2.; | 
|---|
| 54 | i = i + 3; | 
|---|
| 55 | } | 
|---|
| 56 | else | 
|---|
| 57 | { | 
|---|
| 58 | nextDiff = src[i+1] - (*NextNeighborMean)[i+1]; | 
|---|
| 59 | nextNextDiff = src[i+2] - (*NextNeighborMean)[i+2]; | 
|---|
| 60 |  | 
|---|
| 61 | if ( ( nextDiff > nextDiffTHR * diff ) && ( nextNextDiff < nextNextDiffTHR ) ){ | 
|---|
| 62 | dest[i+1] = (*NextNeighborMean)[i+1]; | 
|---|
| 63 | (*NextNeighborMean)[i+2] = (src[i+1] - src[i+3] / 2.); | 
|---|
| 64 | i = i + 2;//do not care about the next sample it was the spike | 
|---|
| 65 | } | 
|---|
| 66 | // treatment for the end of the pipeline must be added !!! | 
|---|
| 67 | } | 
|---|
| 68 | } | 
|---|
| 69 | } // end of spike search and correction | 
|---|
| 70 | delete NextNeighborMean; | 
|---|
| 71 | return; | 
|---|
| 72 | } | 
|---|