diff --git a/.vscode/settings.json b/.vscode/settings.json
index 0b1f618..30b0640 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -111,7 +111,9 @@
"compiler_abstraction.h": "c",
"ble_nus_c.h": "c",
"device_version_info_mgr.h": "c",
- "heart_wave_sample_service_cfg.h": "c"
+ "heart_wave_sample_service_cfg.h": "c",
+ "filter.h": "c",
+ "filters.h": "c"
},
"files.encoding": "gbk"
}
\ No newline at end of file
diff --git a/README.md b/README.md
index 3183424..8b50563 100644
--- a/README.md
+++ b/README.md
@@ -58,13 +58,17 @@ TODO2:
7. 采集中导联脱落蜂鸣器响 OK
8. 采集中导联脱落事件上报 OK
- 2. 采集上报测试 (OK1/2)
- 3. 未采集,蓝牙断开,自动休眠测试
+ 2. 采集上报测试 (OK1/2)OK
+ 3. 未采集,蓝牙断开,自动休眠测试 2)OK
3. 蓝牙连接,5分钟没有收到任何消息,自动休眠
4. 电池电量检测测试
5. 记录读取测试
+ 6. 导联掉落测试 OK
+BUG:
+ 实时上报,第三个通道数据即便上报数据为0,也会突然出现一个突变数据。暂时未发现原因
+
```
diff --git a/app/app.uvoptx b/app/app.uvoptx
index cef9d60..b58c57b 100644
--- a/app/app.uvoptx
+++ b/app/app.uvoptx
@@ -563,6 +563,18 @@
0
0
+
+ 1
+ 16
+ 1
+ 0
+ 0
+ 0
+ .\src\basic\filters.c
+ filters.c
+ 0
+ 0
+
@@ -573,7 +585,7 @@
0
2
- 16
+ 17
1
0
0
@@ -593,7 +605,7 @@
0
3
- 17
+ 18
1
0
0
@@ -605,7 +617,7 @@
3
- 18
+ 19
1
0
0
@@ -625,7 +637,7 @@
0
4
- 19
+ 20
1
0
0
@@ -645,7 +657,7 @@
0
5
- 20
+ 21
1
0
0
@@ -657,7 +669,7 @@
5
- 21
+ 22
1
0
0
@@ -669,7 +681,7 @@
5
- 22
+ 23
1
0
0
@@ -681,7 +693,7 @@
5
- 23
+ 24
1
0
0
@@ -693,7 +705,7 @@
5
- 24
+ 25
1
0
0
@@ -705,7 +717,7 @@
5
- 25
+ 26
1
0
0
@@ -717,7 +729,7 @@
5
- 26
+ 27
1
0
0
@@ -729,7 +741,7 @@
5
- 27
+ 28
1
0
0
@@ -749,7 +761,7 @@
0
6
- 28
+ 29
1
0
0
@@ -769,7 +781,7 @@
0
7
- 29
+ 30
1
0
0
@@ -781,7 +793,7 @@
7
- 30
+ 31
1
0
0
@@ -793,7 +805,7 @@
7
- 31
+ 32
1
0
0
@@ -805,7 +817,7 @@
7
- 32
+ 33
1
0
0
@@ -817,7 +829,7 @@
7
- 33
+ 34
1
0
0
@@ -829,7 +841,7 @@
7
- 34
+ 35
1
0
0
@@ -841,7 +853,7 @@
7
- 35
+ 36
1
0
0
@@ -853,7 +865,7 @@
7
- 36
+ 37
1
0
0
@@ -865,7 +877,7 @@
7
- 37
+ 38
1
0
0
@@ -877,7 +889,7 @@
7
- 38
+ 39
1
0
0
@@ -889,7 +901,7 @@
7
- 39
+ 40
1
0
0
@@ -901,7 +913,7 @@
7
- 40
+ 41
1
0
0
@@ -913,7 +925,7 @@
7
- 41
+ 42
1
0
0
@@ -925,7 +937,7 @@
7
- 42
+ 43
1
0
0
@@ -937,7 +949,7 @@
7
- 43
+ 44
1
0
0
@@ -949,7 +961,7 @@
7
- 44
+ 45
1
0
0
@@ -961,7 +973,7 @@
7
- 45
+ 46
1
0
0
@@ -973,7 +985,7 @@
7
- 46
+ 47
1
0
0
@@ -985,7 +997,7 @@
7
- 47
+ 48
1
0
0
@@ -997,7 +1009,7 @@
7
- 48
+ 49
1
0
0
@@ -1017,7 +1029,7 @@
0
8
- 49
+ 50
1
0
0
@@ -1029,7 +1041,7 @@
8
- 50
+ 51
1
0
0
@@ -1041,7 +1053,7 @@
8
- 51
+ 52
1
0
0
@@ -1053,7 +1065,7 @@
8
- 52
+ 53
1
0
0
@@ -1065,7 +1077,7 @@
8
- 53
+ 54
1
0
0
@@ -1077,7 +1089,7 @@
8
- 54
+ 55
1
0
0
@@ -1089,7 +1101,7 @@
8
- 55
+ 56
1
0
0
@@ -1101,7 +1113,7 @@
8
- 56
+ 57
1
0
0
@@ -1113,7 +1125,7 @@
8
- 57
+ 58
1
0
0
@@ -1125,7 +1137,7 @@
8
- 58
+ 59
1
0
0
@@ -1137,7 +1149,7 @@
8
- 59
+ 60
1
0
0
@@ -1149,7 +1161,7 @@
8
- 60
+ 61
1
0
0
@@ -1161,7 +1173,7 @@
8
- 61
+ 62
1
0
0
@@ -1173,7 +1185,7 @@
8
- 62
+ 63
1
0
0
@@ -1185,7 +1197,7 @@
8
- 63
+ 64
1
0
0
@@ -1197,7 +1209,7 @@
8
- 64
+ 65
1
0
0
@@ -1209,7 +1221,7 @@
8
- 65
+ 66
1
0
0
@@ -1221,7 +1233,7 @@
8
- 66
+ 67
1
0
0
@@ -1233,7 +1245,7 @@
8
- 67
+ 68
1
0
0
@@ -1245,7 +1257,7 @@
8
- 68
+ 69
1
0
0
@@ -1257,7 +1269,7 @@
8
- 69
+ 70
1
0
0
@@ -1269,7 +1281,7 @@
8
- 70
+ 71
1
0
0
@@ -1281,7 +1293,7 @@
8
- 71
+ 72
1
0
0
@@ -1293,7 +1305,7 @@
8
- 72
+ 73
1
0
0
@@ -1305,7 +1317,7 @@
8
- 73
+ 74
1
0
0
@@ -1317,7 +1329,7 @@
8
- 74
+ 75
1
0
0
@@ -1329,7 +1341,7 @@
8
- 75
+ 76
1
0
0
@@ -1349,7 +1361,7 @@
0
9
- 76
+ 77
1
0
0
@@ -1361,7 +1373,7 @@
9
- 77
+ 78
1
0
0
@@ -1373,7 +1385,7 @@
9
- 78
+ 79
1
0
0
@@ -1385,7 +1397,7 @@
9
- 79
+ 80
1
0
0
@@ -1397,7 +1409,7 @@
9
- 80
+ 81
1
0
0
@@ -1409,7 +1421,7 @@
9
- 81
+ 82
1
0
0
@@ -1429,7 +1441,7 @@
0
10
- 82
+ 83
1
0
0
@@ -1441,7 +1453,7 @@
10
- 83
+ 84
1
0
0
@@ -1453,7 +1465,7 @@
10
- 84
+ 85
1
0
0
@@ -1473,7 +1485,7 @@
0
11
- 85
+ 86
1
0
0
@@ -1485,7 +1497,7 @@
11
- 86
+ 87
1
0
0
@@ -1497,7 +1509,7 @@
11
- 87
+ 88
1
0
0
@@ -1517,7 +1529,7 @@
0
12
- 88
+ 89
1
0
0
@@ -1529,7 +1541,7 @@
12
- 89
+ 90
1
0
0
@@ -1541,7 +1553,7 @@
12
- 90
+ 91
1
0
0
@@ -1561,7 +1573,7 @@
0
13
- 91
+ 92
1
0
0
@@ -1573,7 +1585,7 @@
13
- 92
+ 93
1
0
0
@@ -1593,7 +1605,7 @@
0
14
- 93
+ 94
1
0
0
@@ -1605,7 +1617,7 @@
14
- 94
+ 95
1
0
0
@@ -1617,7 +1629,7 @@
14
- 95
+ 96
1
0
0
@@ -1629,7 +1641,7 @@
14
- 96
+ 97
1
0
0
diff --git a/app/app.uvprojx b/app/app.uvprojx
index aeed717..09f0a36 100644
--- a/app/app.uvprojx
+++ b/app/app.uvprojx
@@ -134,11 +134,11 @@
0
1
1
- 4099
+ 4096
1
BIN\UL2CM3.DLL
-
+ "" ()
@@ -313,7 +313,7 @@
1
- 1
+ 4
0
0
1
@@ -458,6 +458,11 @@
1
.\src\basic\device_version_info_mgr.c
+
+ filters.c
+ 1
+ .\src\basic\filters.c
+
@@ -4297,6 +4302,11 @@
1
.\src\basic\device_version_info_mgr.c
+
+ filters.c
+ 1
+ .\src\basic\filters.c
+
diff --git a/app/src/basic/ads1293/ads1293.h b/app/src/basic/ads1293/ads1293.h
index 898e63d..7de9003 100644
--- a/app/src/basic/ads1293/ads1293.h
+++ b/app/src/basic/ads1293/ads1293.h
@@ -121,6 +121,8 @@ void ads1293_spi_stream_readreg(ads1293_t* ads, uint8_t* data, uint8_t len);
void ads1293_read_ecg(ads1293_t* ads, uint32_t ch, uint32_t* data);
void ads1293_read_ecgs(ads1293_t* ads, uint32_t* data /*3*/);
+void ads1293_read_ecgs_v2(ads1293_t* ads, int startoff, uint32_t* data, int num);
+
uint8_t ads1293_read_error_lod(ads1293_t* ads);
void ads1293_start_conversion(ads1293_t* ads);
diff --git a/app/src/basic/device_version_info_mgr.c b/app/src/basic/device_version_info_mgr.c
index 55034a7..c5decf8 100644
--- a/app/src/basic/device_version_info_mgr.c
+++ b/app/src/basic/device_version_info_mgr.c
@@ -16,7 +16,7 @@ void device_info_read_sn(sn_t *sn) {
static char sn_str[15];
sprintf(sn_str, CATEGORY "%04d%05d", lot, id);
if (lot == 0 || id == 0 || lot == 0xffffffff || id == 0xffffffff) {
- sprintf(sn_str, "iflytop_test", 0, 0);
+ sprintf(sn_str, "iflytop_test");
}
memcpy(sn->sn, sn_str, sizeof(sn->sn));
}
diff --git a/app/src/basic/filters.c b/app/src/basic/filters.c
new file mode 100644
index 0000000..8d063a5
--- /dev/null
+++ b/app/src/basic/filters.c
@@ -0,0 +1,113 @@
+#include "filters.h"
+
+#include
+#include
+#define PI 3.14159265358979323846
+
+/********************************************************************************************************
+ * LOW PASS FILTER
+ ********************************************************************************************************/
+
+void LPFilter_Init(LPFilter *filter, float cutoffFreqHz, float sampleTimeS) {
+ float RC = 0.0;
+ RC = 1.0 / (2 * PI * cutoffFreqHz);
+ filter->coef[0] = sampleTimeS / (sampleTimeS + RC);
+ filter->coef[1] = RC / (sampleTimeS + RC);
+
+ filter->v_out[0] = 0.0;
+ filter->v_out[1] = 0.0;
+}
+
+float LPFilter_Update(LPFilter *filter, float v_in) {
+ filter->v_out[1] = filter->v_out[0];
+ filter->v_out[0] = (filter->coef[0] * v_in) + (filter->coef[1] * filter->v_out[1]);
+
+ return (filter->v_out[0]);
+}
+
+/********************************************************************************************************
+ * HIGH PASS FILTER
+ ********************************************************************************************************/
+void HPFilter_Init(HPFilter *filter, float cutoffFreqHz, float sampleTimeS) {
+ float RC = 0.0;
+ RC = 1.0 / (2 * PI * cutoffFreqHz);
+
+ filter->coef = RC / (sampleTimeS + RC);
+
+ filter->v_in[0] = 0.0;
+ filter->v_in[1] = 0.0;
+
+ filter->v_out[0] = 0.0;
+ filter->v_out[1] = 0.0;
+}
+
+float HPFilter_Update(HPFilter *filter, float v_in) {
+ filter->v_in[1] = filter->v_in[0];
+ filter->v_in[0] = v_in;
+
+ filter->v_out[1] = filter->v_out[0];
+
+ filter->v_out[0] = filter->coef * (filter->v_in[0] - filter->v_in[1] + filter->v_out[1]);
+
+ return (filter->v_out[0]);
+}
+
+/********************************************************************************************************
+ * BAND PASS FILTER
+ ********************************************************************************************************/
+
+void PBFilter_Init(PBFilter *filter, float HPF_cutoffFreqHz, float LPF_cutoffFreqHz, float sampleTimeS) {
+ LPFilter_Init(&filter->lpf, LPF_cutoffFreqHz, sampleTimeS);
+ HPFilter_Init(&filter->hpf, HPF_cutoffFreqHz, sampleTimeS);
+ filter->out_in = 0.0;
+}
+
+float PBFilter_Update(PBFilter *filter, float v_in) {
+ filter->out_in = HPFilter_Update(&filter->hpf, v_in);
+
+ filter->out_in = LPFilter_Update(&filter->lpf, filter->out_in);
+
+ return (filter->out_in);
+}
+
+/********************************************************************************************************
+ * NOTCH FILTER
+ ********************************************************************************************************/
+
+void NOTCHFilter_Init(NOTCHFilter *filter, float centerFreqHz, float notchWidthHz, float sampleTimeS) {
+ // filter frequency to angular (rad/s)
+ float w0_rps = 2.0 * PI * centerFreqHz;
+ float ww_rps = 2.0 * PI * notchWidthHz;
+
+ // pre warp center frequency
+ float w0_pw_rps = (2.0 / sampleTimeS) * tanf(0.5 * w0_rps * sampleTimeS);
+
+ // computing filter coefficients
+
+ filter->alpha = 4.0 + w0_rps * w0_pw_rps * sampleTimeS * sampleTimeS;
+ filter->beta = 2.0 * ww_rps * sampleTimeS;
+
+ // clearing input and output buffers
+
+ for (uint8_t n = 0; n < 3; n++) {
+ filter->vin[n] = 0;
+ filter->vout[n] = 0;
+ }
+}
+
+float NOTCHFilter_Update(NOTCHFilter *filter, float vin) {
+ // shifting samples
+ filter->vin[2] = filter->vin[1];
+ filter->vin[1] = filter->vin[0];
+
+ filter->vout[2] = filter->vout[1];
+ filter->vout[1] = filter->vout[0];
+
+ filter->vin[0] = vin;
+
+ // compute new output
+ filter->vout[0] = (filter->alpha * filter->vin[0] + 2.0 * (filter->alpha - 8.0) * filter->vin[1] + filter->alpha * filter->vin[2] - (2.0f * (filter->alpha - 8.0) * filter->vout[1] + (filter->alpha - filter->beta) * filter->vout[2])) / (filter->alpha + filter->beta);
+
+ return (filter->vout[0]);
+}
+
diff --git a/app/src/basic/filters.h b/app/src/basic/filters.h
new file mode 100644
index 0000000..39b77b8
--- /dev/null
+++ b/app/src/basic/filters.h
@@ -0,0 +1,56 @@
+#pragma once
+#include
+
+/********************************************************************************************************
+ * LOW PASS FILTER
+ ********************************************************************************************************/
+typedef struct {
+ float coef[2];
+ float v_out[2];
+} LPFilter;
+
+void LPFilter_Init(LPFilter *filter, float cutoffFreqHz, float sampleTimeS);
+float LPFilter_Update(LPFilter *filter, float v_in);
+
+/********************************************************************************************************
+ * HIGH PASS FILTER
+ ********************************************************************************************************/
+typedef struct {
+ float coef;
+ float v_out[2];
+ float v_in[2];
+
+} HPFilter;
+
+void HPFilter_Init(HPFilter *filter, float cutoffFreqHz, float sampleTimeS);
+float HPFilter_Update(HPFilter *filter, float v_in);
+
+/********************************************************************************************************
+ * BAND PASS FILTER
+ ********************************************************************************************************/
+
+typedef struct {
+ LPFilter lpf;
+ HPFilter hpf;
+ float out_in;
+} PBFilter;
+
+void PBFilter_Init(PBFilter *filter, float HPF_cutoffFreqHz, float LPF_cutoffFreqHz, float sampleTimeS);
+float PBFilter_Update(PBFilter *filter, float v_in);
+
+/********************************************************************************************************
+ * NOTCH FILTER
+ ********************************************************************************************************/
+
+typedef struct {
+ float alpha;
+ float beta;
+
+ float vin[3];
+ float vout[3];
+
+} NOTCHFilter;
+
+void NOTCHFilter_Init(NOTCHFilter *filter, float centerFreqHz, float notchWidthHz, float sampleTimeS);
+float NOTCHFilter_Update(NOTCHFilter *filter, float vin);
+
diff --git a/app/src/board/board.h b/app/src/board/board.h
index 6c74863..62c34f0 100644
--- a/app/src/board/board.h
+++ b/app/src/board/board.h
@@ -65,7 +65,7 @@
#define LITTLE_DATA_BLOCK_FRAME_NUM 4 // 每两帧回调一次,对应100HZ
#define SAMPLE_PRECISION 24
-#define APP_MAX_EVEN_SIZE MAX(APP_TIMER_SCHED_EVENT_DATA_SIZE, sizeof(app_event_t))
+#define APP_MAX_EVEN_SIZE (MAX(APP_TIMER_SCHED_EVENT_DATA_SIZE, sizeof(app_event_t)) + 10)
#define APP_EVENT_QUEUE_SIZE 100
#define APP_AUTO_SLEEP_TIMEOUT_MS (30 * 1000) // 自动休眠时间
diff --git a/app/src/board/board_beep_ctrl.c b/app/src/board/board_beep_ctrl.c
index 078189c..43cb2c2 100644
--- a/app/src/board/board_beep_ctrl.c
+++ b/app/src/board/board_beep_ctrl.c
@@ -22,7 +22,7 @@ static nrf_drv_pwm_config_t const m_beep_pwm0_config0 = {
.irq_priority = APP_IRQ_PRIORITY_LOWEST,
.base_clock = NRF_PWM_CLK_125kHz,
.count_mode = NRF_PWM_MODE_UP,
- .top_value = 46, // 125kHz / 46 = 2.717k
+ .top_value = 56, // 125kHz / 46 = 2.717k
.load_mode = NRF_PWM_LOAD_INDIVIDUAL,
.step_mode = NRF_PWM_STEP_AUTO,
};
@@ -84,7 +84,7 @@ void BoardBeepCtrl_unload() {
void BoardBeepCtrl_set(uint8_t state) {
if (state) {
- m_beep_pwm0_seq_values.channel_0 = m_beep_pwm0_config0.top_value / 2; // 设置占空比,数值最大不超过 top_value
+ m_beep_pwm0_seq_values.channel_0 = 10; // 设置占空比,数值最大不超过 top_value
nrfx_pwm_simple_playback(&m_beep_pwm0, &m_beep_pwm0_seq, 1, NRF_DRV_PWM_FLAG_LOOP);
} else {
nrfx_pwm_stop(&m_beep_pwm0, true);
diff --git a/app/src/device_ctrl_service.c b/app/src/device_ctrl_service.c
index 36c4a31..42e6f98 100644
--- a/app/src/device_ctrl_service.c
+++ b/app/src/device_ctrl_service.c
@@ -214,10 +214,12 @@ static void app_event_listener(void* p_event_data, uint16_t event_size) { //
uint8_t dropdata0 = hwss_get_drop_state0();
uint8_t dropdata1 = hwss_get_drop_state1();
- if (dropdata0 || dropdata1) {
- BoardBeepCtrl_setEffect(kBoardBeepEffect_continuousShortBeep);
- } else {
- BoardBeepCtrl_setEffect(kBoardBeepEffect_none);
+ if (DeviceCtrl_cur_state_haspassed_ms() > 3000) {
+ if ((dropdata0 || dropdata1)) {
+ BoardBeepCtrl_setEffect(kBoardBeepEffect_continuousShortBeep);
+ } else {
+ BoardBeepCtrl_setEffect(kBoardBeepEffect_none);
+ }
}
bool stopcapture = false;
diff --git a/app/src/heart_wave_sample_service.c b/app/src/heart_wave_sample_service.c
index 10f0dd6..80be732 100644
--- a/app/src/heart_wave_sample_service.c
+++ b/app/src/heart_wave_sample_service.c
@@ -6,6 +6,7 @@
#include "app_event.h"
#include "app_event_distribute.h"
#include "basic/ads1293/ads1293.h"
+#include "basic/filters.h"
#include "nrf_drv_gpiote.h"
#include "nrfx_timer.h"
@@ -25,6 +26,35 @@
#define FRAME_FILTER_INDEX_NUM 10 // 过滤帧数,每次启动采集后,过滤掉的帧数
#define GPIO_IRQ_TRIGGER_MODE 1
+#define MEDIAN_FILTER_BUFFER_SIZE 5
+typedef struct {
+ uint32_t val[MEDIAN_FILTER_BUFFER_SIZE];
+ uint32_t processbuf[MEDIAN_FILTER_BUFFER_SIZE];
+ int valcnt;
+} MedianFilter_t;
+
+void MedianFilter_Init(MedianFilter_t *filter) { filter->valcnt = 0; }
+
+uint32_t MedianFilter_Update(MedianFilter_t *filter, uint32_t vin) { //
+ memcpy(&filter->val[1], &filter->val[0], MEDIAN_FILTER_BUFFER_SIZE * sizeof(filter->val[0]));
+ filter->val[0] = vin;
+ if (filter->valcnt < MEDIAN_FILTER_BUFFER_SIZE) {
+ filter->valcnt++;
+ return vin;
+ }
+ memcpy(filter->processbuf, filter->val, MEDIAN_FILTER_BUFFER_SIZE * sizeof(filter->val[0]));
+ for (int i = 0; i < MEDIAN_FILTER_BUFFER_SIZE; i++) {
+ for (int j = i + 1; j < MEDIAN_FILTER_BUFFER_SIZE; j++) {
+ if (filter->processbuf[i] > filter->processbuf[j]) {
+ uint32_t temp = filter->processbuf[i];
+ filter->processbuf[i] = filter->processbuf[j];
+ filter->processbuf[j] = temp;
+ }
+ }
+ }
+ return filter->processbuf[MEDIAN_FILTER_BUFFER_SIZE / 2];
+}
+
/*******************************************************************************
* STRUCT *
*******************************************************************************/
@@ -63,6 +93,8 @@ volatile static bool m_drop_state_triggered = false;
static uint32_t m_capture_start_s;
+LPFilter lowpassfilter[3];
+MedianFilter_t medianFilter[3];
/*******************************************************************************
* CONFIG *
*******************************************************************************/
@@ -108,13 +140,13 @@ static inline void pFrameBufferAB_push_one_byte(uint8_t byte) {
* LittleDataBuffer操作 *
*******************************************************************************/
-static inline void pLittleBlockCache_push_one_frame(uint32_t data0, uint32_t data1, uint32_t data2) {
+static inline void pLittleBlockCache_push_one_frame(uint32_t *data) {
if (m_little_frame_index >= LITTLE_DATA_BLOCK_FRAME_NUM) {
return;
}
- m_sensor_little_frame_cache[m_little_frame_index].data0 = data0;
- m_sensor_little_frame_cache[m_little_frame_index].data1 = data1;
- m_sensor_little_frame_cache[m_little_frame_index].data2 = data2;
+ m_sensor_little_frame_cache[m_little_frame_index].data0 = data[0];
+ m_sensor_little_frame_cache[m_little_frame_index].data1 = data[1];
+ m_sensor_little_frame_cache[m_little_frame_index].data2 = data[2];
m_little_frame_index++;
}
@@ -397,25 +429,49 @@ static void ads1293_sample_one_frame() {
m_frame_index++;
// 检查缓冲区是否为空
if (!m_frame_buffer) pFrameBufferAB_switch();
-
static uint32_t sample[6];
- ads1293_read_ecgs(&m_ads1293_0, &sample[0]);
-#if CHANNEL_NUM == 2
+
+#if 0
ads1293_read_ecgs(&m_ads1293_1, &sample[3]);
+#if CHANNEL_NUM == 2
+ ads1293_read_ecgs(&m_ads1293_0, &sample[0]);
+#endif
#endif
+ ads1293_read_ecg(&m_ads1293_1, 1, &sample[SENSOR1_ID]);
+ ads1293_read_ecg(&m_ads1293_1, 2, &sample[SENSOR2_ID]);
+ ads1293_read_ecg(&m_ads1293_0, 1, &sample[SENSOR0_ID]);
+
+ // medianFilter
+
+ static uint32_t val[3];
+ val[0] = MedianFilter_Update(&medianFilter[0], sample[SENSOR0_ID]);
+ val[1] = MedianFilter_Update(&medianFilter[1], sample[SENSOR1_ID]);
+ val[2] = MedianFilter_Update(&medianFilter[2], sample[SENSOR2_ID]);
+
+ // int32_t val0 = LPFilter_Update(&lowpassfilter[0], sample[SENSOR0_ID]);
+ // int32_t val1 = LPFilter_Update(&lowpassfilter[1], sample[SENSOR1_ID]);
+ // int32_t val2 = LPFilter_Update(&lowpassfilter[2], sample[SENSOR2_ID]);
+
+ // uint32_t val0 = sample[SENSOR0_ID];
+ // uint32_t val1 = sample[SENSOR1_ID];
+ // uint32_t val2 = sample[SENSOR2_ID];
+
+ if (val[0] > 0xffffff) val[0] = 0xffffff;
+ if (val[1] > 0xffffff) val[1] = 0xffffff;
+ if (val[2] > 0xffffff) val[2] = 0xffffff;
static uint8_t cache[9];
- cache[0] = (sample[SENSOR0_ID] >> 0) & 0xff;
- cache[1] = (sample[SENSOR0_ID] >> 8) & 0xff;
- cache[2] = (sample[SENSOR0_ID] >> 16) & 0xff;
+ cache[0] = (val[0] >> 0) & 0xff;
+ cache[1] = (val[0] >> 8) & 0xff;
+ cache[2] = (val[0] >> 16) & 0xff;
- cache[3] = (sample[SENSOR1_ID] >> 0) & 0xff;
- cache[4] = (sample[SENSOR1_ID] >> 8) & 0xff;
- cache[5] = (sample[SENSOR1_ID] >> 16) & 0xff;
+ cache[3] = (val[1] >> 0) & 0xff;
+ cache[4] = (val[1] >> 8) & 0xff;
+ cache[5] = (val[1] >> 16) & 0xff;
- cache[6] = (sample[SENSOR2_ID] >> 0) & 0xff;
- cache[7] = (sample[SENSOR2_ID] >> 8) & 0xff;
- cache[8] = (sample[SENSOR2_ID] >> 16) & 0xff;
+ cache[6] = (val[2] >> 0) & 0xff;
+ cache[7] = (val[2] >> 8) & 0xff;
+ cache[8] = (val[2] >> 16) & 0xff;
/**
* @brief 缓存数据,并触发数据块事件
@@ -432,7 +488,7 @@ static void ads1293_sample_one_frame() {
/**
* @brief 缓存数据,并触发小数据块事件
*/
- pLittleBlockCache_push_one_frame(sample[SENSOR0_ID], sample[SENSOR1_ID], sample[SENSOR2_ID]);
+ pLittleBlockCache_push_one_frame(val);
if (pLittleBlockCache_is_full()) {
pEventHelper_trigger_little_block_data_event();
pLittleBlockCache_reset();
@@ -493,6 +549,15 @@ void hwss_start_capture(void) {
m_frame_index = 0;
m_frame_filter_index = 0;
m_capture_start_s = znordic_getpower_on_s();
+
+ LPFilter_Init(&lowpassfilter[0], 40, 0.0025);
+ LPFilter_Init(&lowpassfilter[1], 40, 0.0025);
+ LPFilter_Init(&lowpassfilter[2], 40, 0.0025);
+
+ MedianFilter_Init(&medianFilter[0]);
+ MedianFilter_Init(&medianFilter[1]);
+ MedianFilter_Init(&medianFilter[2]);
+
pLittleBlockCache_reset();
// ads1293_start_conversion(&m_ads1293_0);
// ads1293_start_conversion(&m_ads1293_1);