Skip to main content

cfs2mat

PyPI version Python versions License: MIT

Convert CED Signal .cfs files to MATLAB .mat format with full metadata preservation.

CFS (CED Filing System) is the native binary format used by Cambridge Electronic Design's Signal software for sweep-based neurophysiology recordings (EMG, EEG, evoked potentials, etc.). This tool converts .cfs files into .mat files that can be loaded directly in MATLAB, preserving all channel metadata, sweep structure, events, and calibration info.

Prerequisites

cfs2mat uses biosig to read CFS files. The biosig Python package requires the libbiosig C library on your system:

# macOS
brew install biosig

# Linux (Debian/Ubuntu)
sudo apt install libbiosig-dev

# Linux (Fedora)
sudo dnf install biosig-devel

Installation

# With uv (recommended)
uv tool install cfs2mat

# With pip
pip install cfs2mat

CLI Usage

Convert files

# Single file
cfs2mat convert recording.cfs

# Multiple files / glob patterns
cfs2mat convert *.cfs
cfs2mat convert data/**/*.cfs

# Output to a specific directory
cfs2mat convert *.cfs -o converted/

# Store data flat (samples x channels) without sweep reshaping
cfs2mat convert recording.cfs --flat

# Quiet mode (no summary output)
cfs2mat convert recording.cfs -q

Inspect file metadata

# Human-readable summary
cfs2mat info recording.cfs

# Full header as JSON
cfs2mat info recording.cfs --json

Example info output:

File:       recording.cfs
Type:       CFS v6.06
Recorded:   2026-02-07 09:13:18.999991
Rate:       2000.00 Hz
Sweeps:     10
Samples:    8000 total (800/sweep)
Channels:   6
  [1] EMG1          unit=V     rate=2000.0 Hz  scale=0.000152588
  [2] EMG2          unit=V     rate=2000.0 Hz  scale=0.000152588
  [3] EMG3          unit=V     rate=2000.0 Hz  scale=0.000152588
  [4] EMG4          unit=V     rate=2000.0 Hz  scale=0.000152588
  [5] Marker        unit=s     rate=2000.0 Hz  scale=0.0005
  [6] Keyboard      unit=?     rate=2000.0 Hz  scale=1
Events:     9
  2026-02-07 09:14:02.592794      start of a new segment (after a break)
  ...

Python API

from cfs2mat import cfs_to_mat, read_cfs

# Convert to .mat (returns output path)
cfs_to_mat("recording.cfs")
cfs_to_mat("recording.cfs", mat_path="output.mat", flat=True)

# Read header + data without converting
header, data = read_cfs("recording.cfs")
# header: dict with all CFS metadata
# data: numpy array (samples x channels)

Output .mat Structure

The output .mat file can be loaded in MATLAB with load('recording.mat') and contains:

Data

Variable Shape Description
data (sweeps, samples_per_sweep, channels) Waveform data reshaped by sweep
data_flat (total_samples, channels) Same data, all sweeps concatenated

Recording metadata

Variable Description
sampling_rate Global sampling rate (Hz)
n_sweeps Number of sweeps
n_channels Number of channels
n_samples Total sample count
samples_per_sweep Samples per sweep
start_of_recording ISO timestamp string
file_type Format identifier (CFS)
file_version CFS version number

Channel metadata (arrays indexed by channel)

Variable Description
channel_labels Channel names (e.g. EMG1, Marker)
channel_units Physical units (V, s, etc.)
channel_sampling_rates Per-channel sampling rate
channel_scaling Scale factor
channel_offset Offset value
channel_physical_max/min Physical range
channel_digital_max/min Digital range

Events

Variable Description
event_types Event type codes
event_positions Event positions (seconds)
event_timestamps ISO timestamp per event
event_descriptions Human-readable event labels

Other

Variable Description
patient_id, patient_gender Patient demographics
manufacturer Device manufacturer string
header_json Complete original CFS header as a JSON string

MATLAB Example

d = load('recording.mat');

% Plot first sweep, first channel
plot(squeeze(d.data(1, :, 1)));
title(d.channel_labels{1});
ylabel(d.channel_units{1});
xlabel(sprintf('Samples @ %.0f Hz', d.sampling_rate));

% Access all metadata
disp(d.start_of_recording);
disp(d.channel_labels);

License

MIT

Metadata

Release files for cfs2mat 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cfs2mat 0.1.0
File Size Uploaded Provenance
cfs2mat-0.1.0.tar.gz 31.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for cfs2mat 0.1.0
File Interpreter ABI Platform
cfs2mat-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 39.4 kB

Release files / cfs2mat-0.1.0.tar.gz

Download URL cfs2mat-0.1.0.tar.gz
Size 31.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2d38356fb9563db1ff65d72d4e210788fa35a27f8680c914e92edd294663b0e9
BLAKE2b-256 checksum
How to use checksums
f21966a5b75f1e8c34e0f6e760cd6881f619b4212c727d6fc3096d204be1b4e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.14

Release files / cfs2mat-0.1.0-py3-none-any.whl

Download URL cfs2mat-0.1.0-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
62ec479b91b83303d234e894ecedda30aeaf249b238e404d7959f15ee25383d2
BLAKE2b-256 checksum
How to use checksums
5851019512fb12170a3658d20b730e7768342b0aff4b63b0c5e165082307908f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.14

Security for cfs2mat 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page