科研 Skill

神经解码器嵌入式移植

neuro-decoder-to-firmware

Ports a neural signal-processing or BCI decoder from Python or MATLAB to fixed-point embedded C on a microcontroller. Use when moving a decoder onto implant or headstage firmware.

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

SKILL.md

Decoder to firmware

The firmware must give the same decisions as the reference on every input the hardware can produce, including full-scale and near-silent signals. Work from a bit-accurate plan, then test against the reference with vectors that cover the extremes.

1. Inventory the reference

List every stage with its numeric range: input type and range (int16 ADC counts, offsets), filters (order, type, band, fs), features (variance, log, power), classifier (weights, bias, comparison). Note where the reference relies on floating point (log, division, mean removal).

2. Filters

  • Always implement IIR filters as cascaded second-order sections, never as one high-order direct form (coefficient sensitivity grows with order).
  • Generate quantized coefficients and headroom with the bundled script:
python scripts/quantize_sos.py --design butter --order 4 --band 8 30 --btype bandpass --fs 250 \
       --coef-bits 30 --input-bits 16 --c-header sos_coefs.h

It reports, per section, the coefficient format, pole radius before and after quantization (stability margin), the worst-case gain from the input to each section output (L1 norm of the impulse response), the bits of headroom needed, and the accumulator width required. It writes a C header.

  • Poles near z = 1 (high-pass below about 1 Hz at kHz rates) need more coefficient and state precision; use 32-bit coefficients with 64-bit accumulation, or a state-variable / error-feedback structure.
  • Saturate on output; never let values wrap.

3. Features and classifier without floats

  • Mean removal: work with sums (n*x - sum) to avoid division.
  • Variance: sum of squares in 64 bits (int16 squared times hundreds of samples overflows 32 bits).
  • Log: avoid it where possible. For LDA on log-variance, w*(log v0 - log v1) + b > 0 becomes v0^w * e^b > v1^w; for w = 1 compare v0 * K > v1 with K = round(e^b * 2^q). Otherwise use a fixed-point log2 (leading-zero count plus a lookup or polynomial).
  • Keep weights in a Q format chosen from their range.

4. Verify

  1. Write a bit-exact Python model of the C arithmetic, or compile the C on the host and call it from Python.
  2. Test vectors: typical trials, full-scale (near +/-32767), near-silent, large DC offsets, constant input, single spikes, and trials close to the decision boundary.
  3. Require identical decisions (or report the mismatch rate and where it occurs) and filter output error within one LSB.
  4. Cross-compile for the target and estimate cycles per sample against the sample period.

Output

C files with the requested API, the coefficient header, the headroom report, the test-vector results, and the cycle estimate.

示例提示词

帮我把这个Python的CSP解码器移植成微控制器上的定点C代码。

所属插件

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

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

同插件的其他科研 Skill

常见问题

神经解码器嵌入式移植能做什么?

Ports a neural signal-processing or BCI decoder from Python or MATLAB to fixed-point embedded C on a microcontroller. Use when moving a decoder onto implant or headstage firmware。

如何安装神经解码器嵌入式移植?

在科搭 Codar 左侧点击「插件」,在「组件」页签搜索「神经解码器嵌入式移植」并安装;在 Claude Code 或 Codex 中可以发送本页的安装提示词,或下载 Skill 包后解压到 ~/.claude/skills 或 ~/.codex/skills。

神经解码器嵌入式移植需要哪些权限?

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

神经解码器嵌入式移植经过官方审核吗?

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