diff --git a/git.bat b/git.bat new file mode 100644 index 0000000..4db359b --- /dev/null +++ b/git.bat @@ -0,0 +1,33 @@ +@echo off +chcp 65001 >nul +echo ======================================== +echo Git 上传脚本 - Rader_Success_5 +echo ======================================== +echo. + +set GIT_PATH="C:\Program Files\Git\bin\git.exe" +set REMOTE_URL=http://lmhrt.cn:6771/ming/Rader_IQ + +echo [1/5] 检查 Git 状态... +%GIT_PATH% status +echo. + +echo [2/5] 添加所有文件到暂存区... +%GIT_PATH% add -A +echo. + +echo [3/5] 提交更改... +set /p commit_msg="请输入提交信息 (默认: Update project): " +if "%commit_msg%"=="" set commit_msg=Update project +%GIT_PATH% commit -m "%commit_msg%" +echo. + +echo [4/5] 推送到远程仓库... +%GIT_PATH% push +echo. + +echo ======================================== +echo 上传完成! +echo ======================================== +echo. +pause diff --git a/src/main.cpp b/src/main.cpp index c7af429..42560f4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,59 +6,42 @@ #include "radar_vitals.h" #include "io_flash.h" +static float I_buf[BASE_DATA_LEN]; +static float Q_buf[BASE_DATA_LEN]; - -// 全局变量声明 - -/** - * @brief 雷达数据采集任务 - * 定期读取ADC数据并调用radar_vitals_process()处理数据 - * @param parameter 任务参数(未使用) - */ void radarDataTask(void *parameter) { Serial.println("📡 雷达数据采集任务启动"); radar_sample_t sample; radar_vitals_t vitals; - float I_buf[DATA_LEN]; - float Q_buf[DATA_LEN]; while(1) { - // 采集DATA_LEN个样本 - for(int i=0; i= input_len) idx = input_len - 1; + output[i] = input[idx]; + } +} + @@ -32,19 +52,21 @@ static int history_index = 0; /******** 新的雷达处理函数 ********/ void radar_process(float *I, float *Q, int len) { + if(len > BASE_DATA_LEN) len = BASE_DATA_LEN; + /* 1. 去直流 (DC Removal) * I'(n) = I(n) - mean(I) * Q'(n) = Q(n) - mean(Q) */ float meanI = 0, meanQ = 0; - for(int i=0;i π → Δφ -= 2π */ unwrap_phase[0] = phase[0]; - for(int i=1;i M_PI) d -= 2*M_PI; if(d < -M_PI) d += 2*M_PI; @@ -63,15 +85,15 @@ void radar_process(float *I, float *Q, int len) * Var(φ) = E[(φ-μ)^2] */ float mean = 0, var = 0; - for(int i=0;i 0.05){ + if(energy > 0.05) { human_state = MOTION; } else { human_state = STATIC_HUMAN; } - /* 6. 呼吸 / 心率频率估计 - * 方法:频段能量最大值搜索(简化 DFT) - * Fs_eff = SAMPLE_RATE / decimation - */ - const float Fs_eff = 200.0f; // 4kHz / 20 + /* 6. 降采样处理 */ + downsample(unwrap_phase, resp_phase, len, RESP_DATA_LEN); + downsample(unwrap_phase, hr_phase, len, HR_DATA_LEN); - // ---- 呼吸:0.1 ~ 0.5 Hz ---- - float max_resp_mag = 0; float resp_freq = 0; - for(float f=0.1f; f<=0.5f; f+=0.02f){ - float re=0, im=0; - for(int n=0;n max_resp_mag) { + max_resp_mag = mag; + resp_freq = f; } - float mag = re*re + im*im; - if(mag > max_resp_mag){ max_resp_mag = mag; resp_freq = f; } } float new_resp_bpm = resp_freq * 60.0f; - // ---- 心率:0.8 ~ 2.5 Hz ---- - float max_hr_mag = 0; float hr_freq = 0; - for(float f=0.8f; f<=2.5f; f+=0.05f){ - float re=0, im=0; - for(int n=0;n max_hr_mag) { + max_hr_mag = mag; + hr_freq = f; } - float mag = re*re + im*im; - if(mag > max_hr_mag){ max_hr_mag = mag; hr_freq = f; } } float new_heart_bpm = hr_freq * 60.0f; // 异常值检测和过滤 - if(new_heart_bpm < 40 || new_heart_bpm > 180){ - new_heart_bpm = heart_bpm; // 使用上次值 + if(new_heart_bpm < 40 || new_heart_bpm > 180) { + new_heart_bpm = heart_bpm; } - if(new_resp_bpm < 4 || new_resp_bpm > 40){ - new_resp_bpm = resp_bpm; // 使用上次值 + if(new_resp_bpm < 4 || new_resp_bpm > 40) { + new_resp_bpm = resp_bpm; } // 移动平均滤波 heart_bpm_history[history_index] = new_heart_bpm; resp_bpm_history[history_index] = new_resp_bpm; - history_index = (history_index + 1) % 10; + history_index = (history_index + 1) % 5; - // 计算平均值 float sum_hr = 0, sum_resp = 0; - for(int i=0; i<10; i++){ + for(int i = 0; i < 5; i++) { sum_hr += heart_bpm_history[i]; sum_resp += resp_bpm_history[i]; } - heart_bpm = sum_hr / 10.0f; - resp_bpm = sum_resp / 10.0f; + heart_bpm = sum_hr / 5.0f; + resp_bpm = sum_resp / 5.0f; // 四舍五入到最接近的整数 heart_bpm = roundf(heart_bpm); @@ -166,13 +193,12 @@ float radar_get_heart_bpm(){ return heart_bpm; } /******** 初始化 ********/ void radar_vitals_init(float fs_hz) { - fs = fs_hz; + fs = BASE_SAMPLE_RATE; human_state = NO_PERSON; resp_bpm = 0; heart_bpm = 0; - // 初始化历史数据数组 - for(int i=0; i<10; i++){ + for(int i = 0; i < 5; i++) { resp_bpm_history[i] = 0; heart_bpm_history[i] = 0; } @@ -184,17 +210,15 @@ void radar_vitals_init(float fs_hz) * 初始化雷达相关的ADC和引脚 */ void radar_init() { - // 配置雷达I/Q引脚为ADC输入 pinMode(PIN_I, INPUT); pinMode(PIN_Q, INPUT); - // 初始化ADC adc1_config_width(ADC_WIDTH_BIT_12); - adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_DB_12); // PIN_I (GPIO1) 对应 ADC1_CHANNEL_0 - adc1_config_channel_atten(ADC1_CHANNEL_1, ADC_ATTEN_DB_12); // PIN_Q (GPIO2) 对应 ADC1_CHANNEL_1 + adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_DB_12); + adc1_config_channel_atten(ADC1_CHANNEL_1, ADC_ATTEN_DB_12); Serial.println("🏗️ 初始化雷达管理器..."); - radar_vitals_init(SAMPLE_RATE); + radar_vitals_init(BASE_SAMPLE_RATE); } diff --git a/src/radar_vitals.h b/src/radar_vitals.h index b780996..fb2b386 100644 --- a/src/radar_vitals.h +++ b/src/radar_vitals.h @@ -11,8 +11,14 @@ -#define SAMPLE_RATE 4000 // 基础采样率(Hz) -#define DATA_LEN 256 // 数据长度 +#define BASE_SAMPLE_RATE 200 // 基础采样率(Hz) +#define BASE_DATA_LEN 1024 // 基础数据长度 (5.12秒) + +#define RESP_SAMPLE_RATE 10 // 呼吸处理采样率(Hz) - 2倍呼吸频率上限 +#define HR_SAMPLE_RATE 50 // 心率处理采样率(Hz) - 2倍心率频率上限 + +#define RESP_DATA_LEN 51 // 呼吸处理数据长度 (5.1秒) +#define HR_DATA_LEN 256 // 心率处理数据长度 (5.12秒) // 人体状态枚举 typedef enum {