-
Notifications
You must be signed in to change notification settings - Fork 1
/
thresholdingdemo.h
62 lines (58 loc) · 2.24 KB
/
thresholdingdemo.h
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
//=============================================================================
/**
* Author: Jason Cipriani
* Website: https://github.com/JC3/ZScorePeakDetection
* License: https://github.com/JC3/ZScorePeakDetection/blob/master/LICENSE
*
* This is an implementation of the Robust Peak Detection Algorithm Using
* Z-Scores (Brackel, J.P.G. van) from https://stackoverflow.com/a/22640362
* with some experimental modifications by me:
*
* - Option to process data set in reverse.
* - Absolute minimum level of a peak.
*/
//=============================================================================
#ifndef THRESHOLDINGDEMO_H
#define THRESHOLDINGDEMO_H
#include <QObject>
#include <QVector>
class ThresholdingDemo : public QObject {
Q_OBJECT
public:
struct Params {
int lag;
float threshold;
float influence;
// extra experimental options
bool reverse;
float minlevel;
Params () : lag(30), threshold(5), influence(0), reverse(false), minlevel(0) { }
};
struct Output {
QVector<float> input;
Params params;
QVector<float> mean;
QVector<float> stddev;
QVector<int> signal;
int outfrom, outto; // mean,stddev,signal valid indices, INCLUSIVE
void clear () { input.clear(); mean.clear(); stddev.clear(); signal.clear(); outfrom = 0; outto = -1; }
};
explicit ThresholdingDemo (QObject *parent = nullptr);
Params params () const { return params_; }
int size () const { return input_.size(); }
public slots:
void setInput (QVector<float> input) { input_ = input; update(); }
void setLag (int lag) { params_.lag = lag; update(); }
void setThreshold (double threshold) { params_.threshold = threshold; update(); }
void setInfluence (double influence) { params_.influence = influence; update(); }
void setReverse (bool reverse) { params_.reverse = reverse; update(); }
void setMinLevel (double minlevel) { params_.minlevel = minlevel; update(); }
signals:
void outputChanged (ThresholdingDemo::Output output);
private:
QVector<float> input_;
Params params_;
void update ();
static void threshold (const Params ¶ms, Output &output, QVector<float> input);
};
#endif // THRESHOLDINGDEMO_H