-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsliwin_ut.cpp
More file actions
78 lines (69 loc) · 1.76 KB
/
sliwin_ut.cpp
File metadata and controls
78 lines (69 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "sliwin.hpp"
#include <iostream>
#include <random>
using namespace std;
class sliwin_peak_finder:public sliwin {
private:
bool _found;
float _peak;
public:
sliwin_peak_finder(size_t);
bool slide(float);
float peak(void);
};
sliwin_peak_finder::sliwin_peak_finder(size_t n):sliwin(n) {
_found = false;
}
bool sliwin_peak_finder::slide(float v) {
_found = false;
sliwin::slide(v);
if (size()>=3) {
v = operator[](1); // hope that [1] is the peak
if ((v>operator[](0) && v>=operator[](2)) || (v>=operator[](0) && v>operator[](2))) { // neighborhood peak found
for (size_t i=3; i<size(); i++) {
if (operator[](i) > v) {
return false;
}
}
_peak = v;
_found = true; // regional peak found
}
}
return _found;
}
float sliwin_peak_finder::peak(void) {
if (_found)
return _peak;
else
return 0.0f;
}
void test_sliwin_peak_finder() {
uniform_real_distribution<float> dis(0.0, 10.0);
minstd_rand gen;
sliwin_peak_finder sw(32);
for (int i=0; i<64; i++) {
bool found = sw.slide(dis(gen));
for (int j=0; j<sw.size(); j++) {
cout << sw[j] << ' ';
}
if (found) {
cout << "found " << sw.peak() << endl;
} else {
cout << endl;
}
}
}
void test_sliwin_stdd() {
sliwin_stdd sw(32);
for (int i=0; i<64; i++) {
sw.slide((float)i);
for (int j=0; j<sw.size(); j++) {
cout << sw[j] << ' ';
}
cout << "stdd " << sw.stdd() << endl;
}
}
int main() {
test_sliwin_stdd();
return 0;
}