edfcore: Reading EDF and BDF EEG recordings directly in TypeScript
I've been working with EDF recordings for EEG and neuroscience projects and kept running into the same problem: most mature EDF tooling assumes Python or native software, while there are comparatively few options for developers building directly in JavaScript or TypeScript.
So I built edfcore, an open-source, zero-dependency TypeScript library for reading EDF-family biosignal recordings directly in browser and Node.js applications.
Install:
npm install edfcore
It supports EDF, EDF+, BDF, and BDF+ and exposes signal samples, channel metadata, sampling information, physical units, annotations, and recording timelines programmatically.
A few parts of the format ended up being much stranger than I expected.
EDF doesn't actually have one global sampling rate. Every signal can contain a different number of samples per data record, meaning EEG at 256 Hz can coexist with a much slower physiological channel in the same recording.
EDF+ annotations are also encoded through a special signal channel rather than being ordinary metadata.
BioSemi BDF adds another issue: its samples are signed 24-bit integers. JavaScript provides convenient readers for 16-bit and 32-bit integers, but not 24-bit values, so those samples have to be reconstructed manually.
The reason I separated edfcore into its own package is that I don't want every browser EEG viewer, BCI application, or Node-based research tool to have to implement these details independently.
GitHub:
https://github.com/tayal-sarthak/edfcore
Documentation:
https://edfcore.vercel.app/
npm:
https://www.npmjs.com/package/edfcore
I also maintain edf2csv, a separate command-line tool for researchers who simply want EDF/BDF recordings converted into accessible CSV files:
https://github.com/tayal-sarthak/edf2csv
Both projects are MIT licensed.
I'd especially love feedback from anyone building browser-based EEG/BCI tools or anyone with unusual EDF/BDF recordings that would be useful for testing.
Comments
Sarthak,
Thanks for making this available to the community, via our Forum.
You can also make a post on the 'Community' section of the OpenBCI website. Instructions:
https://openbci.com/community/
https://docs.openbci.com/GettingStarted/Community/Community/
Regards, William
The time-window example in the README made me think of a viewer test. Give an EDF+D file two one-second records starting at 0 and 5 seconds, with an EEG channel at 256 Hz and a second channel at 1 Hz. Put a labelled event at the start of the second record. A six-second plot should put the event and the first sample from that second record together at 5 s on both traces, with a visible gap between records. An app can decode every sample correctly and still draw the second record at 1 s if it builds the x-axis from sample counts. Is there a small fixture like that you’d point viewer authors to for an end-to-end check?