WFDB-x

A fast, lightweight implementation of the WFDB library and command-line tools, with identical behavior across seven programming languages

View the Project on GitHub alphanumericslab/wfdb-x

WFDB-x

A fast, lightweight implementation of the WFDB library and command-line tools, with identical behavior across seven programming languages

The WFDB Software Package (by George B. Moody and contributors) is the reference C library and set of command-line tools for reading, writing and converting physiologic signal and annotation files, such as the PhysioNet databases. WFDB-x is a faithful reimplementation of its version 10.7.0 in C++, Python, MATLAB/Octave, Rust, Julia, R and Kotlin, so that developers can use the same files, the same functions and the same tools without the C library.

WFDB-x is an independent project. It is not part of the WFDB project or of PhysioNet, and is not endorsed by them. It follows the WFDB format and the behavior of the original C package; see Related projects for the official WFDB software.

Each implementation:

The original C sources are kept, unmodified, in third_party/wfdb-main.zip, and serve as the reference implementation for testing.

WFDB-x at a glance

WFDB-x at a glance: everything the WFDB package does, in seven languages; how to install it and run it in each; how its results are checked against the original C programs; and what it adds

(Also as a PNG image: docs/overview.png.)

Why WFDB-x

For more than four decades, the WFDB Software Package has been the common ground of physiologic signal processing. PhysioNet distributes its databases in WFDB format, and these databases are among the most widely used in the field. Thousands of published studies, open-source tools and machine-learning benchmarks rest on what the WFDB library returns when it reads a record, and on what it writes.

Researchers work with these records in many languages. WFDB-x offers one behavior across seven of them: it takes a single specification, the original C package, and reimplements it in Python, C++, MATLAB/Octave, Rust, Julia, R and Kotlin, tested to be identical, byte for byte, to the original and to each other, for reading and for writing. A record read in Julia gives exactly the samples it gives in C++, and a file written in R is exactly the file the original tools write. Researchers can choose a language for their work, and move between languages, with the same results. The Kotlin implementation brings the same behavior to mobile applications (Android, and iOS through Kotlin Multiplatform) and to the JVM.

Deliberate differences from the original

WFDB-x behaves exactly as the original package, with a few deliberate exceptions. They are the same in all seven languages and tested like everything else:

docs/DIVERGENCES.md explains each difference and the reasons for it. Legacy mode reproduces the original package exactly, for reproducing old results: --legacy as the first argument of a tool, or the legacy option of the library and of the high-level functions.

What “identical behavior” means, and how it is checked

For the same input, a WFDB-x tool produces byte for byte the same standard output, standard error (including error messages), exit status and output files as the original C tool. The library functions return the same values as their C counterparts. (The exceptions are the deliberate divergences above; the reference results are produced by the C code with these changes applied, so they are tested in the same way.)

This is verified by tests whose expected results were produced by the original C code, not written by hand:

A few behaviors of the C code are undefined (crashes or reads of uninitialized memory), and many are surprising but well-defined. Both kinds are documented in docs/KNOWN_C_BEHAVIORS.md, with the behavior WFDB-x chose where C’s is undefined.

Implementations

All seven implement the complete library and all 33 tools (see docs/INVENTORY.md for the details). Each directory has a README with installation instructions, usage examples and requirements.

Language Directory and README Install (from a copy of this repository) Run a tool
Python python/ pip install wfdb-x (PyPI), or pip install ./python wfdbx rdsamp -r 100s
C++ cpp/ cmake -S cpp -B cpp/build && cmake --build cpp/build rdsamp -r 100s
MATLAB / GNU Octave matlab/ addpath('/path/to/wfdb-x/matlab') (tested with GNU Octave; MATLAB untested) wfdbx rdsamp -r 100s
Rust rust/ cargo install --path rust rdsamp -r 100s
Julia julia/ using Pkg; Pkg.develop(path="/path/to/wfdb-x/julia") wfdbx rdsamp -r 100s
R r/ R CMD INSTALL r wfdbx rdsamp -r 100s
Kotlin (Android, iOS, JVM) kotlin/ cd kotlin && ./gradlew publishToMavenLocal, then implementation("io.github.alphanumericslab:wfdbx:1.1.0") (Gradle, with mavenLocal()) kotlin/bin/wfdbx rdsamp -r 100s

Record 100s is the sample record in tests/data. Run the tools there, or point WFDBX_INPUT_DIR at that directory; the Python package also includes it (see python/README.md).

In Julia, R and MATLAB/Octave, wfdbx is a short alias for the language’s own launcher of the tools; each README shows how to set it up. The Python package is distributed on PyPI as wfdb-x, with example notebooks and a sample record (wfdbx --examples copies the notebooks). In code, the packages are named wfdbx (Python, MATLAB, Rust, R, Kotlin, and the C++ namespace) or WFDBX (Julia).

Three ways to use WFDB-x

Every language offers the same three ways in. They are written natively in the language, and none of them calls the C library or another language.

  What it is Use it for
1. The high-level API (recommended) A few functions in the idiom of the language: read_record, read_header, read_annotations, write_record, write_annotations and check_record (readRecord, … in Kotlin). One call reads a whole record or annotation file into arrays (NumPy, Vector, matrix, …), with named options, errors reported as exceptions or error values, and fast block reads. New code, analysis, notebooks, machine learning: anything that wants a record as arrays. It has no counterpart in the C package.
2. The WFDB library functions The C library API under its C names (isigopen, getvec, getann, putann, strtim, …), with the C behavior, frame by frame and annotation by annotation. Porting a program written against the C library, or processing a record as a stream with the exact C semantics.
3. The command-line tools The 33 tools (rdsamp, rdann, wrsamp, xform, …) with the options, output, messages and exit status of the C tools, implemented in each language. Shell scripts and pipelines, and reproducing work done with the original tools, without installing the C package.

The high-level API is built on the library functions, and returns exactly the samples and annotations that they (and the C library) give. The tools are built on the library functions too. Each language’s README shows all three; see the table under Implementations for how each language runs the tools.

Performance

docs/BENCHMARKS.md compares the speed and memory use of the seven implementations, of the original C library and tools, and of wfdb-python, on the same records and the same machine, verifies that they all give identical results, and explains how to get the most speed from WFDB-x in application code. In short:

Command-line tools

Signal and annotation tools from app/: rdsamp, wrsamp, rdann, wrann, sortann, ann2rr, rr2ann, wfdbdesc, wfdbtime, time2sec, sampfreq, signame, signum, sigamp, snip, xform, wfdbcat, wfdbwhich.

Format converters from convert/: edf2mit, mit2edf, rdedfann, wav2mit, mit2wav, wfdb2mat, a2m, m2a, ad2m, md2a, ahaecg2mit, makeid, readid, revise, parsescp.

The interactive viewer (WAVE), the plotting tools, and the analysis programs of psd/ are outside the scope of this project.

Documentation

How WFDB-x was developed

WFDB-x was built through AI-assisted development, cross-language verification and unit testing.

Reports of any difference from the original package are welcome as GitHub issues.

Versions

WFDB-x has its own version numbers, shared by the seven implementations and following semantic versioning; the current version is 1.1.0. They are independent of the version of the WFDB Software Package that WFDB-x implements, 10.7.0, which the library still reports as in C (wfdbversion() returns "10.7.0", and wfdberror() names it).

These projects and initiatives are related to WFDB-x, which does not use or depend on any of them. WFDB-x is a port of the original C package to other languages, and the C programs produce the expected results of its tests. The other projects are acknowledged as related work.

Authors and license

WFDB-x was developed by Reza Sameni (GitHub) (2026), through AI-assisted development, cross-language verification and unit testing (see How WFDB-x was developed). It is an independent reimplementation of the WFDB Software Package: its code in each language is a translation of the package’s C code, written for WFDB-x, not code by the original WFDB developers. The C library and tools were written by George B. Moody, Benjamin Moody and the other contributors credited, file by file, in each WFDB-x source file and in docs/AUTHORS.md.

WFDB-x is distributed under the GNU General Public License, version 3 or (at your option) any later version (LICENSE). The original C sources in third_party/ keep their own licenses: the GNU Library General Public License, version 2 or later, for the library, and the GNU General Public License, version 2 or later, for the tools.

The original WFDB Software Package is Copyright (C) 1983-2022 George B. Moody and the WFDB contributors.