Asi zig-syrup-bci

Multimodal BCI pipeline in Zig: DSI-24 EEG, fNIRS mBLL, eye tracking IVT, LSL sync, EDF read/write, GF(3) conservation

install
source · Clone the upstream repo
git clone https://github.com/plurigrid/asi
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/plurigrid/asi "$T" && mkdir -p ~/.claude/skills && cp -r "$T/plugins/asi/skills/zig-syrup-bci" ~/.claude/skills/plurigrid-asi-zig-syrup-bci && rm -rf "$T"
manifest: plugins/asi/skills/zig-syrup-bci/SKILL.md
source content

zig-syrup-bci

Multimodal brain-computer interface pipeline for zig-syrup. Parses, processes, and classifies signals from EEG, fNIRS, eye tracking, and body pose modalities with GF(3) trit conservation.

Modules

ModuleFileTritPurpose
dsi24_parser
src/dsi24_parser.zig
0Wearable Sensing DSI-24 24ch dry EEG (84-byte packets, ADS1299, 300Hz)
fnirs_processor
src/fnirs_processor.zig
+1Modified Beer-Lambert Law: raw optical → HbO/HbR/HbT concentrations
eyetracking
src/eyetracking.zig
-1IVT fixation/saccade classifier, pupillometry, blink detection
lsl_inlet
src/lsl_inlet.zig
0Lab Streaming Layer C FFI + software-only fallback, StreamSynchronizer
pose_bridge
src/pose_bridge.zig
0Body tracking joint angles → movement trit (tremor detection)
edf_writer
src/edf_writer.zig
0EDF+ format writer for EEG archival (MNE/EEGLAB compatible)
edf_reader
src/edf_reader.zig
0EDF/EDF+ parser validated against PhysioNet BCI2000 (65ch, 160Hz)
bci_receiver
src/bci_receiver.zig
0Universal 9-modality receiver (nRF5340 target)
erc
src/erc.zig
0Ensemble Reservoir Computing: ensemble averaging, NLMS online learning → trit
fft_bands
src/fft_bands.zig
0Comptime-memoized FFT, Welch PSD, EEG band extraction

GF(3) Conservation

eeg(0) + fnirs(+1) + eye(-1) = 0 mod 3 ✓

Verified across module boundaries in

bci_integration_test.zig
(16 tests).

Quick Start

# Run all BCI tests
zig build test-bci

# With real PhysioNet data (downloads 1.2MB EDF)
curl -sL -o testdata/S001R01.edf \
  "https://physionet.org/files/eegmmidb/1.0.0/S001/S001R01.edf"
zig build test-bci

Test Fixtures

FileSizeSourceTests
src/testdata/fixture_2ch.edf
800BSyntheticEDF round-trip, basic parsing
src/testdata/subsecond_starttime.edf
17KBMNE testing4ch EDF+C, subsecond timestamps
src/testdata/test_utf8_annotations.edf
48KBMNE testing12ch synthetic waveforms
testdata/S001R01.edf
1.2MBPhysioNet BCI200065ch real EEG (gitignored)
testdata/minimal.xdf
2KBxdf-modulesXDF reference (2 LSL streams)
testdata/minimum_example.snirf
14KBfNIRS/snirf-samplesSNIRF HDF5 reference

Key APIs

DSI-24 Parser

const sample = try dsi24.parseDSI24Packet(&packet_84bytes);
// sample.eeg_channels[0..21] — µV values
// sample.aux_channels[0..3]
// sample.sample_counter, .timestamp_us

fNIRS Modified Beer-Lambert

const config = fnirs.WavelengthPair.plux(); // 660/860nm, DPF 6.51/5.60
const hemo = fnirs.beerLambert(delta_od1, delta_od2, config);
// hemo.hbo, .hbr, .hbt — µmol/L concentration changes
const reading = fnirs.FNIRSReading.fromConcentration(hemo, timestamp_ms, threshold);
// reading.trit — .plus (activation), .zero (baseline), .minus (deactivation)

Eye Tracking IVT

const result = eye.classifyIVT(current_gaze, prev_gaze, .{});
// result.event — .fixation, .saccade, .blink
// result.velocity — degrees/second
// result.event.toTrit() — .zero (fixation), .plus (saccade), .minus (blink)

EDF Reader

const edf = try edf_reader.EDFFile.parse(file_bytes);
// edf.n_channels, .n_records, .record_duration
// edf.channels[i].labelStr(), .unitStr(), .samples_per_record
const digital = try edf.getSample(record, channel, sample_idx);
const physical_uv = edf.toPhysical(channel, digital);

ERC (Ensemble Reservoir Computing)

var reservoir = erc.Cyton.init(.entropy_weighted);
const result = reservoir.processFromBandPowers(all_bands);
// result.trit, .confidence, .logits[3], .ensemble_entropy

// Online adaptation (NLMS — learning rate independent of feature scale)
const config = erc.LearningConfig{ .learning_rate = 0.5 };
const mse = reservoir.adaptFromBandPowers(all_bands, .plus, config);
// mse → convergence monitor; weights adapt to real EEG data

// Propagator integration
const cv = reservoir.toCellValue(); // → CellValue(f32)

LSL StreamSynchronizer

var sync = lsl.StreamSynchronizer.init();
const eeg_id = try sync.addStream(.{ .stream_type = .eeg, .nominal_rate = 300.0, ... });
// StreamType.trit(): eeg→0, fnirs→+1, eye_tracking→-1

SDF Verification (Ch1-Ch8)

SDF ChapterScoreEvidence
Ch1 Combinators (+1)★★★Composable parse→scale→classify pipeline
Ch2 DSL (-1)★★☆DSI-24 packet DSL, EDF header grammar
Ch3 Generic Arithmetic (0)★★☆Trit type generic across all modalities
Ch4 Pattern Matching (+1)★★★Packet type dispatch, IVT event classification
Ch6 Layering (+1)★★☆Physical/digital layers in EDF, metadata in LSL
Ch7 Propagators (0)★★★Full EEG→FFT→Cell→neurofeedback_gate pipeline, lattice contradiction detection
Ch8 Degeneracy (-1)★★★LSL software fallback, pose threshold redundancy

Additive Design: ✓

New modalities added without modifying existing modules. Each sensor is a

SensorConfig
struct registered in
UniversalReceiver.init()
.

Abstraction Barriers: ✓

Three clear layers: acquisition (parsers) → processing (mBLL/IVT/FFT) → classification (trit).

gx10 Deployment

Validated on 4x NVIDIA GB10 nodes (aarch64-linux, 128GB unified memory each):

# Install zig on gx10 node
curl -sL -o /tmp/zig.tar.xz 'https://ziglang.org/download/0.15.2/zig-aarch64-linux-0.15.2.tar.xz'
mkdir -p ~/.local && tar xf /tmp/zig.tar.xz -C ~/.local/
ln -sf ~/.local/zig-aarch64-linux-0.15.2/zig ~/.local/bin/zig

# Clone and test
git clone -b feat/bci-multimodal-pipeline https://github.com/plurigrid/zig-syrup.git
cd zig-syrup && zig build test-bci

gx10 BCI Use Cases

  • Headless BCI acquisition server: Run LSL bridge + EDF writer on idle nodes
  • Cross-compile target: Native aarch64 build, same arch as embedded targets
  • Parallel dataset processing: Parse/classify large EDF archives across 4 nodes
  • LoLa integration: BCI trit streams as input features for autoencoder training

Related Skills

SkillTritRelation
sdf
-1SDF verification framework
zig
-1Zig ecosystem patterns
zig-syrup-propagator-interleave
-1Propagator network bridge
reafference-corollary-discharge
+1Corollary discharge → neurofeedback gate
bci-colored-operad
+1Operadic composition of BCI channels
sheaf-cohomology-bci
0Sheaf-theoretic BCI signal fusion

GF(3) Triads

zig-syrup-bci(0) ⊗ sdf(-1) ⊗ bci-colored-operad(+1) = 0 ✓
zig-syrup-bci(0) ⊗ edf-reader(-1) ⊗ fnirs-processor(+1) = 0 ✓

PR

https://github.com/plurigrid/zig-syrup/pull/2