#ifndef _SIGNAL_PROCESSOR_H_ #define _SIGNAL_PROCESSOR_H_ #include "headfile.h" #include #include #include // 滤波类型 enum class filtertype { lowpass,highpass,notchpass,bandpass,bandstop }; // 特征数据结构 struct ECGChannelFeatures { std::vector r_peaks; // R波位置 float sdnn = 0.0f; // RR间期标准差 float rmssd = 0.0f; // RR间期差值的均方根 }; struct FeatureSet { std::vector ecg_features; // 其他设备的特征结构... }; // 生理指标数据结构 struct ECGIndicators { float heart_rate = 0.0f; // 心率 (bpm) float sdnn = 0.0f; // 心率变异性指标 float rmssd = 0.0f; // 心率变异性指标 float st_elevation = 0.0f; // ST段抬高 (mV) float st_depression = 0.0f; // ST段压低 (mV) }; struct PPGIndicators { float spo2 = 0.0f; // 血氧饱和度 float pi = 0.0f; // 灌注指数 float pulse_rate = 0.0f; // 脉率 }; struct EEGIndicators { float alpha_power = 0.0f; // Alpha波功率 float beta_power = 0.0f; // Beta波功率 float attention = 0.0f; // 注意力指数 }; struct IndicatorSet { float sqi = 0.0f; // 信号质量指数 (0.0-1.0) std::vector ecg_indicators; std::vector ppg_indicators; std::vector eeg_indicators; }; // 滤波器配置 struct FilterConfig { std::string type; double cutoff_frequency = 0.0; double Q_factor = 0.0; double low_cutoff = 0.0; double high_cutoff = 0.0; }; class SignalProcessor { public: // 预处理信号 SensorData preprocess_signals(const SensorData& raw_data); // 使用DataType枚举 SensorData preprocess_generic(const SensorData& data); // 特征提取 FeatureSet extract_signal_features(const SensorData& processed_data, const std::vector& features = {}); // 计算生理指标 IndicatorSet compute_physiological_indicators(const FeatureSet& features, const std::vector& indicators = {}); // 获取处理流水线配置 std::string getProcessingPipeline(DataType device_type); // 使用DataType枚举 // 设置滤波器参数 void setFilterParams(const std::string& filter_type, const FilterConfig& params); // 修改为public访问权限 public: SensorData preprocess_ecg_12lead(const SensorData& data); SensorData preprocess_eeg(const SensorData& data); SensorData preprocess_ecg_2lead(const SensorData& data); SensorData preprocess_ppg(const SensorData& data); SensorData preprocess_respiration(const SensorData& data); SensorData preprocess_snore(const SensorData& data); SensorData preprocess_stethoscope(const SensorData& data); // 设备特定的特征提取 FeatureSet extract_eeg_features(const SensorData& data); FeatureSet extract_ecg_features(const SensorData& data); FeatureSet extract_ppg_features(const SensorData& data); FeatureSet extract_respiration_features(const SensorData& data); FeatureSet extract_snore_features(const SensorData& data); FeatureSet extract_stethoscope_features(const SensorData& data); // 滤波器配置 std::map filter_configs_; // 滤波器状态 struct FilterState { std::vector x_history; std::vector y_history; }; std::map filter_states_; // 在SignalProcessor类中添加 public: // 带通滤波器实现 std::vector bandpass_filter(const std::vector& input, double sample_rate, double low_cutoff, double high_cutoff); std::vector Lowpass_filter(const std::vector& input, double sample_rate, double low_cutoff) ; std::vector filter(const std::vector& input, double sample_rate, double low_cutoff, double high_cutoff, filtertype type); std::vector Highpass_filter(const std::vector& input, double sample_rate, double high_cutoff); std::vector compensate_motion_artifact(const std::vector& ppg, const std::vector& motion); std::vector compensate_eog_artifact(const std::vector& eeg, const std::vector& eog1, const std::vector& eog2) ; // 添加自适应陷波滤波器声明 std::vector adaptive_notch_filter(const std::vector& input, double sample_rate, double target_freq, double bandwidth) ; std::vector bandstop_filter(const std::vector& input, double sample_rate, double low_cutoff, double high_cutoff); void normalize_amplitude(std::vector& signal) ; // 添加通用预处理辅助函数 std::vector remove_dc_offset(const std::vector& signal); std::vector apply_gain(const std::vector& signal, float gain); float calculate_correlation(const std::vector& x, const std::vector& y); float calculate_snr(const std::vector& signal); float calculate_PPG_sqi(const std::vector& red_channel, const std::vector& ir_channel); float calculate_ecg_sqi(const std::vector& signal, double sample_rate); }; #endif