EnergySpectrumAnalyer/src/DataCalcProcess/Poly2FindPeaks.h

54 lines
2.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef POLY2FINDPEAKS_H
#define POLY2FINDPEAKS_H
#include <algorithm>
#include <cmath>
#include <vector>
class Poly2FindPeaks {
public:
// 峰值结构体,存储峰值特征
typedef struct {
int index; // 峰值在数据中的索引
double position; // 峰值的精确位置(插值计算)
double height; // 峰值高度(相对于基线)
double amplitude; // 峰值的绝对幅度
double fwhm; // 半高宽Full Width at Half Maximum
} Peak;
// 滑动平均平滑(去噪预处理)
static std::vector<double> SmoothData(const std::vector<double>& data, int window_size);
// 计算基线(使用百分位法,假设大部分数据为基线)
static double calculateBaseline(const std::vector<double>& data, double percentile = 0.1);
// 检测峰值
static std::vector<Peak> findPeaks(
const std::vector<double>& data,
double height_threshold = 0.0, // 峰值高度阈值(相对于基线)
int min_distance = 3, // 峰之间的最小距离(索引)
int smooth_window = 3 // 平滑窗口大小
);
};
/*******************************************************************************
算法说明
核心功能:
1、对原始数据进行平滑去噪滑动平均
2、自动计算基线区分信号和背景
3、检测局部最大值作为峰值候选
4、过滤假峰通过高度阈值和最小峰间距
5、精确计算峰值特征位置、高度、半高宽
关键参数:
* heightThreshold峰值相对于基线的最小高度过滤小噪声峰
* minDistance两个峰值之间的最小距离避免同一峰被多次检测
* smoothWindow平滑窗口大小越大去噪效果越好但可能模糊窄峰
峰值特征:
* position峰值的精确位置通过抛物线插值优化
* height峰值相对于基线的高度
* amplitude峰值的绝对幅度
* fwhm半高宽反映峰的宽窄用于峰的进一步分类
*******************************************************************************/
#endif // POLY2FINDPEAKS_H