科研 Skill

实时闭环BCI系统搭建

neuro-realtime-bci-pipeline

Builds or debugs a real-time closed-loop BCI or neurofeedback pipeline using LSL, BrainFlow or similar frameworks. Use when streaming data live, sending triggers, or measuring latency.

发布者 Codar安全审核通过v0.1.0更新于 2026-11-18

SKILL.md

Real-time BCI pipeline

An online pipeline has to be causal, keep up with the data rate, and have known timing. Build it in the order below and measure timing before collecting real data.

0. Load the tool reference

TaskReference
LSL streams, clocks, LabRecorder/XDF, replaying recordings with MNE-LSLreferences/lsl.md
BrainFlow boards, buffers, causal filtering, packet lossreferences/brainflow.md
PsychoPy or Psychtoolbox stimuli, frame timing, markers and TTL triggersreferences/stimulus.md
Choosing and using BCI2000, OpenViBE, Timeflux, BciPy, MEDUSA, BRANDreferences/frameworks.md

Check any live stream with scripts/lsl_stream_check.py (true rate, gaps, lost samples, clock offset, sample age) before recording real data.

1. Acquisition

  • LSL: one stream per device; record everything with LabRecorder to XDF. Load with pyxdf.load_xdf(..., synchronize_clocks=True, dejitter_timestamps=True) so streams share one clock.
  • BrainFlow: BoardShim with the board id; use the synthetic board to develop without hardware. Check the board's real sampling rate, not the nominal one.
  • Pull in chunks (for example 20-50 ms) rather than per sample; keep a ring buffer sized to the longest window you need.

2. Markers and sync

Software markers from the stimulus PC carry OS and display jitter. For anything time-locked (ERPs, phase-locked stimulation) send a hardware trigger (TTL into the amplifier's trigger input, or a photodiode on the screen) and use software markers only as labels. Verify alignment with neuro-stimulus-timing-audit; align separate clocks with neuro-sync-forensics.

3. Causal processing

  • Filters: scipy.signal.sosfilt with state carried across chunks (zi from sosfilt_zi, then pass the returned state into the next call). Never filtfilt online.
  • Features over a sliding window ending at "now"; the offline model must be trained on the same causal features and window length.
  • Re-referencing and spatial filters (CAR, CSP) are fine online if fitted offline on calibration data.

4. Measure latency and jitter

End-to-end latency = acquisition buffering + transport + processing + feedback rendering. Measure it, do not estimate it:

  1. Loopback test: feed a known signal (function generator or the amplifier test signal) and detect it at the output, or
  2. Photodiode on the feedback display, recorded on an amplifier channel.

Report median and 95th percentile latency, and processing time per chunk (must stay well below the chunk duration).

5. Before the first session

Dry run 30 minutes with a synthetic or test signal: no buffer growth, no dropped samples (check sample counters), CPU headroom, and logging of every decoder output with its timestamp.

Output

Pipeline diagram (devices, streams, rates, chunk sizes), filter and feature settings, measured latency (median, p95) and jitter, and the test log.

示例提示词

帮我用pylsl和BrainFlow搭一套实时脑机接口神经反馈系统。

所属插件

神经科学面向神经科学研究:EEG/MEG、fMRI、BIDS、spike sorting、连接组、脑机接口解码评估、神经刺激安全与公开神经数据检索。

安装该插件会一并获得同领域的 45 个 Skill / MCP。

同插件的其他科研 Skill

常见问题

实时闭环BCI系统搭建能做什么?

Builds or debugs a real-time closed-loop BCI or neurofeedback pipeline using LSL, BrainFlow or similar frameworks. Use when streaming data live, sending triggers, or measuring latency。

如何安装实时闭环BCI系统搭建?

在科搭 Codar 左侧点击「插件」,在「组件」页签搜索「实时闭环BCI系统搭建」并安装;在 Claude Code 或 Codex 中可以发送本页的安装提示词,或下载 Skill 包后解压到 ~/.claude/skills 或 ~/.codex/skills。

实时闭环BCI系统搭建需要哪些权限?

该科研 Skill没有声明额外权限;执行具体操作时仍由 Agent 按自身规则请求确认。

实时闭环BCI系统搭建经过官方审核吗?

是。SpeedSkills 收录的每个版本都会记录内容摘要与权限声明,当前版本已通过安全审核。