[ PROMPT_NODE_26878 ]
epochs_events
[ SKILL_DOCUMENTATION ]
# Epochs 和事件相关分析
## 概述
事件相关分析检查与特定刺激或事件时间锁定的生理反应。NeuroKit2 提供了用于所有信号类型的事件检测、分段创建、平均化和事件相关特征提取的工具。
## 事件检测
### events_find()
根据阈值交叉或变化自动检测信号中的事件/触发器。
python
events = nk.events_find(event_channel, threshold=0.5, threshold_keep='above',
duration_min=1, inter_min=0)
**参数:**
- `threshold`: 检测阈值
- `threshold_keep`: `'above'` 或 `'below'` 阈值
- `duration_min`: 保留的最小事件持续时间(采样点)
- `inter_min`: 事件之间的最小间隔(采样点)
**返回:**
- 字典,包含:
- `'onset'`: 事件起始索引
- `'offset'`: 事件终止索引(如果适用)
- `'duration'`: 事件持续时间
- `'label'`: 事件标签(如果存在多种事件类型)
**常见用例:**
**实验中的 TTL 触发器:**
python
# 触发通道:0V 基线,事件期间为 5V 脉冲
events = nk.events_find(trigger_channel, threshold=2.5, threshold_keep='above')
**按钮按下:**
python
# 检测按钮信号何时变高
button_events = nk.events_find(button_signal, threshold=0.5, threshold_keep='above',
duration_min=10) # 去抖动
**状态变化:**
python
# 检测高于/低于阈值的周期
high_arousal = nk.events_find(eda_signal, threshold='auto', duration_min=100)
### events_plot()
可视化事件相对于信号的时间安排。
python
nk.events_plot(events, signal)
**显示:**
- 信号轨迹
- 事件标记(垂直线或阴影区域)
- 事件标签
**用例:**
- 验证事件检测的准确性
- 检查事件的时间分布
- 分段前的质量控制
## 分段创建
### epochs_create()
创建事件周围的数据段(Epochs),用于事件相关分析。
python
epochs = nk.epochs_create(data, events, sampling_rate=1000,
epochs_start=-0.5, epochs_end=2.0,
event_labels=None, event_conditions=None,
baseline_correction=False)
**参数:**
- `data`: 包含信号的 DataFrame 或单个信号
- `events`: 事件索引或来自 `events_find()` 的字典
- `sampling_rate`: 信号采样率 (Hz)
- `epochs_start`: 相对于事件的开始时间 (s