2026-06-15 16:49:21 +08:00
|
|
|
#ifndef __ALGORITHM_H
|
|
|
|
|
#define __ALGORITHM_H
|
|
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
#define CRC16_BASE 0xA001
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 峰值谷值检查结果结构体
|
|
|
|
|
typedef struct {
|
|
|
|
|
bool peaks_positive; // 所有峰值是否大于0
|
|
|
|
|
bool valleys_negative; // 所有谷值是否小于0
|
|
|
|
|
int peak_count; // 检测到的峰值数量
|
|
|
|
|
int valley_count; // 检测到的谷值数量
|
|
|
|
|
} PeakValleyCheck;
|
|
|
|
|
|
|
|
|
|
// 趋势分析结果结构体
|
|
|
|
|
typedef struct {
|
|
|
|
|
double slope; // 线性斜率
|
|
|
|
|
int sign_changes; // 符号变化次数
|
|
|
|
|
char trend_type; // 趋势类型
|
|
|
|
|
char steepness; // 陡峭度
|
|
|
|
|
} TrendResult;
|
|
|
|
|
|
|
|
|
|
PeakValleyCheck check_peaks_valleys(int data[], int length);
|
|
|
|
|
TrendResult analyze_trend(int data[], int length);
|
|
|
|
|
float calculateAverage(int *arr, int size);
|
|
|
|
|
double slope(int32_t *x_data, int32_t *y_data, int n) ;
|
|
|
|
|
long long power(int base, unsigned int exponent);
|
|
|
|
|
int IntFilter_16t(int16_t *Data, uint8_t Cnt, uint8_t FilterCnt);
|
|
|
|
|
int IntFilter_32t(int32_t *Data, uint8_t Cnt, uint8_t FilterCnt);
|
|
|
|
|
uint32_t IntFilter_u32t(uint32_t *Data, uint8_t Cnt, uint8_t FilterCnt);
|
|
|
|
|
float IntFilter_Float(float *Data, uint8_t Cnt, uint8_t FilterCnt);
|
|
|
|
|
uint32_t AverageFilter_u32t(uint32_t *Data, uint8_t Cnt);
|
|
|
|
|
int AverageFilter_32t(int32_t *Data, uint8_t Cnt);
|
|
|
|
|
void Fitting_Polynomial(double *AD, double *Actual, uint8_t Cnt);
|
|
|
|
|
float get_K(uint8_t count , int32_t *dataCol_X, int32_t *dataRow_Y);
|
|
|
|
|
int8_t TrendAnalyse(int32_t *Data, uint8_t Cnt, int32_t VPT);
|
|
|
|
|
void Waveform_Up(int32_t *Data, uint8_t dCnt, uint8_t pCnt, int32_t *vlue);
|
|
|
|
|
void Waveform_Down(int32_t *Data, uint8_t dCnt, uint8_t pCnt, int32_t *vlue);
|
|
|
|
|
bool count_most_greater(int32_t *arr, uint8_t size, int32_t target);
|
|
|
|
|
bool count_greater(int32_t *arr, uint8_t size, int32_t target);
|
|
|
|
|
bool count_smaller(int32_t *arr, uint8_t size, int32_t target);
|
|
|
|
|
uint16_t CRC_Modbus(uint16_t wBase, uint8_t *para, uint16_t length);
|
|
|
|
|
uint8_t CRC_Sum(uint8_t *_pbuff, uint16_t _cmdLen);
|
|
|
|
|
bool isAllZero(uint8_t *arr, int size);
|
|
|
|
|
int fixWithMedianIterative(int arr[], int size, int windowSize, int threshold, int maxIterations, int verbose);
|
|
|
|
|
int finalCheck(int arr[], int size, int threshold, int verbose);
|
2026-07-09 18:52:49 +08:00
|
|
|
int weightedMovingAverageWithEnhance(int32_t arr[], int size, int windowSize,int enhanceStart, int enhanceEnd, double enhanceFactor, int verbose);
|
|
|
|
|
int CompareAndCountAbs(const int32_t *arr1, const int32_t *arr2, uint16_t length,int32_t zero1, int32_t zero2, int32_t offset);
|
2026-06-15 16:49:21 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|