ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
PeakDetection.h
Go to the documentation of this file.
1/**
2 * @file PeakDetection.h
3 * @brief Implements peak detection for time-series data using a sliding window approach.
4 *
5 * The `PeakDetection` class identifies peaks in a data stream by maintaining a moving
6 * average and standard deviation and comparing incoming values against a dynamic threshold.
7 *
8 * @date 22/12/2024
9 * @version 1.0
10 * @author Coela Can't
11 */
12
13#pragma once
14
15#include "../Math/Mathematics.h"
16
17/**
18 * @class PeakDetection
19 * @brief Detects peaks in time-series data using statistical methods.
20 *
21 * This class identifies peaks by calculating a moving average and standard deviation
22 * of the data and comparing each value against a dynamically adjusted threshold.
23 *
24 * @tparam sampleSize The size of the data window used for peak detection.
25 */
26template <size_t sampleSize>
28private:
29 uint8_t lag; ///< Number of data points to use for moving average and standard deviation.
30 float threshold; ///< Threshold for peak detection, expressed as a multiple of the standard deviation.
31 float influence; ///< Influence of detected peaks on subsequent calculations.
32 float filData[sampleSize]; ///< Filtered data array for influence adjustment.
33 float avg[sampleSize]; ///< Moving average of the data.
34 float std[sampleSize]; ///< Moving standard deviation of the data.
35
36 /**
37 * @brief Calculates the mean and standard deviation for a range of data.
38 *
39 * @param start The starting index of the range.
40 * @param length The number of elements in the range.
41 * @param data Pointer to the data array.
42 * @param avgRet Output parameter for the calculated mean.
43 * @param stdRet Output parameter for the calculated standard deviation.
44 */
45 void GetStdDev(uint8_t start, uint8_t length, float* data, float& avgRet, float& stdRet);
46
47public:
48 /**
49 * @brief Constructs a `PeakDetection` object with the specified parameters.
50 *
51 * @param lag The number of data points for the moving average and standard deviation (default: 12).
52 * @param threshold The threshold for detecting peaks, expressed as a multiple of the standard deviation (default: 0.75).
53 * @param influence The influence of detected peaks on subsequent calculations (default: 0.5).
54 */
55 PeakDetection(uint8_t lag = 12, float threshold = 0.75f, float influence = 0.5f);
56
57 /**
58 * @brief Processes the data and identifies peaks.
59 *
60 * @param data Pointer to the input data array.
61 * @param peaks Output array of boolean values indicating whether each point is a peak.
62 */
63 void Calculate(float* data, bool* peaks);
64};
65
66#include "PeakDetection.tpp" // Includes the implementation of the template class.
Detects peaks in time-series data using statistical methods.
uint8_t lag
Number of data points to use for moving average and standard deviation.
void GetStdDev(uint8_t start, uint8_t length, float *data, float &avgRet, float &stdRet)
Calculates the mean and standard deviation for a range of data.
void Calculate(float *data, bool *peaks)
Processes the data and identifies peaks.
float avg[sampleSize]
Moving average of the data.
float threshold
Threshold for peak detection, expressed as a multiple of the standard deviation.
float std[sampleSize]
Moving standard deviation of the data.
float influence
Influence of detected peaks on subsequent calculations.
float filData[sampleSize]
Filtered data array for influence adjustment.
PeakDetection(uint8_t lag=12, float threshold=0.75f, float influence=0.5f)
Constructs a PeakDetection object with the specified parameters.