Chris@4
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@4
|
2
|
Chris@4
|
3 /*
|
Chris@4
|
4 Vamp feature extraction plugin for the BeatRoot beat tracker.
|
Chris@4
|
5
|
Chris@4
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@4
|
7 This file copyright 2011 Simon Dixon, Chris Cannam and QMUL.
|
Chris@4
|
8
|
Chris@4
|
9 This program is free software; you can redistribute it and/or
|
Chris@4
|
10 modify it under the terms of the GNU General Public License as
|
Chris@4
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@4
|
12 License, or (at your option) any later version. See the file
|
Chris@4
|
13 COPYING included with this distribution for more information.
|
Chris@4
|
14 */
|
Chris@4
|
15
|
Chris@4
|
16 #ifndef _BEATROOT_PEAKS_H_
|
Chris@4
|
17 #define _BEATROOT_PEAKS_H_
|
Chris@4
|
18
|
Chris@4
|
19 #include <vector>
|
Chris@4
|
20 #include <cmath>
|
Chris@4
|
21
|
Chris@4
|
22 using std::vector;
|
Chris@4
|
23
|
Chris@4
|
24 class Peaks
|
Chris@4
|
25 {
|
Chris@4
|
26 protected:
|
Chris@4
|
27 static int pre;
|
Chris@4
|
28 static int post;
|
Chris@4
|
29
|
Chris@4
|
30 public:
|
Chris@4
|
31 /** General peak picking method for finding n local maxima in an array
|
Chris@4
|
32 * @param data input data
|
Chris@4
|
33 * @param peaks list of peak indexes
|
Chris@4
|
34 * @param width minimum distance between peaks
|
Chris@4
|
35 */
|
Chris@15
|
36 static int findPeaks(const vector<double> &data, vector<int> peaks, int width);
|
Chris@4
|
37
|
Chris@4
|
38 /** General peak picking method for finding local maxima in an array
|
Chris@4
|
39 * @param data input data
|
Chris@4
|
40 * @param width minimum distance between peaks
|
Chris@4
|
41 * @param threshold minimum value of peaks
|
Chris@4
|
42 * @return list of peak indexes
|
Chris@4
|
43 */
|
Chris@4
|
44 static vector<int> findPeaks(const vector<double> &data, int width,
|
Chris@4
|
45 double threshold) {
|
Chris@4
|
46 return findPeaks(data, width, threshold, 0, false);
|
Chris@4
|
47 } // findPeaks()
|
Chris@4
|
48
|
Chris@4
|
49 /** General peak picking method for finding local maxima in an array
|
Chris@4
|
50 * @param data input data
|
Chris@4
|
51 * @param width minimum distance between peaks
|
Chris@4
|
52 * @param threshold minimum value of peaks
|
Chris@4
|
53 * @param decayRate how quickly previous peaks are forgotten
|
Chris@4
|
54 * @param isRelative minimum value of peaks is relative to local average
|
Chris@4
|
55 * @return list of peak indexes
|
Chris@4
|
56 */
|
Chris@4
|
57 static vector<int> findPeaks(const vector<double> &data, int width,
|
Chris@15
|
58 double threshold, double decayRate, bool isRelative);
|
Chris@4
|
59
|
Chris@4
|
60 static double expDecayWithHold(double av, double decayRate,
|
Chris@15
|
61 const vector<double> &data, int start, int stop);
|
Chris@4
|
62
|
Chris@4
|
63 static bool overThreshold(const vector<double> &data, int index, int width,
|
Chris@15
|
64 double threshold, bool isRelative,
|
Chris@15
|
65 double av);
|
Chris@4
|
66
|
Chris@15
|
67 static void normalise(vector<double> &data);
|
Chris@4
|
68
|
Chris@4
|
69 /** Uses an n-point linear regression to estimate the slope of data.
|
Chris@4
|
70 * @param data input data
|
Chris@4
|
71 * @param hop spacing of data points
|
Chris@4
|
72 * @param n length of linear regression
|
Chris@4
|
73 * @param slope output data
|
Chris@4
|
74 */
|
Chris@4
|
75 static void getSlope(const vector<double> &data, double hop, int n,
|
Chris@15
|
76 vector<double> &slope);
|
Chris@4
|
77
|
Chris@18
|
78 static double min(const vector<double> &arr) {
|
Chris@18
|
79 if (arr.empty()) return 0;
|
Chris@18
|
80 return arr[imin(arr)];
|
Chris@18
|
81 }
|
Chris@18
|
82 static double max(const vector<double> &arr) {
|
Chris@18
|
83 if (arr.empty()) return 0;
|
Chris@18
|
84 return arr[imax(arr)];
|
Chris@18
|
85 }
|
Chris@4
|
86
|
Chris@15
|
87 static int imin(const vector<double> &arr);
|
Chris@15
|
88 static int imax(const vector<double> &arr);
|
Chris@4
|
89
|
Chris@4
|
90 }; // class Peaks
|
Chris@4
|
91
|
Chris@4
|
92 #endif
|