qm-dsp 1.8
PeakPicking.cpp
Go to the documentation of this file.
1/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3/*
4 QM DSP Library
5
6 Centre for Digital Music, Queen Mary, University of London.
7 This file 2005-2006 Christian Landone.
8
9 Modifications:
10
11 - delta threshold
12 Description: add delta threshold used as offset in the smoothed
13 detection function
14 Author: Mathieu Barthet
15 Date: June 2010
16
17 This program is free software; you can redistribute it and/or
18 modify it under the terms of the GNU General Public License as
19 published by the Free Software Foundation; either version 2 of the
20 License, or (at your option) any later version. See the file
21 COPYING included with this distribution for more information.
22*/
23
24#include "PeakPicking.h"
25#include "maths/Polyfit.h"
26
27#include <iostream>
28#include <cstring>
29
30
32// Construction/Destruction
34
36{
38 initialise( Config );
39}
40
45
47{
48 m_DFLength = Config.length ;
49 Qfilta = Config.QuadThresh.a ;
50 Qfiltb = Config.QuadThresh.b ;
51 Qfiltc = Config.QuadThresh.c ;
52
61 m_DFProcessingParams.delta = Config.delta; //add the delta threshold as an adjustable parameter
62
64
65 m_workBuffer = new double[ m_DFLength ];
66 memset( m_workBuffer, 0, sizeof(double)*m_DFLength);
67}
68
70{
71 delete [] m_workBuffer;
72 delete m_DFSmoothing;
74}
75
76void PeakPicking::process( double* src, unsigned int len, vector<int> &onsets )
77{
78 if (len < 4) return;
79
80 vector <double> m_maxima;
81
82 // Signal conditioning
84
85 for( unsigned int u = 0; u < len; u++)
86 {
87 m_maxima.push_back( m_workBuffer[ u ] );
88 }
89
90 quadEval( m_maxima, onsets );
91
92 for( int b = 0; b < (int)m_maxima.size(); b++)
93 {
94 src[ b ] = m_maxima[ b ];
95 }
96}
97
98int PeakPicking::quadEval( vector<double> &src, vector<int> &idx )
99{
100 unsigned int maxLength;
101
102 vector <int> m_maxIndex;
103 vector <int> m_onsetPosition;
104
105 vector <double> m_maxFit;
106 vector <double> m_poly;
107 vector <double> m_err;
108
109 m_poly.push_back(0);
110 m_poly.push_back(0);
111 m_poly.push_back(0);
112
113 for( int t = -2; t < 3; t++)
114 {
115 m_err.push_back( (double)t );
116 }
117 for( unsigned int i = 2; i < src.size() - 2; i++)
118 {
119 if( (src[i] > src[i-1]) && (src[i] > src[i+1]) && (src[i] > 0) )
120 {
121// m_maxIndex.push_back( i + 1 );
122 m_maxIndex.push_back(i);
123 }
124 }
125
126 maxLength = m_maxIndex.size();
127
128 double selMax = 0;
129
130 for( unsigned int j = 0; j < maxLength ; j++)
131 {
132 for (int k = -2; k <= 2; ++k)
133 {
134 selMax = src[ m_maxIndex[j] + k ] ;
135 m_maxFit.push_back(selMax);
136 }
137
138 TPolyFit::PolyFit2(m_err, m_maxFit, m_poly);
139
140 double f = m_poly[0];
141 double h = m_poly[2];
142
143 if (h < -Qfilta || f > Qfiltc)
144 {
145 idx.push_back(m_maxIndex[j]);
146 }
147
148 m_maxFit.clear();
149 }
150
151 return 1;
152}
#define NULL
Definition Filter.h:20
void process(double *src, double *dst)
Definition DFProcess.cpp:87
int quadEval(vector< double > &src, vector< int > &idx)
DFProcConfig m_DFProcessingParams
unsigned int m_DFLength
virtual ~PeakPicking()
double Qfiltb
double * m_workBuffer
PeakPicking(PPickParams Config)
void initialise(PPickParams Config)
void process(double *src, unsigned int len, vector< int > &onsets)
double Qfiltc
DFProcess * m_DFSmoothing
double Qfilta
void deInitialise()
static double PolyFit2(const vector< double > &x, const vector< double > &y, vector< double > &coef)
Definition Polyfit.h:102
unsigned int length
Definition DFProcess.h:31
double * LPBCoeffs
Definition DFProcess.h:34
unsigned int winPost
Definition DFProcess.h:36
double * LPACoeffs
Definition DFProcess.h:33
float delta
Definition DFProcess.h:39
unsigned int LPOrd
Definition DFProcess.h:32
bool isMedianPositive
Definition DFProcess.h:38
unsigned int winPre
Definition DFProcess.h:35
double AlphaNormParam
Definition DFProcess.h:37
unsigned int pre
Definition PeakPicking.h:38
unsigned int post
Definition PeakPicking.h:39
double * LPACoeffs
Definition PeakPicking.h:69
double * LPBCoeffs
Definition PeakPicking.h:70
QFitThresh QuadThresh
Definition PeakPicking.h:72
unsigned int alpha
Definition PeakPicking.h:66
unsigned int LPOrd
Definition PeakPicking.h:68
unsigned int length
Definition PeakPicking.h:64
PPWinThresh WinT
Definition PeakPicking.h:71