To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / Peaks.h @ 18:55969570044e

History | View | Annotate | Download (3.03 KB)

1
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2

    
3
/*
4
  Vamp feature extraction plugin for the BeatRoot beat tracker.
5

6
  Centre for Digital Music, Queen Mary, University of London.
7
  This file copyright 2011 Simon Dixon, Chris Cannam and QMUL.
8
    
9
  This program is free software; you can redistribute it and/or
10
  modify it under the terms of the GNU General Public License as
11
  published by the Free Software Foundation; either version 2 of the
12
  License, or (at your option) any later version.  See the file
13
  COPYING included with this distribution for more information.
14
*/
15

    
16
#ifndef _BEATROOT_PEAKS_H_
17
#define _BEATROOT_PEAKS_H_
18

    
19
#include <vector>
20
#include <cmath>
21

    
22
using std::vector;
23

    
24
class Peaks
25
{
26
protected:
27
    static int pre;
28
    static int post;
29
        
30
public:
31
    /** General peak picking method for finding n local maxima in an array
32
     *  @param data input data
33
     *  @param peaks list of peak indexes
34
     *  @param width minimum distance between peaks
35
     */
36
    static int findPeaks(const vector<double> &data, vector<int> peaks, int width);
37

    
38
    /** General peak picking method for finding local maxima in an array
39
     *  @param data input data
40
     *  @param width minimum distance between peaks
41
     *  @param threshold minimum value of peaks
42
     *  @return list of peak indexes
43
     */ 
44
    static vector<int> findPeaks(const vector<double> &data, int width,
45
                                 double threshold) {
46
        return findPeaks(data, width, threshold, 0, false);
47
    } // findPeaks()
48
        
49
    /** General peak picking method for finding local maxima in an array
50
     *  @param data input data
51
     *  @param width minimum distance between peaks
52
     *  @param threshold minimum value of peaks
53
     *  @param decayRate how quickly previous peaks are forgotten
54
     *  @param isRelative minimum value of peaks is relative to local average
55
     *  @return list of peak indexes
56
     */
57
    static vector<int> findPeaks(const vector<double> &data, int width,
58
                                 double threshold, double decayRate, bool isRelative);
59

    
60
    static double expDecayWithHold(double av, double decayRate,
61
                                   const vector<double> &data, int start, int stop);
62

    
63
    static bool overThreshold(const vector<double> &data, int index, int width,
64
                              double threshold, bool isRelative,
65
                              double av);
66

    
67
    static void normalise(vector<double> &data);
68

    
69
    /** Uses an n-point linear regression to estimate the slope of data.
70
     *  @param data input data
71
     *  @param hop spacing of data points
72
     *  @param n length of linear regression
73
     *  @param slope output data
74
     */
75
    static void getSlope(const vector<double> &data, double hop, int n,
76
                         vector<double> &slope);
77

    
78
    static double min(const vector<double> &arr) {
79
        if (arr.empty()) return 0;
80
        return arr[imin(arr)];
81
    }
82
    static double max(const vector<double> &arr) {
83
        if (arr.empty()) return 0;
84
        return arr[imax(arr)];
85
    }
86

    
87
    static int imin(const vector<double> &arr);
88
    static int imax(const vector<double> &arr);
89

    
90
}; // class Peaks
91

    
92
#endif