Phasic← Overview

BDF and EDF

Reads:      .bdf, .edf
Writes:     .bdf only (BDF+C, 24-bit)
Requires:   (no feature flag)
Applies to: all channel kinds

BDF and EDF share one reader. They differ only in sample width — 24-bit for BDF, 16-bit for EDF — and the format is identified from the header’s first byte rather than the file extension, so a misnamed file still reads correctly.

Recordings are memory-mapped rather than loaded, so opening is near-instant regardless of file size: only the header is read up front.

What is supported

  • EDF, 16-bit, read only
  • BDF, 24-bit, read and write
  • EDF+ and BDF+ annotations, read from the file’s annotation channel
  • Heterogeneous per-channel sample rates, presented on a master grid
  • Truncated files — the number of records is derived from the file size rather than trusted from the header, so a partially-written recording opens with the records it has

Continuous (EDF+C/BDF+C) and unmarked files both load. Discontinuous files are refused — see below.

Discontinuous files are refused

EDF+D and BDF+D recordings are not supported and are rejected at load:

discontinuous recordings (EDF+D) are not supported: their data records carry
individual start times, and reading one as contiguous would place samples at the
wrong times.  Convert it to a continuous file first.

In a discontinuous file each data record carries its own start time and may sit anywhere on the timeline. Phasic lays records out contiguously, at record index multiplied by record duration, which is correct for EDF+C and wrong for EDF+D wherever a gap falls.

Reading one anyway would not fail — it would produce a plausible-looking timeline that is silently misaligned, and every analysis downstream would inherit the error. Refusing is the safer answer.

Convert the recording to a continuous file before opening it.

Files that are refused

Condition Message
Header declares no signals BDF header reports 0 signals
Only annotation or timestamp channels present no signal channels found in BDF/EDF (only annotation/timestamp channels present)
Header yields no positive sample rate BDF/EDF header yields no positive sample rate (record duration … s, … samples/record)
Not even one whole data record no data records found in BDF
Header shorter than the format requires reading BDF main header / reading BDF signal headers

The sample-rate gate matters: without it a record duration of zero would produce an infinite sampling interval and poison every time and every derived analysis downstream.

Where a file degrades quietly

These do not refuse the file, and are worth knowing about.

A degenerate digital range produces a flat channel — and says so. When a channel’s declared digital maximum and minimum differ by less than 1, its gain is set to zero and the channel decodes flat, rather than at the roughly 1e30 scaling the header literally implies.

The affected channels are named in File information:

⚠ 1 channel declares a degenerate digital range in the header and decodes flat: Fp1

This matters because a flattened channel is otherwise indistinguishable from one that genuinely recorded nothing — including in the channel-range table, where it shows a legitimate-looking zero range.

Malformed numeric header fields become zero rather than an error. A zero record duration is then caught by the sample-rate gate; other fields are not separately validated.

Empty channel names are accepted. A channel whose label is blank is kept as a signal channel.

Every annotation channel is read. EDF+ permits more than one, and a file uses the extra ones when a record’s events do not fit in a single channel. All are scanned and merged into one list ordered by onset, so an event’s channel does not affect where it appears.

Channels are excluded from the signal set when their label contains Annotations, or is exactly TimeStamp. Note the asymmetry: Annotations matches as a substring anywhere in the label, while TimeStamp must match exactly, including case.

Heterogeneous sample rates

A single BDF or EDF file may declare a different number of samples per record for each channel. Phasic accepts this and builds a master grid at the highest rate present, interpolating slower channels up to match.

  • Channels are only ever upsampled, never downsampled, so no aliasing is introduced
  • At the end of each record, the trailing master samples hold the record’s last native value rather than interpolating across the record boundary
  • The sample rate shown in the interface is the master rate, not any channel’s native rate

Export does not preserve native rates. Saving writes every channel on the master grid, so a recording combining 256 Hz EEG with 1 Hz SpO2 is written as a uniform 256 Hz file with the SpO2 channel interpolated. A native-rate-preserving round-trip is not yet implemented. Where per-channel rates must survive, use XDF.

Annotations

Annotations are read from the file’s annotation channel across the whole recording and sorted by onset. Each carries an onset, an optional duration and its text. The mandatory per-record timekeeping entries are skipped rather than presented as events.

Writing round-trips onsets, durations and text: annotations are placed into the record their onset falls in, and an annotation channel is always written even when the recording has none, because the format requires its timekeeping entries.

What writing produces

The writer emits BDF+C only — always continuous, always 24-bit, regardless of what the source was. Reading an EDF and saving it produces a BDF.

Two details are worth knowing:

Patient and recording identification are written as a literal X. No subject metadata is carried into the saved file.

Header numbers are truncated to eight characters to fit the format’s fixed-width fields, so a record duration with a long fractional part loses precision.

A recording written to BDF and read back returns the same physical values in microvolts; this round-trip is covered by the test suite.