source: fact/tools/rootmacros/SpikeRemoval.C@ 14027

Last change on this file since 14027 was 13535, checked in by neise, 13 years ago
Makefile works
  • Property svn:executable set to *
File size: 2.0 KB
Line 
1#include "SpikeRemoval.h"
2
3#include <iostream>
4using namespace std;
5
6// compute the mean of the left and right neighbors of a channel
7vector<float> * computeN1mean( vector<float> &src)
8{
9 vector<float> * dest = new vector<float>;
10
11 dest->push_back(src[1]);
12
13 for(unsigned int i = 1; i < src.size() - 1; i++){
14/* 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 }
23*/
24 dest->push_back( ( src[i-1] + src[i+1] ) / 2. );
25 }
26
27 dest->push_back(src[src.size() - 1]);
28 return dest;
29} // end of computeN1mean computation
30
31void removeSpikes(
32 vector<float> &src,
33 vector<float> &dest,
34 const float CandidateTHR,
35 const float nextDiffTHR,
36 const float nextNextDiffTHR
37){
38 vector<float> * NextNeighborMean = computeN1mean(src);
39
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;
44
45 float diff, nextDiff, nextNextDiff;
46
47// find the spike and replace it by mean value of neighbors
48 for (unsigned int i = 0; i < src.size(); i++) {
49
50 diff = src[i] - (*NextNeighborMean)[i];
51
52 if ( diff < CandidateTHR ){ // a spike candidate
53 // check consistency with a single channel spike
54
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];
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;
77}
Note: See TracBrowser for help on using the repository browser.