Convert data readable in matlab into WFDB Physionet format.
Input Paramater are:
X -(required) NxM matrix of M signals with N samples each. The
signals can be of type double.The signals are assumed to be
in physical units already and will be converted to
fname -(required) String where the the header (*.hea) and data (*.dat)
files will be saved (one single name for both, with no sufix).
Fs -(Optional) 1x1 sampling frequency in Hz (all signals must have
been sampled at the same frquency). Default is 1 Hz.
bit_res -(Optional) 1xM (or Mx1):scalar determining the bit depth of the conversion for
1x1 : If all the signals should have the same bit depth
Options are: 8, 16, and 32 ( all are signed types). 16 is the default.
adu -(Optional) Cell array of strings describing the physical units (default is 'V').
If only one string is entered all signals will have the same physical units.
If multiple physical units, the total units entered has to equal M (number of
channels). Units are delimited by '/'. See examples below.
info -(Optional) String that will be added to the comment section of the header file.
gain -(Optional) Scalar, if provided, no automatic scaling will be applied before the
quantitzation of the signal. If a gain is passed, in will be the same one set
on the header file. The signal will be scaled by this gain prior to the quantization
process. Use this options if you want to have a standard gain and quantization
process for all signals in a dataset (the function will not attempt to quantitized
individual waveforms based on their individual range and baseline).
baseline -(Optional) Offset (ADC zero) Mx1 array of integers 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.
sg_name -(Optional) Cell array of strings describing signal names.
isint -(Optional) Logical value (default=0). Use this option if you know
the signal is already quantitized, and you want to remove round-off
error by setting the original values to integers prior to fixed
Ouput Parameters are:
xbit -(Optional) NxM the quantitized signals that written to file (possible
rescaled if no gain was provided at input). Useful for comparing
and estimating quatitization error with the input double signal X
(see examples below).
NOTE: The signals can have different amplitudes, they will all be scaled to
a reference gain, with the scaling factor saved in the *.hea file.
Written by Ikaro Silva 2010
Modified by Louis Mayaud 2011
See also wrsamp, wfdbdesc
%%%%%%%%% Example 1 %%%%%%%%%%%%
display('***This example will write a Ex1.dat and Ex1.hea file to your current directory!')
s=input('Hit "ctrl + c" to quit or "Enter" to continue!');
%Generate 3 different signals and convert them to signed 16 bit in WFDB format
clear all;clc;close all
%First signal a ramp with 2^16 unique levels and is set to (+-) 2^15 (Volts)
%Thus the header file should have one quant step equal to (2^15-(-2^15))/(2^16) V.
%Second signal is a sine wave with 2^8 unique levels and set to (+-) 1 (mV)
%Thus the header file should one quant step equal a (1--1)/(2^16) adu step
%Third signal is a random binary signal set to to (+-) 1 (V) with DC (to be discarded)
%Thus the header file should have one quant step equal a 1/(2^16) adu step.
sig3=(rand(N,1) > 0.97)*2 -1 + 2^16;
%Concatenate all signals and convert to WFDB format with default 16 bits (empty brackets)
sig=[sig1 sig2 sig3];
% %NOTE: If you have WFDB installed you can check the conversion by
% %uncomenting and this section and running (notice that all signals are scaled
% %to unit amplitude during conversion, with the header files keeping the gain info):
% !rdsamp -r Ex1 > foo
% plot(x(:,1),x(:,2));hold on;plot(x(:,1),x(:,3),'k');plot(x(:,1),x(:,4),'r')
%%%%%%% End of Example 1%%%%%%%%%