next up previous contents
Next: WFDB_tools library functions Up: Using the WFDB_tools library Previous: Creating an annotation file   Contents


Creating a signal file

Creating an output signal file is made in three steps: create a signal information structure, write the output signal data, and create the header file.

Assume we have data from three signals. We need to create a signal information structure using:

    >> S = WFDB_Siginfo(3)
    S = 
    1x3 struct array with fields:
        fname
        desc
        units
        gain
        initval
        group
        fmt
        spf
        bsize
        adcres
        adczero
        baseline

Now these fields need to be filled with appropriate values. All of them have default values to avoid producing errors, but it is unlikely that they will fit our signals. For example, if signal 0 is the X-lead of a Frank-lead ECG, we may want its description to be:

    >> S(1).desc = 'Frank X';

and so on for all other fields. (Remember: the first signal is signal 0; its attributes are in S(1).) When done, we create an empty signal file in which to write the data, using

    >> WFDB_osigfopen(S)

We also need to supply the sampling frequency, for example 1 kHz:

    >> WFDB_setsampfreq(1000);

and the basetime of the recording (i.e. the time of sample number 0). Assuming the recording was started when my oldest daughter was born:

    >> WFDB_setbasetime('02:19:00 02/09/1999')

(Dates used by WFDB_tools are always in DD/MM/YYYY format; 02/09/1999 is 2 September, not February 9.)

Now we're done with providing signal information and it is time to write the actual signal data. This must be stored column-wise in a matrix (one signal per column, one sample per row). If our data is stored in the variable DATA we would use:

    >> WFDB_putvec(DATA)

Finally, we need to record the information from S into a header (.hea) file for later use. We need to choose a name for the new record we are creating (avoiding the names of any existing records that we wish to read in the future); if we choose test1 as the record name, we can create the header file by:

    >> WFDB_newheader('test1')

These operations will create a header file, test1.hea, in the current directory, and a signal file with the name previously specified in the fname fields of the signal information structure, S. (Notice that WFDB_newheader must always be invoked after all of the samples have been written using WFDB_putvec, because the header file includes the number of samples in the record and checksums for each signal, which are not known by the WFDB library until all of the samples have been written.) As always, we use

    >> WFDB_wfdbquit

to flush all pending output to the files, to close them, and to reset the internal WFDB library variables.

As in the previous example, we can inspect our results using WAVE:

    >> !wave -r test1 &

An elaborated version of this example is provided in the examples directory of the WFDB_tools package (look for example4.m).


next up previous contents
Next: WFDB_tools library functions Up: Using the WFDB_tools library Previous: Creating an annotation file   Contents
George B. Moody 2005-06-02