#include <PeakDetection.h>
Public Types | |
enum | SortMethod { NONE = 0, BYMAGNITUDE = 1, BYPOSITION = 2 } |
Specifies the way to sort the peak candidates before returning them. More... | |
Public Member Functions | |
PeakDetection (int peakCount=1024/3, SortMethod sort=BYMAGNITUDE, int minimumPeakWidth=3, int candidateCount=-1, Real minimumPeakContrast=0) | |
~PeakDetection () | |
void | process (const MatrixXR &frames, MatrixXR *peakPositions, MatrixXR *peakMagnitudes) |
int | peakCount () const |
void | setPeakCount (int count, bool callSetup=true) |
int | minimumPeakWidth () const |
void | setMinimumPeakWidth (int width, bool callSetup=true) |
int | candidateCount () const |
void | setCandidateCount (int count, bool callSetup=true) |
Real | minimumPeakContrast () const |
void | setMinimumPeakContrast (Real contrast, bool callSetup=true) |
SortMethod | sortMethod () const |
void | setSortMethod (SortMethod method, bool callSetup=true) |
This class represents an object to find peaks in a vector of Real values. The algorithm finds a maximum number of peaks and returns the indices of the peaks and the values of the peaks in separate matrices.
The maximum number of peaks can be specified using setPeakCount().
The resulting peak arrays may be sorted by position or by magnitude. This can be specified using setSortMethod().
When sorting by position it may be interesting to specify a number of candidates, in order to perform a preselection of the highest valued peaks before sorting. This can be specified using setCandidateCount().
The implementation consists in running a sliding windows along the vector in search of indices which whose value is the maximum of the window. The size of the window defines the minimum width of the peak.
enum SortMethod |
PeakDetection | ( | int | peakCount = 1024 / 3 , |
|
SortMethod | sort = BYMAGNITUDE , |
|||
int | minimumPeakWidth = 3 , |
|||
int | candidateCount = -1 , |
|||
Real | minimumPeakContrast = 0 | |||
) |
Constructs a peak detection object with the given peakCount, sort method, minimumPeakWidth, candidateCount and minimumPeakContrast parameters given.
References setCandidateCount(), setMinimumPeakContrast(), setMinimumPeakWidth(), setPeakCount(), and setSortMethod().
~PeakDetection | ( | ) |
Destroys the algorithm and frees its resources.
void process | ( | const MatrixXR & | frames, | |
MatrixXR * | peakPositions, | |||
MatrixXR * | peakMagnitudes | |||
) |
Detects peaks on each of the rows of frames and puts the resulting peak indices and magnitudes in the rows of peakPositions and peakMagnitudes respectively.
frames | matrix of Real values. | |
peakPositions | pointer to a matrix of Real values (but always Integers) for the peak indices. The matrix should have the same number of rows as frames and peakCount columns. | |
peakMagnitudes | pointer to a matrix of Real values for the peak magnitudes. The matrix should have the same number of rows as frames and peakCount columns. |
Note that if the output matrices are not of the required size they will be resized, reallocating a new memory space if necessary.
References BYMAGNITUDE, BYPOSITION, candidateCount(), NONE, and peakCount().
Referenced by PitchACF::process().
int peakCount | ( | ) | const |
Returns the maximum number of peaks to be detected by the algorithm.
By default it is 1024 / 3.
Referenced by process().
void setPeakCount | ( | int | count, | |
bool | callSetup = true | |||
) |
Specifies the maximum peak count to be detected by the algorithm. If <= 0, then all possible peaks are detected.
Referenced by PeakDetection().
int minimumPeakWidth | ( | ) | const |
Returns the minimum width of a peak for it to be detected.
By default it is 3.
void setMinimumPeakWidth | ( | int | width, | |
bool | callSetup = true | |||
) |
Specifies the minimum width of a peak for it to be detected.
Referenced by PeakDetection().
int candidateCount | ( | ) | const |
Returns the number of highest value candidates to be considered before sorting.
Note that if the value is <= 0, then no preselection is performed and all detected peaks are considered as candidates.
By default it is -1.
Referenced by process().
void setCandidateCount | ( | int | count, | |
bool | callSetup = true | |||
) |
Specifies the number of highest value candidates to be considered before sorting.
Note that if the value is <= 0, then no preselection is performed and all detected peaks are considered as candidates.
Referenced by PeakDetection().
Real minimumPeakContrast | ( | ) | const |
Returns the minimum contrast of a peak for it to be detected.
The contrast is considered of a peak is the maximum value minus the minimum value of all the points in the peak detection running window.
By default it is 0.0.
void setMinimumPeakContrast | ( | Real | contrast, | |
bool | callSetup = true | |||
) |
Specifies the minimum contrast of a peak for it to be detected.
The contrast is considered of a peak is the maximum value minus the minimum value of all the points in the peak detection running window.
Referenced by PeakDetection().
PeakDetection::SortMethod sortMethod | ( | ) | const |
Returns the method for sorting the peaks.
By default it is BYMAGNITUDE.
void setSortMethod | ( | SortMethod | method, | |
bool | callSetup = true | |||
) |
Specifies the method for sorting the peaks.
Referenced by PeakDetection().