Ignore:
Timestamp:
01/31/13 09:02:26 (12 years ago)
Author:
Jens Buss
Message:
whitespace + comments
File:
1 edited

Legend:

Unmodified
Added
Removed
  • fact/tools/rootmacros/SpikeRemoval.C

    r13535 r14800  
    77vector<float> * computeN1mean( vector<float> &src)
    88{
    9         vector<float> * dest = new vector<float>;
     9    vector<float> * dest = new vector<float>;
    1010
    11         dest->push_back(src[1]);
     11    dest->push_back(src[1]);
    1212
    13         for(unsigned int i = 1; i < src.size() - 1; i++){
     13    for(unsigned int i = 1; i < src.size() - 1; i++){
    1414/*        if (i == 0){ // use right sample es mean
    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                 }
     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        }
    2323*/
    24                 dest->push_back( ( src[i-1] + src[i+1] ) / 2. );
    25         }
     24        dest->push_back( ( src[i-1] + src[i+1] ) / 2. );
     25    }
    2626
    27         dest->push_back(src[src.size() - 1]);
    28         return dest;
     27    dest->push_back(src[src.size() - 1]);
     28    return dest;
    2929} // end of computeN1mean computation
    3030
    3131void removeSpikes(
    32         vector<float> &src,
    33         vector<float> &dest,
    34         const float CandidateTHR,
    35         const float nextDiffTHR,
    36         const float nextNextDiffTHR
     32    vector<float> &src,
     33    vector<float> &dest,
     34    const float CandidateTHR,
     35    const float nextDiffTHR,
     36    const float nextNextDiffTHR
    3737){
    38         vector<float> * NextNeighborMean = computeN1mean(src);
     38    //vector with Mean values of both neighbor samples of a sample
     39    vector<float> * NextNeighborMean = computeN1mean(src);
    3940
    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;
    4447
    45         float diff, nextDiff, nextNextDiff;
     48    float diff, nextDiff, nextNextDiff;
    4649
    4750// find the spike and replace it by mean value of neighbors
    48         for (unsigned int i = 0; i < src.size(); i++) {
     51    for (unsigned int i = 0; i < src.size(); i++) {
    4952
    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];
    5155
    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
    5459
    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.;
    6565
    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;
    7788}
Note: See TracChangeset for help on using the changeset viewer.