| Line | |
|---|
| 1 | #include <vector>
|
|---|
| 2 |
|
|---|
| 3 | // searches for zero crossings in a given vector of floats
|
|---|
| 4 | // for zero crossings in falling edge
|
|---|
| 5 | // give edge = -1
|
|---|
| 6 | //
|
|---|
| 7 | //
|
|---|
| 8 | // returns pointer to vetctor of ints
|
|---|
| 9 |
|
|---|
| 10 | vector<int> *zerosearch(vector<float> &input, int edge =-1 , int pre=10, int post=30 ){
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 | vector<int> * zeroPositions = new vector<int>;
|
|---|
| 14 |
|
|---|
| 15 | for (int sl =pre ; sl < input.size()-post; sl++){
|
|---|
| 16 | //cout << "sl:" << sl << endl;
|
|---|
| 17 | if (input[sl] * input[sl-1] < 0 || input[sl]==0.0 ){ // sign change --> zero crossing OR really zero
|
|---|
| 18 |
|
|---|
| 19 | if ( (input[sl-1] - input[sl]) * edge < 0){ // this is the crossing the user wanted
|
|---|
| 20 |
|
|---|
| 21 | // check if we go lower than a certain limit in the next few slices
|
|---|
| 22 | for ( int lala=0; lala<post; lala++){
|
|---|
| 23 | if (input[sl+lala] < -1.5) {
|
|---|
| 24 | zeroPositions->push_back(sl);
|
|---|
| 25 | sl += lala;
|
|---|
| 26 | break;
|
|---|
| 27 | }
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | } else if ( (input[sl-1] - input[sl]) * edge > 0){ // this is the zero x-ing the user did not want
|
|---|
| 31 |
|
|---|
| 32 | // do nothing
|
|---|
| 33 |
|
|---|
| 34 | } else { // sl and sl-1 are equal .. don't know waht do to...
|
|---|
| 35 |
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | } // end of loop over slices - between pre and post
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 | return zeroPositions;
|
|---|
| 44 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.