Twu31 commited on
Commit
aaa76e5
·
verified ·
1 Parent(s): 4993704

Initial release: 5 MI sessions, 5 calibrator recordings, loader, reports

Browse files
.gitattributes CHANGED
@@ -58,3 +58,11 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
58
  # Video files - compressed
59
  *.mp4 filter=lfs diff=lfs merge=lfs -text
60
  *.webm filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
58
  # Video files - compressed
59
  *.mp4 filter=lfs diff=lfs merge=lfs -text
60
  *.webm filter=lfs diff=lfs merge=lfs -text
61
+ data/mi/cap32_20260722_135310_raw.fif filter=lfs diff=lfs merge=lfs -text
62
+ data/mi/cap32_20260725_135441_mi_raw.fif filter=lfs diff=lfs merge=lfs -text
63
+ data/mi/cap32_20260725_143756_hands-rest_raw.fif filter=lfs diff=lfs merge=lfs -text
64
+ data/mi/cap32_20260725_163251_hands-feet-math_raw.fif filter=lfs diff=lfs merge=lfs -text
65
+ docs/crosstalk_report.pdf filter=lfs diff=lfs merge=lfs -text
66
+ docs/crosstalk_report_zh.pdf filter=lfs diff=lfs merge=lfs -text
67
+ docs/hardware_acceptance.pdf filter=lfs diff=lfs merge=lfs -text
68
+ docs/mi_pilot_report.pdf filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,247 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-4.0
3
+ language:
4
+ - en
5
+ - zh
6
+ tags:
7
+ - eeg
8
+ - motor-imagery
9
+ - brain-computer-interface
10
+ - bci
11
+ - dry-electrode
12
+ - ads1299
13
+ - biosignal
14
+ pretty_name: "cap32 — 32-channel dry-electrode motor imagery EEG"
15
+ size_categories:
16
+ - n<1K
17
+ task_categories:
18
+ - time-series-forecasting
19
+ ---
20
+
21
+ # cap32 — 32-channel dry-electrode motor imagery EEG
22
+
23
+ One subject, one low-cost 32-channel dry-electrode cap (TI ADS1299, 250 Hz, WiFi/UDP).
24
+ Motor imagery and cognitive-task sessions, plus a set of calibrator recordings used to
25
+ characterise the amplifier.
26
+
27
+ Code, analysis and reports: **[github.com/twu3202/EEG_MI](https://github.com/twu3202/EEG_MI)**
28
+
29
+ > **Read §4 before analysing.** Two of the five MI sessions have defects that change what
30
+ > you can conclude from them, and they are not visible in the file itself.
31
+
32
+ ---
33
+
34
+ ## 1. Quick start
35
+
36
+ ```python
37
+ from load_cap32 import load, epochs, to_mne
38
+
39
+ rec = load("data/mi/cap32_20260725_163251_hands-feet-math.npz")
40
+ X, y, t = epochs(rec, tmin=-1.0, tmax=4.0) # (75, 32, 1250) µV, relative to imagery onset
41
+ print(X.shape, set(y)) # {'hands', 'feet', 'math'}
42
+
43
+ raw = to_mne(rec) # or read the paired _raw.fif directly
44
+ raw.info["bads"] = ["F7"] # see §4.3
45
+ raw.filter(1., 40.).notch_filter(50.).set_eeg_reference("average")
46
+ ```
47
+
48
+ Pure MNE:
49
+
50
+ ```python
51
+ import mne
52
+ raw = mne.io.read_raw_fif("data/mi/cap32_20260725_163251_hands-feet-math_raw.fif", preload=True)
53
+ events, event_id = mne.events_from_annotations(raw)
54
+ ep = mne.Epochs(raw, events, event_id, tmin=-1., tmax=4., baseline=(-1., 0.))
55
+ ```
56
+
57
+ `python load_cap32.py` summarises every session. The loader needs only numpy (MNE optional).
58
+
59
+ ## 2. Hardware and montage
60
+
61
+ | | |
62
+ |---|---|
63
+ | Amplifier | TI ADS1299, 24 bit, gain 24 |
64
+ | Scaling | `µV = counts × 0.02235`; full scale ±187500 µV |
65
+ | Sampling | 250 Hz |
66
+ | Electrodes | dry, 32 channels |
67
+ | Reference | on-board floating reference (**not** re-referenced in these files) |
68
+ | Transport | WiFi UDP, 105-byte frames with a 1-byte sequence counter |
69
+
70
+ Channel order (the row order of `data`):
71
+
72
+ ```
73
+ FP1 FP2 AF3 AF4 F3 F4 F7 F8 FC1 FC2 FC5 FC6 C3 C4 T7 T8
74
+ CP1 CP2 CP5 CP6 P3 P4 P7 P8 PO3 PO4 O1 O2 FZ CZ PZ OZ
75
+ ```
76
+
77
+ **The signal is raw: unfiltered, not re-referenced, in µV.** The CAR and 1–40 Hz band-pass
78
+ shown in the acquisition GUI affect the display only and are never written to disk, so you
79
+ choose the preprocessing. Dry electrodes drift hard — high-pass at 0.5–1 Hz before looking
80
+ at anything.
81
+
82
+ ## 3. File format
83
+
84
+ ### `data/mi/*.npz` — the complete source
85
+
86
+ | key | dtype | shape | meaning |
87
+ |---|---|---|---|
88
+ | `data` | float32 | (32, N) | raw µV, unfiltered, pre-CAR |
89
+ | `fs` | float64 | () | 250.0 |
90
+ | `ch_names` | U3 | (32,) | the order above |
91
+ | `marker` | int32 | (N,) | **primary label track**; the task code at imagery onset, 0 elsewhere |
92
+ | `trigger` | int32 | (N,) | hardware trigger echo (redundant path; all-zero when the firmware does not echo) |
93
+ | `gap` | int8 | (N,) | 1 = this sample was linearly interpolated across a dropped UDP frame — **not EEG** |
94
+ | `trial_*` | | (n_trials,) | trial table: `index/code/name/onset/cue_onset/end`, in sample indices |
95
+ | `meta_json` | str | () | full snapshot of paradigm, timing, link statistics, acquisition settings |
96
+ | `format_version` | int64 | () | 2 (with trial table); the two earliest recordings lack this field |
97
+
98
+ Prefer the trial table over the label track — it also records where the cue ended and
99
+ imagery began.
100
+
101
+ ### `data/mi/*_raw.fif` — MNE version
102
+
103
+ Same signal in volts, with the `standard_1020` montage and task names as annotations.
104
+ **It does not carry the `gap` track** — go back to the npz to exclude interpolated samples.
105
+
106
+ ### `data/mi/*.json` — sidecar
107
+
108
+ A readable copy of `meta_json`, so paradigm and link stats can be inspected without opening
109
+ the npz.
110
+
111
+ ### Task codes
112
+
113
+ | code | name | kind | | code | name | kind |
114
+ |---|---|---|---|---|---|---|
115
+ | 1 | rest | rest | | 10 | math | cognitive (serial subtraction by 7) |
116
+ | 2 | left | motor (left hand) | | 11 | words | cognitive (word association) |
117
+ | 3 | right | motor (right hand) | | 12 | song | cognitive (auditory imagery) |
118
+ | 4 | feet | motor (both feet) | | 13 | navigate | cognitive (spatial navigation) |
119
+ | 5 | tongue | motor (tongue) | | 14 | rotation | cognitive (mental rotation) |
120
+ | 6 | hands | motor (both hands) | | 15 | face | cognitive (familiar face) |
121
+
122
+ Only `left / right / hands / rest / feet / math` actually occur here.
123
+
124
+ ### Trial timing
125
+
126
+ Four-phase state machine, 9.0 s per trial: `fixation 1.5 → cue 1.5 → imagery 4.0 → rest 2.0`.
127
+ `trial_onset` points at **imagery onset**; `trial_cue_onset` at cue onset. Imagery was
128
+ kinesthetic (imagine the *feeling* of moving, not watching yourself move).
129
+
130
+ ## 4. Known issues — please read all of these
131
+
132
+ ### 4.1 The hands-rest session has only 19 usable trials
133
+
134
+ `cap32_20260725_143756_hands-rest` lists 50 trials. **Only 19 are real.**
135
+
136
+ The acquisition socket had no timeout, so when the board stopped sending, `recvfrom` blocked
137
+ forever and the reader thread died silently. The paradigm kept running, and trials 20–50 were
138
+ all logged at the same frozen sample index (the end of the file). They are kept in the table
139
+ for provenance but carry no signal.
140
+
141
+ `valid_trials()` in the loader filters them; never use `len(trials)`. (A 2 s watchdog with
142
+ auto-reconnect fixed this afterwards; later sessions are unaffected.)
143
+
144
+ ### 4.2 The left/right session has a visual confound
145
+
146
+ During `cap32_20260725_135441_mi`, a countdown digit on screen changed four times *during*
147
+ the imagery window. The result: **the only significant effect in the whole session was
148
+ occipital 13–30 Hz (+46 %, p = 0.023)** — that is the digit, not motor imagery. Central
149
+ channels showed nothing (p = 0.41).
150
+
151
+ Usable for studying visual/artifact responses; **not usable for evaluating MI decoding**.
152
+ Later sessions keep the countdown inside the cue phase and hold the imagery screen static.
153
+
154
+ ### 4.3 F7 is an intermittent open circuit
155
+
156
+ F7 is flagged bad in all four sessions here. But it worked in a separate SSVEP test and has
157
+ gone green in impedance checks — so this is **a connector/lead fault, not scalp contact**.
158
+
159
+ Treat F7 as a bad channel (interpolate or drop), but not as a permanently dead electrode.
160
+ `cap32_20260722_135310` additionally has FC1 / O2 / OZ bad.
161
+
162
+ ### 4.4 The subject was MI-naive
163
+
164
+ This affects interpretation: for an untrained subject, **the urge to suppress actual movement
165
+ plausibly dominated the motor imagery itself**. Both engage somatotopically organised
166
+ sensorimotor cortex, so this offline data **cannot separate** the two. Do not read any
167
+ hands-vs-feet effect here as pure motor imagery.
168
+
169
+ ### 4.5 Interpolated samples
170
+
171
+ `gap == 1` marks linear interpolation, not measurement. Per session: hands-rest 84 samples
172
+ (0.198 %, 3 bursts, longest 40 frames = 160 ms); all others 0.
173
+
174
+ Interpolating rather than skipping is deliberate — silently dropping missing frames compresses
175
+ the time axis and shifts every downstream latency and frequency estimate. Exclude affected
176
+ trials when epoching (the loader does by default), or at least know that you did not.
177
+
178
+ ## 5. Sessions
179
+
180
+ | file | duration | tasks | usable trials | bad channels | frame loss |
181
+ |---|---|---|---|---|---|
182
+ | `cap32_20260721_224212` | 1 s | — | — | — | — |
183
+ | `cap32_20260722_135310` | 31 s | — | — | F7, FC1, O2, OZ | — |
184
+ | `cap32_20260725_135441_mi` | 270 s | left / right | 30 (15+15) | F7 | 0.108 % |
185
+ | `cap32_20260725_143756_hands-rest` | 170 s | hands / rest | **19** of 50 | F7 | 0.308 % |
186
+ | `cap32_20260725_163251_hands-feet-math` | 675 s | hands / feet / math | 75 (25×3) | F7 | 0.045 % |
187
+
188
+ `sessions.csv` is the machine-readable version.
189
+
190
+ ## 6. Calibrator recordings
191
+
192
+ `data/calibrator/` holds the amplifier characterisation: the cap off the head, an external
193
+ generator's ground tied to board GND and REF, and a 7 Hz sine driven into **one** channel
194
+ input with every other input left open.
195
+
196
+ | file | driven | rate | duration |
197
+ |---|---|---|---|
198
+ | `cal_7hz_180s.npz` | CH29 (FZ), VHDCI pin 31 | 250 Hz | 179 s |
199
+ | `cal_7hz_fp1_250sps_180s.npz` | CH1 (FP1), VHDCI pin 2 | 250 Hz | 180 s |
200
+ | `cal_7hz_fp1_1000sps_180s.npz` | CH1 (FP1), VHDCI pin 2 | 1000 Hz | 180 s |
201
+ | `cal_7hz_xt7hz_60s.npz`, `cal_7hz_probe11s.npz` | CH29 (FZ) | 250 Hz | 59 s, 11 s |
202
+
203
+ Two things to know before using them. First, an open ADS1299 input rails: 25–28 of the 32
204
+ channels sit pinned at +187500 µV and carry **no information at all**. Second, the tone is at
205
+ **7.0226 Hz, not 7.000** — fitting the nominal frequency over a long record averages a steady
206
+ 24.5 µV tone down to 0.31 µV.
207
+
208
+ The terminated channel is a clean characterisation of the front end: 0.092 µV rms
209
+ (20–45 Hz), THD 0.22 %, 50 Hz at 0.0045 µV, and the two driven electrodes agree on amplitude
210
+ to 0.05 %. No crosstalk was detectable into any other channel; the measurement bounds it at
211
+ −24 dB, a bound set by the *open* inputs' noise rather than by the amplifier.
212
+ Full analysis in `docs/crosstalk_report.pdf`.
213
+
214
+ ## 7. What has been found so far
215
+
216
+ From `docs/mi_pilot_report.pdf`:
217
+
218
+ - **left vs right is not decodable** (p = 0.41). A dry cap does not resolve C3 vs C4 finely
219
+ enough, and that session also carried the visual confound in §4.2.
220
+ - **hands vs rest is decodable**, AUC 0.83–0.87 (n = 19, breadth search over 115
221
+ channel × band × pipeline combinations). An earlier 0.90 in the report was best-of-5-bands
222
+ selection bias and is corrected there.
223
+ - **hands vs feet separates in mu (8–13 Hz) on 17 central+frontal channels**, AUC 0.704,
224
+ p = 0.040. Exploratory and selection-biased; turning it into a trustworthy result needs a
225
+ pre-registered re-recording.
226
+ - **Seven EEG foundation models all lost to the classical pipeline** (CSP / Riemannian
227
+ tangent space + LR, 0.790). The initially top-ranked BENDR (0.733) was an artifact of zero
228
+ padding — it scored 0.303 once the input was fixed. A representation-health gate (padding
229
+ fraction, channel coverage, centred variation ratio, effective rank) now runs before any
230
+ probe score is trusted.
231
+
232
+ ## 8. Citation and license
233
+
234
+ CC BY 4.0. If you use this data, please link back to
235
+ [github.com/twu3202/EEG_MI](https://github.com/twu3202/EEG_MI).
236
+
237
+ ```bibtex
238
+ @misc{cap32_mi_eeg_2026,
239
+ title = {cap32: 32-channel dry-electrode motor imagery EEG},
240
+ author = {Twu},
241
+ year = {2026},
242
+ url = {https://huggingface.co/datasets/Twu31/cap32-mi-eeg}
243
+ }
244
+ ```
245
+
246
+ Recordings are from a single consenting adult subject (the author), released deliberately.
247
+ No clinical or identifying information is included.
data/calibrator/cal_7hz_180s.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aea9e6081dfe7c6296a379288a478fdf395d77654978409574d57fc17c7fa9ca
3
+ size 1210398
data/calibrator/cal_7hz_fp1_1000sps_180s.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:23a40924d3ecada6372860c95feac7f4f5cc53350a9888a95291991b9c2b1b4f
3
+ size 2736880
data/calibrator/cal_7hz_fp1_250sps_180s.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e48587910a599cf10841f6272d3e2b85391dc930cac422211390f6864ff22ef5
3
+ size 676218
data/calibrator/cal_7hz_probe11s.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1c62e9d95b16ac5e944365266715aa17b25046cb667259fe218343dfed91a42a
3
+ size 80581
data/calibrator/cal_7hz_xt7hz_60s.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:152a2eacff3e17b7638dd60da765e25dea34b0617d48a05601f63154b711572d
3
+ size 400591
data/mi/cap32_20260721_224212.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:282af146a8ba758809c88440f7fda394d3cb6565e686f6974ce1004864280f18
3
+ size 23646
data/mi/cap32_20260721_224212_raw.fif ADDED
Binary file (28.5 kB). View file
 
data/mi/cap32_20260722_135310.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:72b41f79bd33bd1e2eed88a15befb2a5bbf4b891bd4a9e0676d43fdf6f199e15
3
+ size 726089
data/mi/cap32_20260722_135310_raw.fif ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8ba1c866f9e1a0e70771e9eb265773837b5c9427a3eb88df0924a4ae55e378f9
3
+ size 998640
data/mi/cap32_20260725_135441_mi.json ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "paradigm": {
3
+ "kind": "motor-imagery",
4
+ "tasks": [
5
+ "left",
6
+ "right"
7
+ ],
8
+ "reps": 15,
9
+ "imagery_mode": "kinesthetic",
10
+ "sequence": [
11
+ "left",
12
+ "right",
13
+ "left",
14
+ "left",
15
+ "right",
16
+ "right",
17
+ "left",
18
+ "left",
19
+ "right",
20
+ "left",
21
+ "left",
22
+ "right",
23
+ "right",
24
+ "right",
25
+ "left",
26
+ "left",
27
+ "left",
28
+ "right",
29
+ "left",
30
+ "right",
31
+ "right",
32
+ "right",
33
+ "right",
34
+ "right",
35
+ "right",
36
+ "right",
37
+ "left",
38
+ "left",
39
+ "left",
40
+ "left"
41
+ ],
42
+ "timing": {
43
+ "fixation": 1.5,
44
+ "cue": 1.5,
45
+ "imagery": 4.0,
46
+ "rest": 2.0
47
+ }
48
+ },
49
+ "acquisition": {
50
+ "source": "udp",
51
+ "host": "192.168.4.1",
52
+ "port": 8086,
53
+ "sfreq": 250.0,
54
+ "car": true,
55
+ "deblink": false,
56
+ "display_filter": {
57
+ "low": "1",
58
+ "high": "40",
59
+ "notch50": true
60
+ },
61
+ "channels": [
62
+ "FP1",
63
+ "FP2",
64
+ "AF3",
65
+ "AF4",
66
+ "F3",
67
+ "F4",
68
+ "F7",
69
+ "F8",
70
+ "FC1",
71
+ "FC2",
72
+ "FC5",
73
+ "FC6",
74
+ "C3",
75
+ "C4",
76
+ "T7",
77
+ "T8",
78
+ "CP1",
79
+ "CP2",
80
+ "CP5",
81
+ "CP6",
82
+ "P3",
83
+ "P4",
84
+ "P7",
85
+ "P8",
86
+ "PO3",
87
+ "PO4",
88
+ "O1",
89
+ "O2",
90
+ "FZ",
91
+ "CZ",
92
+ "PZ",
93
+ "OZ"
94
+ ],
95
+ "dead_channels": []
96
+ },
97
+ "link": {
98
+ "frames_received": 73760,
99
+ "frames_lost": 80,
100
+ "loss_pct": 0.108,
101
+ "samples_filled": 0
102
+ },
103
+ "n_filled_samples": 0,
104
+ "filled_pct": 0.0,
105
+ "format_version": 2,
106
+ "saved": "20260725_135441",
107
+ "n_samples": 67459,
108
+ "n_channels": 32,
109
+ "sfreq": 250.0,
110
+ "n_trials": 30,
111
+ "duration_s": 269.84,
112
+ "units": "microvolts",
113
+ "notes": "RAW µV, pre-CAR, unfiltered"
114
+ }
data/mi/cap32_20260725_135441_mi.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:800059aefa9c2ae07f7284d5098045a2af46cf2fce7ef7328bfb6f4f0a5f8562
3
+ size 5699057
data/mi/cap32_20260725_135441_mi_raw.fif ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f9608e0aa7f62bd1772300f39588acbd4f6a88fb0407107cdeb62ea54f2f65c1
3
+ size 8644932
data/mi/cap32_20260725_143756_hands-rest.json ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "paradigm": {
3
+ "kind": "motor-imagery",
4
+ "tasks": [
5
+ "hands",
6
+ "rest"
7
+ ],
8
+ "reps": 25,
9
+ "imagery_mode": "kinesthetic",
10
+ "sequence": [
11
+ "hands",
12
+ "rest",
13
+ "rest",
14
+ "rest",
15
+ "hands",
16
+ "hands",
17
+ "hands",
18
+ "rest",
19
+ "rest",
20
+ "rest",
21
+ "hands",
22
+ "hands",
23
+ "hands",
24
+ "hands",
25
+ "rest",
26
+ "rest",
27
+ "rest",
28
+ "hands",
29
+ "hands",
30
+ "hands",
31
+ "rest",
32
+ "hands",
33
+ "hands",
34
+ "hands",
35
+ "rest",
36
+ "hands",
37
+ "rest",
38
+ "rest",
39
+ "hands",
40
+ "rest",
41
+ "rest",
42
+ "rest",
43
+ "rest",
44
+ "rest",
45
+ "rest",
46
+ "hands",
47
+ "rest",
48
+ "rest",
49
+ "hands",
50
+ "rest",
51
+ "rest",
52
+ "hands",
53
+ "hands",
54
+ "hands",
55
+ "hands",
56
+ "rest",
57
+ "hands",
58
+ "hands",
59
+ "rest",
60
+ "hands"
61
+ ],
62
+ "timing": {
63
+ "fixation": 1.5,
64
+ "cue": 1.5,
65
+ "imagery": 4.0,
66
+ "rest": 2.0
67
+ }
68
+ },
69
+ "acquisition": {
70
+ "source": "udp",
71
+ "host": "192.168.4.1",
72
+ "port": 8086,
73
+ "sfreq": 250.0,
74
+ "car": true,
75
+ "deblink": false,
76
+ "display_filter": {
77
+ "low": "1",
78
+ "high": "40",
79
+ "notch50": true
80
+ },
81
+ "channels": [
82
+ "FP1",
83
+ "FP2",
84
+ "AF3",
85
+ "AF4",
86
+ "F3",
87
+ "F4",
88
+ "F7",
89
+ "F8",
90
+ "FC1",
91
+ "FC2",
92
+ "FC5",
93
+ "FC6",
94
+ "C3",
95
+ "C4",
96
+ "T7",
97
+ "T8",
98
+ "CP1",
99
+ "CP2",
100
+ "CP5",
101
+ "CP6",
102
+ "P3",
103
+ "P4",
104
+ "P7",
105
+ "P8",
106
+ "PO3",
107
+ "PO4",
108
+ "O1",
109
+ "O2",
110
+ "FZ",
111
+ "CZ",
112
+ "PZ",
113
+ "OZ"
114
+ ],
115
+ "dead_channels": []
116
+ },
117
+ "link": {
118
+ "frames_received": 53040,
119
+ "frames_lost": 164,
120
+ "loss_pct": 0.308,
121
+ "samples_filled": 84
122
+ },
123
+ "n_filled_samples": 84,
124
+ "filled_pct": 0.1976,
125
+ "format_version": 2,
126
+ "saved": "20260725_143756",
127
+ "n_samples": 42520,
128
+ "n_channels": 32,
129
+ "sfreq": 250.0,
130
+ "n_trials": 50,
131
+ "duration_s": 170.08,
132
+ "units": "microvolts",
133
+ "notes": "RAW µV, pre-CAR, unfiltered"
134
+ }
data/mi/cap32_20260725_143756_hands-rest.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:da7ca19a73d718ddd3fddf9900039a323ac293e2977e131ce1be826951cb7e2f
3
+ size 3591751
data/mi/cap32_20260725_143756_hands-rest_raw.fif ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:629b16d53c827f8b712f10461bc5529724b865c9ac69503322bd4a8b3f5f7ce7
3
+ size 5450964
data/mi/cap32_20260725_163251_hands-feet-math.json ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "paradigm": {
3
+ "kind": "motor-imagery",
4
+ "tasks": [
5
+ "hands",
6
+ "feet",
7
+ "math"
8
+ ],
9
+ "reps": 25,
10
+ "imagery_mode": "kinesthetic",
11
+ "sequence": [
12
+ "math",
13
+ "math",
14
+ "hands",
15
+ "feet",
16
+ "math",
17
+ "math",
18
+ "math",
19
+ "feet",
20
+ "feet",
21
+ "hands",
22
+ "math",
23
+ "feet",
24
+ "hands",
25
+ "feet",
26
+ "feet",
27
+ "math",
28
+ "math",
29
+ "feet",
30
+ "math",
31
+ "feet",
32
+ "hands",
33
+ "hands",
34
+ "feet",
35
+ "hands",
36
+ "feet",
37
+ "math",
38
+ "math",
39
+ "feet",
40
+ "math",
41
+ "hands",
42
+ "hands",
43
+ "math",
44
+ "hands",
45
+ "feet",
46
+ "feet",
47
+ "math",
48
+ "feet",
49
+ "feet",
50
+ "hands",
51
+ "hands",
52
+ "feet",
53
+ "feet",
54
+ "math",
55
+ "feet",
56
+ "math",
57
+ "math",
58
+ "hands",
59
+ "feet",
60
+ "feet",
61
+ "hands",
62
+ "hands",
63
+ "hands",
64
+ "hands",
65
+ "math",
66
+ "math",
67
+ "math",
68
+ "feet",
69
+ "hands",
70
+ "math",
71
+ "hands",
72
+ "hands",
73
+ "hands",
74
+ "math",
75
+ "math",
76
+ "math",
77
+ "feet",
78
+ "feet",
79
+ "hands",
80
+ "hands",
81
+ "math",
82
+ "feet",
83
+ "hands",
84
+ "hands",
85
+ "hands",
86
+ "feet"
87
+ ],
88
+ "timing": {
89
+ "fixation": 1.5,
90
+ "cue": 1.5,
91
+ "imagery": 4.0,
92
+ "rest": 2.0
93
+ }
94
+ },
95
+ "acquisition": {
96
+ "source": "udp",
97
+ "host": "192.168.4.1",
98
+ "port": 8086,
99
+ "sfreq": 250.0,
100
+ "car": true,
101
+ "deblink": false,
102
+ "display_filter": {
103
+ "low": "1",
104
+ "high": "40",
105
+ "notch50": true
106
+ },
107
+ "channels": [
108
+ "FP1",
109
+ "FP2",
110
+ "AF3",
111
+ "AF4",
112
+ "F3",
113
+ "F4",
114
+ "F7",
115
+ "F8",
116
+ "FC1",
117
+ "FC2",
118
+ "FC5",
119
+ "FC6",
120
+ "C3",
121
+ "C4",
122
+ "T7",
123
+ "T8",
124
+ "CP1",
125
+ "CP2",
126
+ "CP5",
127
+ "CP6",
128
+ "P3",
129
+ "P4",
130
+ "P7",
131
+ "P8",
132
+ "PO3",
133
+ "PO4",
134
+ "O1",
135
+ "O2",
136
+ "FZ",
137
+ "CZ",
138
+ "PZ",
139
+ "OZ"
140
+ ],
141
+ "dead_channels": []
142
+ },
143
+ "link": {
144
+ "frames_received": 177560,
145
+ "frames_lost": 80,
146
+ "loss_pct": 0.045,
147
+ "samples_filled": 0,
148
+ "stalls": []
149
+ },
150
+ "n_filled_samples": 0,
151
+ "filled_pct": 0.0,
152
+ "format_version": 2,
153
+ "saved": "20260725_163251",
154
+ "n_samples": 168776,
155
+ "n_channels": 32,
156
+ "sfreq": 250.0,
157
+ "n_trials": 75,
158
+ "duration_s": 675.1,
159
+ "units": "microvolts",
160
+ "notes": "RAW µV, pre-CAR, unfiltered"
161
+ }
data/mi/cap32_20260725_163251_hands-feet-math.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ada910f1f6f3c1a0014a1cebc067eb907b30539869640ebeba9e45ed11d2a907
3
+ size 14444714
data/mi/cap32_20260725_163251_hands-feet-math_raw.fif ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fb53aff81563ccfb42ecbff78cbe321b0f1ed5df413efdbb632599ded7ad050f
3
+ size 21620779
docs/crosstalk_report.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:35f2f32998a6be07cc2609fb35fac2b1664b780dec4d9f0bfd0e5c37d1544f39
3
+ size 928596
docs/crosstalk_report_zh.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8c1cbeb19e862e59582581c4c9e7ed6e0d0160dbc525d42eb35b7422a585d98a
3
+ size 1154873
docs/hardware_acceptance.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8c7e95c8d687abe7eacea4a5e9e5b6b52328956e060fd22458ff15a4071adaa6
3
+ size 881721
docs/mi_pilot_report.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f60db53b28fc4bce09da30003c195eb5cccbf5e114c8d9c2d9e5a347bf3625ee
3
+ size 577680
load_cap32.py ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ """Standalone loader for the cap32 recordings — numpy only, no project code needed.
3
+
4
+ Everything you need is in the .npz: raw µV, the per-sample label track, the trial table,
5
+ and the gap track that says which samples were reconstructed after a UDP drop. The paired
6
+ _raw.fif is the same signal in MNE's format with the task labels as annotations, for people
7
+ who would rather start from `mne.io.read_raw_fif`.
8
+
9
+ python load_cap32.py # summarise every session
10
+ python load_cap32.py data/mi/cap32_20260725_163251_hands-feet-math.npz --epochs
11
+ """
12
+ from __future__ import annotations
13
+
14
+ import argparse
15
+ import json
16
+ from pathlib import Path
17
+
18
+ import numpy as np
19
+
20
+ HERE = Path(__file__).resolve().parent
21
+
22
+ # The paradigm writes these small integers into the `marker` track at imagery onset.
23
+ CODE_TO_LABEL = {1: "rest", 2: "left", 3: "right", 4: "feet", 5: "tongue", 6: "hands",
24
+ 10: "math", 11: "words", 12: "song", 13: "navigate", 14: "rotation",
25
+ 15: "face"}
26
+
27
+
28
+ def load(path):
29
+ """-> dict with data (n_ch, N) µV, fs, ch_names, marker/trigger/gap tracks, trials, meta."""
30
+ d = np.load(path, allow_pickle=True)
31
+ out = {k: d[k] for k in d.files if k != "meta_json"}
32
+ out["fs"] = float(d["fs"])
33
+ out["ch_names"] = [str(c) for c in d["ch_names"]]
34
+ out["meta"] = json.loads(str(d["meta_json"])) if "meta_json" in d.files else {}
35
+ if "trial_name" in d.files:
36
+ out["trials"] = [
37
+ dict(i=int(d["trial_index"][k]), name=str(d["trial_name"][k]),
38
+ code=int(d["trial_code"][k]), onset=int(d["trial_onset"][k]),
39
+ cue_onset=int(d["trial_cue_onset"][k]), end=int(d["trial_end"][k]))
40
+ for k in range(len(d["trial_name"]))
41
+ ]
42
+ return out
43
+
44
+
45
+ def valid_trials(rec):
46
+ """Trials whose imagery window actually exists in the data.
47
+
48
+ The 2026-07-25 hands-rest session hit a receiver stall: the acquisition thread blocked
49
+ on a socket with no timeout, so trials 20-50 were all logged at the same frozen sample
50
+ index (the end of the file). They are kept in the table for provenance but carry no
51
+ signal — filter with this, never with len(trials)."""
52
+ n = rec["data"].shape[1]
53
+ ts = rec.get("trials", [])
54
+ return [t for i, t in enumerate(ts)
55
+ if t["onset"] < n and (i == 0 or t["onset"] > ts[i - 1]["onset"])]
56
+
57
+
58
+ def epochs(rec, tmin=-1.0, tmax=4.0, drop_filled=True):
59
+ """-> X (n_trials, n_ch, n_times) µV, y (labels), times. Cut around imagery onset.
60
+
61
+ `drop_filled` removes trials that overlap samples reconstructed across a UDP drop —
62
+ those samples are linear interpolation, not EEG, and they are flagged in rec['gap']."""
63
+ fs, X, y = rec["fs"], [], []
64
+ lo, hi = int(round(tmin * fs)), int(round(tmax * fs))
65
+ gap = rec.get("gap")
66
+ for t in valid_trials(rec):
67
+ a, b = t["onset"] + lo, t["onset"] + hi
68
+ if a < 0 or b > rec["data"].shape[1]:
69
+ continue
70
+ if drop_filled and gap is not None and gap[a:b].any():
71
+ continue
72
+ X.append(rec["data"][:, a:b])
73
+ y.append(t["name"])
74
+ return np.asarray(X), np.asarray(y), np.arange(lo, hi) / fs
75
+
76
+
77
+ def to_mne(rec):
78
+ """-> mne.io.RawArray with the standard_1020 montage and task annotations."""
79
+ import mne
80
+ info = mne.create_info(rec["ch_names"], rec["fs"], "eeg")
81
+ raw = mne.io.RawArray(rec["data"] * 1e-6, info, verbose="ERROR") # MNE wants volts
82
+ raw.set_montage(mne.channels.make_standard_montage("standard_1020"),
83
+ match_case=False, on_missing="ignore")
84
+ ts = valid_trials(rec)
85
+ if ts:
86
+ raw.set_annotations(mne.Annotations(
87
+ onset=[t["onset"] / rec["fs"] for t in ts],
88
+ duration=[(t["end"] - t["onset"]) / rec["fs"] for t in ts],
89
+ description=[t["name"] for t in ts]))
90
+ return raw
91
+
92
+
93
+ def summarise(path):
94
+ rec = load(path)
95
+ n = rec["data"].shape[1]
96
+ tr, vt = rec.get("trials", []), valid_trials(rec)
97
+ gap = rec.get("gap")
98
+ print(f"\n{path.name}")
99
+ print(f" {rec['data'].shape[0]} ch × {n} samp = {n/rec['fs']:.0f} s @ {rec['fs']:.0f} Hz, µV")
100
+ if tr:
101
+ cnt = {}
102
+ for t in vt:
103
+ cnt[t["name"]] = cnt.get(t["name"], 0) + 1
104
+ print(f" trials: {len(vt)} usable of {len(tr)} logged {cnt}")
105
+ if len(vt) < len(tr):
106
+ print(f" ⚠ {len(tr)-len(vt)} trial(s) logged after the stream stalled — no signal")
107
+ if gap is not None and gap.any():
108
+ print(f" gap-filled: {int(gap.sum())} samp ({100*gap.mean():.3f} %) — interpolated, not EEG")
109
+ link = rec["meta"].get("link")
110
+ if link:
111
+ print(f" link: {link.get('loss_pct', 0):.3f} % frame loss")
112
+
113
+
114
+ def main():
115
+ ap = argparse.ArgumentParser(description=__doc__,
116
+ formatter_class=argparse.RawDescriptionHelpFormatter)
117
+ ap.add_argument("path", nargs="?", help="a .npz (default: summarise all)")
118
+ ap.add_argument("--epochs", action="store_true", help="also cut and report epochs")
119
+ a = ap.parse_args()
120
+ paths = [Path(a.path)] if a.path else sorted((HERE / "data" / "mi").glob("*.npz"))
121
+ for p in paths:
122
+ summarise(p)
123
+ if a.epochs:
124
+ X, y, t = epochs(load(p))
125
+ if len(X):
126
+ print(f" epochs: X {X.shape} y {dict(zip(*np.unique(y, return_counts=True)))}"
127
+ f" t [{t[0]:.1f}, {t[-1]:.1f}] s")
128
+
129
+
130
+ if __name__ == "__main__":
131
+ main()
sessions.csv ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ file,duration_s,n_samples,sfreq,n_channels,tasks,trials_logged,trials_usable,per_class,gap_samples,frame_loss_pct,format_version
2
+ cap32_20260721_224212,0.8,192,250,32,,0,0,,0,,1
3
+ cap32_20260722_135310,31.0,7757,250,32,,0,0,,0,,1
4
+ cap32_20260725_135441_mi,269.8,67459,250,32,left+right,30,30,left=15;right=15,0,0.108,2
5
+ cap32_20260725_143756_hands-rest,170.1,42520,250,32,hands+rest,50,19,hands=10;rest=9,84,0.308,2
6
+ cap32_20260725_163251_hands-feet-math,675.1,168776,250,32,hands+feet+math,75,75,feet=25;hands=25;math=25,0,0.045,2