write_EDF¶
- write_EDF(out_fname, header, signal_header, signal_cell, varargin)¶
WRITE_EDF Write an EDF / EDF+ file (with optional gzip or zstd output)
WRITE_EDF is the structural mirror of READ_EDF. It accepts the same header / signal_header / signal_cell / annotations shapes that READ_EDF returns, and produces a valid EDF or EDF+ file. Output is written via a compiled MEX (with zlib for .edf.gz and libzstd for .edf.zst) when available, or a pure MATLAB fallback otherwise.
- Usage:
write_EDF(out_fname, header, signal_header, signal_cell) write_EDF(out_fname, header, signal_header, signal_cell, annotations) write_EDF(…, ‘AutoScale’, ‘preserve’ | ‘recompute’, …) write_EDF(…, ‘GzipLevel’, 1..9, …) % only for .edf.gz write_EDF(…, ‘ZstdLevel’, 1..22, …) % only for .edf.zst
- Inputs:
- out_fnameoutput file path.
ends in ‘.gz’ -> gzipped output (zlib) ends in ‘.zst’ -> zstd output (libzstd) otherwise -> plain EDF
header : 1x1 struct (matches read_EDF’s first output) signal_header : 1xN struct array (matches read_EDF’s second output) signal_cell : 1xN cell array of physical-unit channel vectors annotations : Nx1 struct array of {onset, text} (optional, [] OK)
- Name-value pairs:
- ‘Channels’cell array of expression strings (default {}).
Same syntax as read_EDF’s ‘Channels’ — passthrough labels, ‘+’/’-‘/mean(…) expressions, aliased outputs (‘OUT = expr’), ‘$LABEL$’ escapes, and inline chaining via aliased outputs. When non- empty, the derivation pipeline runs over the provided (signal_header, signal_cell) before writing, and only the derived channels reach the file. See APPLY_CHANNEL_DERIVATIONS.
- ‘References’cell array of ‘NAME = expr’ strings (default {}).
Pre-baked intermediates available to ‘Channels’ expressions but not written to disk unless also listed in ‘Channels’.
‘Verbose’ : logical (default false) ‘forceMATLAB’ : logical (default false) ‘AutoScale’ : ‘preserve’ (default) -> keep existing physical_min/max
- ‘recompute’ -> set from data (lossless if data
fits within int16 dynamic range)
- ‘GzipLevel’integer 1..9 (default 6). Used only when out_fname
ends in ‘.gz’. Lower = faster, larger output.
- ‘ZstdLevel’integer 1..22 (default 9). Used only when out_fname
ends in ‘.zst’. Higher = slower, smaller output.
‘debug’ : logical (default false)
- Output naming:
If out_fname ends in ‘.gz’ (case-insensitive), the writer streams through zlib and produces a gzipped EDF on the fly. If it ends in ‘.zst’, the writer streams through libzstd. Otherwise plain EDF.
- AutoScale notes:
‘preserve’ is the default for write_EDF because the lower-level contract is “write what you were given.” It is required for lossless round-trip: read_EDF -> write_EDF reproduces the original file up to ~1 digital LSB per sample. ‘recompute’ resets each channel’s physical_min/max from the actual data range – use this when the input data may exceed the existing physical_min/max (e.g. after a resample’s anti-aliasing filter briefly produces out-of-range samples). Note: convert_EDF defaults to ‘recompute’ for exactly that reason.
See also: read_EDF, convert_EDF, batch_convert_EDF.