Format Conversions

The wfdb.io.convert subpackage contains functions to read and write non-WFDB files commonly used for waveforms.

CSV

wfdb.io.convert.csv.csv_to_wfdb(file_name, fs, units, fmt=None, adc_gain=None, baseline=None, samps_per_frame=None, counter_freq=None, base_counter=None, base_time=None, base_date=None, comments=None, sig_name=None, dat_file_name=None, skew=None, byte_offset=None, adc_res=None, adc_zero=None, init_value=None, checksum=None, block_size=None, record_only=False, header=True, delimiter=',', verbose=False)

Read a WFDB header file and return either a Record object with the record descriptors as attributes or write a record and header file.

Parameters
file_namestr

The name of the WFDB record to be read, without any file extensions. If the argument contains any path delimiter characters, the argument will be interpreted as PATH/BASE_RECORD. Both relative and absolute paths are accepted. If the pn_dir parameter is set, this parameter should contain just the base record name, and the files fill be searched for remotely. Otherwise, the data files will be searched for in the local path.

fsfloat

This number can be expressed in any format legal for a Python input of floating point numbers (thus ‘360’, ‘360.’, ‘360.0’, and ‘3.6e2’ are all legal and equivalent). The sampling frequency must be greater than 0; if it is missing, a value of 250 is assumed.

unitslist, str

This will be applied as the passed list unless a single str is passed instead - in which case the str will be assigned for all channels. This field can be present only if the ADC gain is also present. It follows the baseline field if that field is present, or the gain field if the baseline field is absent. The units field is a list of character strings that specifies the type of physical unit. If the units field is absent, the physical unit may be assumed to be 1 mV.

fmtlist, str, optional

This will be applied as the passed list unless a single str is passed instead - in which case the str will be assigned for all channels. A list of strings giving the WFDB format of each file used to store each channel. Accepted formats are: ‘80’,’212’,’16’,’24’, and ‘32’. There are other WFDB formats as specified by: https://www.physionet.org/physiotools/wag/signal-5.htm but this library will not write (though it will read) those file types. Each field is an integer that specifies the storage format of the signal. All signals in a given group are stored in the same format. The most common format is format 16 (sixteen-bit amplitudes). The parameters samps_per_frame, skew, and byte_offset are optional fields, and if present, are bound to the format field. In other words, they may be considered as format modifiers, since they further describe the encoding of samples within the signal file.

adc_gainlist, int, optional

This will be applied as the passed list unless a single int is passed instead - in which case the int will be assigned for all channels. This field is a list of numbers that specifies the difference in sample values that would be observed if a step of one physical unit occurred in the original analog signal. For ECGs, the gain is usually roughly equal to the R-wave amplitude in a lead that is roughly parallel to the mean cardiac electrical axis. If the gain is zero or missing, this indicates that the signal amplitude is uncalibrated; in such cases, a value of 200 ADC units per physical unit may be assumed.

baselinelist, int, optional

This will be applied as the passed list unless a single int is passed instead - in which case the int will be assigned for all channels. This field can be present only if the ADC gain is also present. It is not separated by whitespace from the ADC gain field; rather, it is surrounded by parentheses, which delimit it. The baseline is an integer that specifies the sample value corresponding to 0 physical units. If absent, the baseline is taken to be equal to the ADC zero. Note that the baseline need not be a value within the ADC range; for example, if the ADC input range corresponds to 200-300 degrees Kelvin, the baseline is the (extended precision) value that would map to 0 degrees Kelvin.

samps_per_framelist, int, optional

This will be applied as the passed list unless a single int is passed instead - in which case the int will be assigned for all channels. Normally, all signals in a given record are sampled at the (base) sampling frequency as specified by fs; in this case, the number of samples per frame is 1 for all signals, and this field is conventionally omitted. If the signal was sampled at some integer multiple, n, of the base sampling frequency, however, each frame contains n samples of the signal, and the value specified in this field is also n. (Note that non-integer multiples of the base sampling frequency are not supported).

counter_freqfloat, optional

This field (a floating-point number, in the same format as fs) can be present only if fs is also present. Typically, the counter frequency may be derived from an analog tape counter, or from page numbers in a chart recording. If the counter frequency is absent or not positive, it is assumed to be equal to fs.

base_counterfloat, optional

This field can be present only if the counter frequency is also present. The base counter value is a floating-point number that specifies the counter value corresponding to sample 0. If absent, the base counter value is taken to be 0.

base_timedatetime.time, optional

This field can be present only if the number of samples is also present. It gives the time of day that corresponds to the beginning of the record.

base_datedatetime.date, optional

This field can be present only if the base time is also present. It contains the date that corresponds to the beginning of the record.

commentslist, optional

A list of string comments to be written to the header file. Each string entry represents a new line to be appended to the bottom of the header file (‘.hea’).

sig_namelist, optional

A list of strings giving the signal name of each signal channel. This will be used for plotting the signal both in this package and LightWave. Note, this value will be used in preference to the CSV header, if applicable, to define custom signal names.

dat_file_namestr, optional

The name of the file in which samples of the signal are kept. Although the record name is usually part of the signal file name, this convention is not a requirement. Note that several signals can share the same file (i.e., they can belong to the same signal group); all entries for signals that share a given file must be consecutive, however. Note, the default behavior is to save the files in the current working directory, not the directory of the file being read.

skewlist, int, optional

This will be applied as the passed list unless a single int is passed instead - in which case the int will be assigned for all channels. Ideally, within a given record, samples of different signals with the same sample number are simultaneous (within one sampling interval). If this is not the case (as, for example, when a multitrack analog tape recording is digitized and the azimuth of the playback head does not match that of the recording head), the skew between signals can sometimes be determined (for example, by locating recorded waveform features with known time relationships, such as calibration signals). If this has been done, the skew field may be inserted into the header file to indicate the (positive) number of samples of the signal that are considered to precede sample 0. These samples, if any, are included in the checksum. (Note the checksum need not be changed if the skew field is inserted or modified).

byte_offsetlist, int, optional

This will be applied as the passed list unless a single int is passed instead - in which case the int will be assigned for all channels. Normally, signal files include only sample data. If a signal file includes a preamble, however, this field specifies the offset in bytes from the beginning of the signal file to sample 0 (i.e., the length of the preamble). Data within the preamble is not included in the signal checksum. Note that the byte offset must be the same for all signals within a given group (use the skew field to correct for intersignal skew). This feature is provided only to simplify the task of reading signal files not generated using the WFDB library; the WFDB library does not support any means of writing such files, and byte offsets must be inserted into header files manually.

adc_res: list, int, optional

This will be applied as the passed list unless a single int is passed instead - in which case the int will be assigned for all channels. This field can be present only if the ADC gain is also present. It specifies the resolution of the analog-to-digital converter used to digitize the signal. Typical ADCs have resolutions between 8 and 16 bits. If this field is missing or zero, the default value is 12 bits for amplitude-format signals, or 10 bits for difference-format signals (unless a lower value is specified by the format field).

adc_zero: list, int, optional

This will be applied as the passed list unless a single int is passed instead - in which case the int will be assigned for all channels. This field can be present only if the ADC resolution is also present. It is an integer that represents the amplitude (sample value) that would be observed if the analog signal present at the ADC inputs had a level that fell exactly in the middle of the input range of the ADC. For a bipolar ADC, this value is usually zero, but a unipolar (offset binary) ADC usually produces a non-zero value in the middle of its range. Together with the ADC resolution, the contents of this field can be used to determine the range of possible sample values. If this field is missing, a value of 0 is assumed.

init_valuelist, int, optional

This will be applied as the passed list unless a single int is passed instead - in which case the int will be assigned for all channels. This field can be present only if the ADC zero is also present. It specifies the value of sample 0 in the signal, but is used only if the signal is stored in difference format. If this field is missing, a value equal to the ADC zero is assumed.

checksumlist, optional

This field can be present only if the initial value is also present. It is a 16-bit signed checksum of all samples in the signal. (Thus the checksum is independent of the storage format.) If the entire record is read without skipping samples, and the header’s record line specifies the correct number of samples per signal, this field is compared against a computed checksum to verify that the signal file has not been corrupted. A value of zero may be used as a field placeholder if the number of samples is unspecified.

block_sizelist, int, optional

This will be applied as the passed list unless a single int is passed instead - in which case the int will be assigned for all channels. This field can be present only if the checksum is present. This field is an integer and is usually 0. If the signal is stored in a file that must be read in blocks of a specific size, however, this field specifies the block size in bytes. (On UNIX systems, this is the case only for character special files, corresponding to certain tape and raw disk files. If necessary, the block size may be given as a negative number to indicate that the associated file lacks I/O driver support for some operations.) All signals belonging to the same signal group have the same block size.

record_onlybool, optional

Whether to only return the record information (True) or not (False). If false, this function will generate both a .dat and .hea file.

headerbool, optional

Whether to assume the CSV has a first line header (True) or not (False) which defines the signal names. If false, this function will generate either the signal names provided by sig_name or set [ch_1, ch_2, …] as the default.

delimiterstr, optional

What to use as the delimiter for the file to separate data. The default if a comma (‘,’). Other common delimiters are tabs (’ ‘), spaces (’ ‘), pipes (‘|’), and colons (‘:’).

verbosebool, optional

Whether to print all the information read about the file (True) or not (False).

Returns
recordRecord or MultiRecord, optional

The WFDB Record or MultiRecord object representing the contents of the CSV file read.

Notes

CSVs should be in the following format:

sig_1_name,sig_2_name,… sig_1_val_1,sig_2_val_1,… sig_1_val_2,sig_2_val_2,… …,…,…

Or this format if header=False is defined:

sig_1_val_1,sig_2_val_1,… sig_1_val_2,sig_2_val_2,… …,…,…

The signal will be saved defaultly as a p_signal so both floats and ints are acceptable.

Examples

Create the header (‘.hea’) and record (‘.dat’) files, specifies both units to be ‘mV’ >>> csv_to_wfdb(‘sample-data/100.csv’, fs=360, units=’mV’)

Create the header (‘.hea’) and record (‘.dat’) files, change units for each signal >>> csv_to_wfdb(‘sample-data/100.csv’, fs=360, units=[‘mV’,’kV’])

Return just the record, note the use of lists to specify which values should be applied to each signal >>> csv_record = csv_to_wfdb(‘sample-data/100.csv’, fs=360, units=[‘mV’,’mV’],

fmt=[‘80’,212’], adc_gain=[100,200], baseline=[1024,512], record_only=True)

Return just the record, note the use of single strings and ints to specify when fields can be applied to all signals >>> csv_record = csv_to_wfdb(‘sample-data/100.csv’, fs=360, units=’mV’,

fmt=[‘80’,’212’], adc_gain=200, baseline=1024, record_only=True)

EDF

wfdb.io.convert.edf.rdedfann(record_name, pn_dir=None, delete_file=True, info_only=True, record_only=False, verbose=False, encoding='iso8859-1')

This program returns the annotation information from an EDF+ file containing annotations (with the signal name given as ‘EDF Annotations’). The information that is returned if info_only is set to True is:

{
‘onset_time’: list of %H:%M:%S.fff strings denoting the annotation

onset times,

‘sample_num’: list of integers denoting the annotation onset

sample numbers,

‘comment’: list of comments (aux_note) for the annotations, ‘duration’: list of floats denoting the duration of the event

}

Else, this function will return either the WFDB Annotation format of the information of the file if record_only is set to True, or nothing if neither are set to True though a WFDB Annotation file will be created.

Parameters
record_namestr

The name of the input EDF record to be read.

pn_dirstr, optional

Option used to stream data from Physionet. The Physionet database directory from which to find the required record files. eg. For record ‘100’ in ‘http://physionet.org/content/mitdb’ pn_dir=’mitdb’.

delete_filebool, optional

Whether to delete the saved EDF file (False) or not (True) after being imported.

info_onlybool, optional

Return, strictly, the information contained in the file as formatted by the original WFDB package. Must not be True if record_only is True.

record_onlybool, optional

Whether to only return the annotation information (True) or not (False). If False, this function will generate a WFDB-formatted annotation file. If True, it will return the object returned if that file were read with rdann. Must not be True if info_only is True.

verbosebool, optional

Whether to print all the information read about the file (True) or not (False).

encodingstr, optional

The encoding to use for strings in the header. Although the edf specification requires ascii strings, some files do not adhere to it.

Returns
N/Adict, Annotation, optional

If ‘info_only’ is set to True, return all of the annotation information needed to generate WFDB-formatted annotation files. If ‘record_only’ is set to True, return the WFDB-formatted annotation object generated by the rdann output. If none are set to True, write the WFDB-formatted annotation file.

Notes

The entire file is composed of (seen here: https://www.edfplus.info/specs/edfplus.html#edfplusannotations):

HEADER RECORD (we suggest to also adopt the 12 simple additional EDF+ specs) 8 ascii : version of this data format (0) 80 ascii : local patient identification (mind item 3 of the additional EDF+ specs) 80 ascii : local recording identification (mind item 4 of the additional EDF+ specs) 8 ascii : startdate of recording (dd.mm.yy) (mind item 2 of the additional EDF+ specs) 8 ascii : starttime of recording (hh.mm.ss) 8 ascii : number of bytes in header record 44 ascii : reserved 8 ascii : number of data records (-1 if unknown, obey item 10 of the additional EDF+ specs) 8 ascii : duration of a data record, in seconds 4 ascii : number of signals (ns) in data record ns * 16 ascii : ns * label (must be ‘EDF Annotations’) ns * 80 ascii : ns * transducer type (must be whitespace) ns * 8 ascii : ns * physical dimension (must be whitespace) ns * 8 ascii : ns * physical minimum (e.g. -500 or 34, different than physical maximum) ns * 8 ascii : ns * physical maximum (e.g. 500 or 40, different than physical minimum) ns * 8 ascii : ns * digital minimum (must be -32768) ns * 8 ascii : ns * digital maximum (must be 32767) ns * 80 ascii : ns * prefiltering (must be whitespace) ns * 8 ascii : ns * nr of samples in each data record ns * 32 ascii : ns * reserved

ANNOTATION RECORD

Examples

>>> ann_info = wfdb.rdedfann('sample-data/test_edfann.edf')
wfdb.io.convert.edf.read_edf(record_name, pn_dir=None, header_only=False, verbose=False, rdedfann_flag=False, encoding='iso8859-1')

Read a EDF format file into a WFDB Record.

Many EDF files contain signals at widely varying sampling frequencies. read_edf handles these properly, but the default behavior of most WFDB applications is to read such data in low-resolution mode (in which all signals are resampled at the lowest sampling frequency used for any signal in the record). This is almost certainly not what you want if, for example, the record contains EEG signals sampled at 200 Hz and body temperature sampled at 1 Hz; by default, applications such as rdsamp will resample the EEGs (and any other signals in the record) at 1 Hz. To avoid this behavior, you can set smooth_frames to False (high resolution) provided by rdrecord and a few other WFDB applications.

Note that applications built using version 3.1.0 and later versions of the WFDB-Python library can read EDF files directly, so that the conversion performed by read_edf is no longer necessary. However, one can still use this function to produce WFDB-compatible files from EDF files if desired.

Parameters
record_namestr

The name of the input EDF record to be read.

pn_dirstr, optional

Option used to stream data from Physionet. The Physionet database directory from which to find the required record files. eg. For record ‘100’ in ‘http://physionet.org/content/mitdb’ pn_dir=’mitdb’.

header_onlybool, optional

Whether to only return the header information (True) or not (False). If true, this function will only return [‘fs’, ‘sig_len’, ‘n_sig’, ‘base_date’, ‘base_time’, ‘units’, ‘sig_name’, ‘comments’].

verbosebool, optional

Whether to print all the information read about the file (True) or not (False).

rdedfann_flagbool, optional

Whether the function is being called by rdedfann or the user. If it is being called by the user and the file has annotations, then warn them that the EDF file has annotations and that they should use rdedfann instead.

encodingstr, optional

The encoding to use for strings in the header. Although the edf specification requires ascii strings, some files do not adhere to it.

Returns
recorddict, optional

All of the record information needed to generate MIT formatted files. Only returns if ‘record_only’ is set to True, else generates the corresponding .dat and .hea files. This record file will not match the rdrecord output since it will only give us the digital signal for now.

Notes

The entire file is composed of (seen here: https://www.edfplus.info/specs/edf.html):

HEADER RECORD (we suggest to also adopt the 12 simple additional EDF+ specs) 8 ascii : version of this data format (0) 80 ascii : local patient identification (mind item 3 of the additional EDF+ specs) 80 ascii : local recording identification (mind item 4 of the additional EDF+ specs) 8 ascii : startdate of recording (dd.mm.yy) (mind item 2 of the additional EDF+ specs) 8 ascii : starttime of recording (hh.mm.ss) 8 ascii : number of bytes in header record 44 ascii : reserved 8 ascii : number of data records (-1 if unknown, obey item 10 of the additional EDF+ specs) 8 ascii : duration of a data record, in seconds 4 ascii : number of signals (ns) in data record ns * 16 ascii : ns * label (e.g. EEG Fpz-Cz or Body temp) (mind item 9 of the additional EDF+ specs) ns * 80 ascii : ns * transducer type (e.g. AgAgCl electrode) ns * 8 ascii : ns * physical dimension (e.g. uV or degreeC) ns * 8 ascii : ns * physical minimum (e.g. -500 or 34) ns * 8 ascii : ns * physical maximum (e.g. 500 or 40) ns * 8 ascii : ns * digital minimum (e.g. -2048) ns * 8 ascii : ns * digital maximum (e.g. 2047) ns * 80 ascii : ns * prefiltering (e.g. HP:0.1Hz LP:75Hz) ns * 8 ascii : ns * nr of samples in each data record ns * 32 ascii : ns * reserved

DATA RECORD nr of samples[1] * integer : first signal in the data record nr of samples[2] * integer : second signal .. .. nr of samples[ns] * integer : last signal

Bytes 0 - 127: descriptive text Bytes 128 - 131: master tag (data type = matrix) Bytes 132 - 135: master tag (data size) Bytes 136 - 151: array flags (4 byte tag with data type, 4 byte

tag with subelement size, 8 bytes of content)

Bytes 152 - 167: array dimension (4 byte tag with data type, 4

byte tag with subelement size, 8 bytes of content)

Bytes 168 - 183: array name (4 byte tag with data type, 4 byte

tag with subelement size, 8 bytes of content)

Bytes 184 - …: array content (4 byte tag with data type, 4 byte

tag with subelement size, … bytes of content)

Examples

>>> record = read_edf('x001_FAROS.edf',
                       pn_dir='simultaneous-measurements/raw_data')
wfdb.io.convert.edf.wfdb_to_edf(record_name, pn_dir=None, sampfrom=0, sampto=None, channels=None, output_filename='', edf_plus=False)

These programs convert EDF (European Data Format) files into WFDB-compatible files (as used in PhysioNet) and vice versa. European Data Format (EDF) was originally designed for storage of polysomnograms.

Note that WFDB format does not include a standard way to specify the transducer type or the prefiltering specification; these parameters are not preserved by these conversion programs. Also note that use of the standard signal and unit names specified for EDF is permitted but not enforced by wfdb_to_edf.

Parameters
record_namestr

The name of the input WFDB record to be read. Can also work with both EDF and WAV files.

pn_dirstr, optional

Option used to stream data from Physionet. The Physionet database directory from which to find the required record files. eg. For record ‘100’ in ‘http://physionet.org/content/mitdb’ pn_dir=’mitdb’.

sampfromint, optional

The starting sample number to read for all channels.

samptoint, ‘end’, optional

The sample number at which to stop reading for all channels. Reads the entire duration by default.

channelslist, optional

List of integer indices specifying the channels to be read. Reads all channels by default.

output_filenamestr, optional

The desired name of the output file. If this value set to the default value of ‘’, then the output filename will be ‘REC.edf’.

edf_plusbool, optional

Whether to write the output file in EDF (False) or EDF+ (True) format.

Returns
N/A

Notes

The entire file is composed of (seen here: https://www.edfplus.info/specs/edf.html):

HEADER RECORD (we suggest to also adopt the 12 simple additional EDF+ specs) 8 ascii : version of this data format (0) 80 ascii : local patient identification (mind item 3 of the additional EDF+ specs) 80 ascii : local recording identification (mind item 4 of the additional EDF+ specs) 8 ascii : startdate of recording (dd.mm.yy) (mind item 2 of the additional EDF+ specs) 8 ascii : starttime of recording (hh.mm.ss) 8 ascii : number of bytes in header record 44 ascii : reserved 8 ascii : number of data records (-1 if unknown, obey item 10 of the additional EDF+ specs) 8 ascii : duration of a data record, in seconds 4 ascii : number of signals (ns) in data record ns * 16 ascii : ns * label (e.g. EEG Fpz-Cz or Body temp) (mind item 9 of the additional EDF+ specs) ns * 80 ascii : ns * transducer type (e.g. AgAgCl electrode) ns * 8 ascii : ns * physical dimension (e.g. uV or degreeC) ns * 8 ascii : ns * physical minimum (e.g. -500 or 34) ns * 8 ascii : ns * physical maximum (e.g. 500 or 40) ns * 8 ascii : ns * digital minimum (e.g. -2048) ns * 8 ascii : ns * digital maximum (e.g. 2047) ns * 80 ascii : ns * prefiltering (e.g. HP:0.1Hz LP:75Hz) ns * 8 ascii : ns * nr of samples in each data record ns * 32 ascii : ns * reserved

DATA RECORD nr of samples[1] * integer : first signal in the data record nr of samples[2] * integer : second signal .. .. nr of samples[ns] * integer : last signal

Bytes 0 - 127: descriptive text Bytes 128 - 131: master tag (data type = matrix) Bytes 132 - 135: master tag (data size) Bytes 136 - 151: array flags (4 byte tag with data type, 4 byte

tag with subelement size, 8 bytes of content)

Bytes 152 - 167: array dimension (4 byte tag with data type, 4

byte tag with subelement size, 8 bytes of content)

Bytes 168 - 183: array name (4 byte tag with data type, 4 byte

tag with subelement size, 8 bytes of content)

Bytes 184 - …: array content (4 byte tag with data type, 4 byte

tag with subelement size, … bytes of content)

Examples

>>> wfdb.wfdb_to_edf('100', pn_dir='pwave')

The output file name is ‘100.edf’

Matlab

wfdb.io.convert.matlab.wfdb_to_mat(record_name, pn_dir=None, sampfrom=0, sampto=None, channels=None)

This program converts the signals of any PhysioNet record (or one in any compatible format) into a .mat file that can be read directly using any version of Matlab, and a short text file containing information about the signals (names, gains, baselines, units, sampling frequency, and start time/date if known). If the input record name is REC, the output files are RECm.mat and RECm.hea. The output files can also be read by any WFDB application as record RECm.

This program does not convert annotation files; for that task, ‘rdann’ is recommended.

The output .mat file contains a single matrix named val containing raw (unshifted, unscaled) samples from the selected record. Using various options, you can select any time interval within a record, or any subset of the signals, which can be rearranged as desired within the rows of the matrix. Since .mat files are written in column-major order (i.e., all of column n precedes all of column n+1), each vector of samples is written as a column rather than as a row, so that the column number in the .mat file equals the sample number in the input record (minus however many samples were skipped at the beginning of the record, as specified using the start_time option). If this seems odd, transpose your matrix after reading it!

This program writes version 5 MAT-file format output files, as documented in http://www.mathworks.com/access/helpdesk/help/pdf_doc/matlab/matfile_format.pdf The samples are written as 32-bit signed integers (mattype=20 below) in little-endian format if the record contains any format 24 or format 32 signals, as 8-bit unsigned integers (mattype=50) if the record contains only format 80 signals, or as 16-bit signed integers in little-endian format (mattype=30) otherwise.

The maximum size of the output variable is 2^31 bytes. wfdb2mat from versions 10.5.24 and earlier of the original WFDB software package writes version 4 MAT- files which have the additional constraint of 100,000,000 elements per variable.

The output files (recordm.mat + recordm.hea) are still WFDB-compatible, given the .hea file constructed by this program.

Parameters
record_namestr

The name of the input WFDB record to be read.

pn_dirstr, optional

Option used to stream data from Physionet. The Physionet database directory from which to find the required record files. eg. For record ‘100’ in ‘http://physionet.org/content/mitdb’ pn_dir=’mitdb’.

sampfromint, optional

The starting sample number to read for all channels.

samptoint, ‘end’, optional

The sample number at which to stop reading for all channels. Reads the entire duration by default.

channelslist, optional

List of integer indices specifying the channels to be read. Reads all channels by default.

Returns
N/A

Notes

The entire file is composed of:

Bytes 0 - 127: descriptive text Bytes 128 - 131: master tag (data type = matrix) Bytes 132 - 135: master tag (data size) Bytes 136 - 151: array flags (4 byte tag with data type, 4 byte

tag with subelement size, 8 bytes of content)

Bytes 152 - 167: array dimension (4 byte tag with data type, 4

byte tag with subelement size, 8 bytes of content)

Bytes 168 - 183: array name (4 byte tag with data type, 4 byte

tag with subelement size, 8 bytes of content)

Bytes 184 - …: array content (4 byte tag with data type, 4 byte

tag with subelement size, … bytes of content)

Examples

>>> wfdb2mat('100', pn_dir='pwave')

The output file name is 100m.mat and 100m.hea

TFF

Module for reading ME6000 .tff format files.

http://www.biomation.com/kin/me6000.htm

wfdb.io.convert.tff.rdtff(file_name, cut_end=False)

Read values from a tff file.

Parameters
file_namestr

Name of the .tff file to read.

cut_endbool, optional

If True, cuts out the last sample for all channels. This is for reading files which appear to terminate with the incorrect number of samples (ie. sample not present for all channels).

Returns
signalndarray

A 2d numpy array storing the physical signals from the record.

fieldsdict

A dictionary containing several key attributes of the read record.

markersndarray

A 1d numpy array storing the marker locations.

triggersndarray

A 1d numpy array storing the trigger locations.

Notes

This function is slow because tff files may contain any number of escape sequences interspersed with the signals. There is no way to know the number of samples/escape sequences beforehand, so the file is inefficiently parsed a small chunk at a time.

It is recommended that you convert your tff files to WFDB format.

WAV

wfdb.io.convert.wav.read_wav(record_name, pn_dir=None, delete_file=True, record_only=False)

Convert .wav (format 16, multiplexed signals, with embedded header information) formatted files to WFDB format. See here for more details about the formatting of a .wav file: http://soundfile.sapp.org/doc/WaveFormat/.

This process may not work with some .wav files that are encoded using variants of the original .wav format that are not WFDB-compatible. In principle, this program should be able to recognize such files by their format codes, and it will produce an error message in such cases. If the format code is incorrect, however, read_wav may not recognize that an error has occurred.

Parameters
record_namestr

The name of the input .wav record to be read.

pn_dirstr, optional

Option used to stream data from Physionet. The Physionet database directory from which to find the required record files. eg. For record ‘100’ in ‘http://physionet.org/content/mitdb’ pn_dir=’mitdb’.

delete_filebool, optional

Whether to delete the saved .wav file (False) or not (True) after being imported.

Returns
recordRecord

A WFDB Record object.

Notes

Files that can be processed successfully using read_wav always have exactly three chunks (a header chunk, a format chunk, and a data chunk). In .wav files, binary data are always written in little-endian format (least significant byte first). The format of read_wav’s input files is as follows:

[Header chunk] Bytes 0 - 3: “RIFF” [4 ASCII characters] Bytes 4 - 7: L-8 (number of bytes to follow in the file, excluding bytes 0-7) Bytes 8 - 11: “WAVE” [4 ASCII characters]

[Format chunk] Bytes 12 - 15: “fmt ” [4 ASCII characters, note trailing space] Bytes 16 - 19: 16 (format chunk length in bytes, excluding bytes 12-19) Bytes 20 - 35: format specification, consisting of: Bytes 20 - 21: 1 (format tag, indicating no compression is used) Bytes 22 - 23: number of signals (1 - 65535) Bytes 24 - 27: sampling frequency in Hz (per signal)

Note that the sampling frequency in a .wav file must be an integer multiple of 1 Hz, a restriction that is not imposed by MIT (WFDB) format.

Bytes 28 - 31: bytes per second (sampling frequency * frame size in bytes) Bytes 32 - 33: frame size in bytes Bytes 34 - 35: bits per sample (ADC resolution in bits)

Note that the actual ADC resolution (e.g., 12) is written in this field, although each output sample is right-padded to fill a full (16-bit) word. (.wav format allows for 8, 16, 24, and 32 bits per sample)

[Data chunk] Bytes 36 - 39: “data” [4 ASCII characters] Bytes 40 - 43: L-44 (number of bytes to follow in the data chunk) Bytes 44 - L-1: sample data, consisting of: Bytes 44 - 45: sample 0, channel 0 Bytes 46 - 47: sample 0, channel 1 … etc. (same order as in a multiplexed WFDB signal file)

Examples

>>> record = read_wav('sample-data/SC4001E0-PSG.wav')
wfdb.io.convert.wav.wfdb_to_wav(record_name, pn_dir=None, sampfrom=0, sampto=None, channels=None, output_filename='', write_header=False)

This program converts a WFDB record into .wav format (format 16, multiplexed signals, with embedded header information).

Parameters
record_namestr

The name of the input WFDB record to be read. Can also work with both EDF and WAV files.

pn_dirstr, optional

Option used to stream data from Physionet. The Physionet database directory from which to find the required record files. eg. For record ‘100’ in ‘http://physionet.org/content/mitdb’ pn_dir=’mitdb’.

sampfromint, optional

The starting sample number to read for all channels.

samptoint, ‘end’, optional

The sample number at which to stop reading for all channels. Reads the entire duration by default.

channelslist, optional

List of integer indices specifying the channels to be read. Reads all channels by default.

output_filenamestr, optional

The desired name of the output file. If this value set to the default value of ‘’, then the output filename will be ‘REC.wav’.

write_headerbool, optional

Whether to write (True) or not to write (False) a header file to accompany the generated WAV file. The default value is ‘False’.

Returns
N/A

Examples

>>> wfdb_to_wav('100', pn_dir='pwave')

The output file name is ‘100.wav’