[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.2 Special I/O Modes


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

setifreq

 
void setifreq(WFDB_Frequency frequency)

This function sets the current input sampling frequency (in samples per second per signal). It should be invoked after opening the input signals (using isigopen or wfdbinit), and before using any of getvec, getann, putann, isigsettime, isgsettime, timstr, mstimstr, strtim, or annopen. Note that the operation of getframe is unaffected by setifreq.

Use setifreq when your application requires input samples at a specific frequency. After invoking setifreq, getvec resamples the digitized signals from the input signals at the desired frequency (see section getvec), and all of the WFDB library functions that accept or return times in sample intervals automatically convert between the actual sampling intervals and those corresponding to the desired frequency. This slightly elaborated version of the example program from the previous chapter invokes setifreq, passing it the desired sampling frequency from the command line, then prints the samples in record 100s, beginning 1 second (t0) and ending 2 seconds (t1) from the beginning of the record:

 
#include <stdio.h>
#include <wfdb/wfdb.h>

main(int argc, char **argv)
{
    WFDB_Frequency f = (WFDB_Frequency)0;
    WFDB_Sample v[2];
    WFDB_Siginfo s[2];
    WFDB_Time t, t0, t1;

    if (argc > 1) sscanf(argv[1], "%lf", &f);
    if (f <= (WFDB_Frequency)0) f = sampfreq("100s");

    if (isigopen("100s", s, 2) < 1)
        exit(1);
    setifreq(f);
    t0 = strtim("1");
    isigsettime(t0);
    t1 = strtim("2");
    for (t = t0; t <= t1; t++) {
        if (getvec(v) < 0)
            break;
        printf("%d\t%d\n", v[0], v[1]);
    }
    exit(0);
}

(See http://physionet.org/physiotools/wfdb/examples/psamplex.c for a copy of this program. Compile it as shown in the previous chapter, then run it using a command such as ‘psamplex 100’.) The QRS detector in chapter 6 also illustrates the use of setifreq (see section Example 10: A QRS Detector).

Avoid using wfdbinit and setifreq in the same program.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

getifreq

 
WFDB_Frequency getifreq(void)

Return:

(WFDB_Frequency)

the input sampling frequency

This function returns the current input sampling frequency (in samples per second per signal), which is either the raw sampling frequency for the record (as would be returned by sampfreq, see section sampfreq), or the frequency chosen using a previous invocation of setifreq.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

setgvmode

 
void setgvmode(int *mode)

This function sets the mode used by getvec when reading a multi-frequency record (see section Multi-Frequency Records). If mode is WFDB_LOWRES, getvec decimates any signals sampled at multiples of the frame rate, so that one sample is returned per signal per frame (i.e., the oversampled signals are resampled by simple averaging of the samples for each signal within each frame). If mode is WFDB_HIGHRES, each sample of any oversampled signal is returned by successive invocations of getvec, and each sample of any signal sampled at a lower frequency is returned by two or more successive invocations of getvec (i.e., the less frequently sampled signals are resampled using zero-order interpolation). getvec operates in WFDB_LOWRES mode by default. WFDB_LOWRES and WFDB_HIGHRES are defined in ‘<wfdb/wfdb.h>’.

In WFDB library version 9.6 and later versions, setgvmode also affects how annotations are read and written. If setgvmode(WFDB_HIGHRES) is invoked before using annopen, wfdbinit, getvec, sampfreq, strtim, or timstr, then all WFDB_Time data (including the time attributes of annotations read by getann or written by putann) visible to the application are in units of the high-resolution sampling intervals. (Otherwise, WFDB_Time data are in units of frame intervals.)

Version 10.4 and later versions of the WFDB library support two modes of handling invalid or missing samples. By default, getframe, getvec, and sample return the special value WFDB_INVALID_SAMPLE in such cases. If mode is WFDB_GVPAD + WFDB_LOWRES or WFDB_GVPAD + WFDB_HIGHRES, however, these functions replicate the previous valid sample whenever they encounter an invalid or missing sample, which may simplify the design of applications such as digital filters. The constant WFDB_GVPAD is defined in ‘<wfdb/wfdb.h>’.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

getgvmode

 
int setgvmode(void)

This function returns the operating mode used by getvec. If the returned value has the WFDB_HIGHRES bit set, getvec is operating in high-resolution mode; if the returned value has the WFDB_GVPAD bit set, getvec replicates the previous valid sample whenever it encounters an invalid or missing sample, rather than returning the value WFDB_INVALID_SAMPLE. The constants WFDB_HIGHRES, WFDB_GVPAD, and WFDB_INVALID_SAMPLE are defined in ‘<wfdb/wfdb.h>’.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

getspf

 
int getspf(void)

Return:

(int)

the number of samples per signal per frame

Unless the application is operating in WFDB_HIGHRES mode (see section setgvmode) and has then opened a multi-frequency record, this function returns 1. For the case of a multi-frequency record being read in high resolution mode, however, getspf returns the number of samples per signal per frame (hence sampfreq(NULL)/getspf() is the number of frames per second).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

setafreq

 
void setafreq(WFDB_Frequency frequency)

This function sets the time resolution, in ticks per second, for any output annotation files created after it has been invoked. By default, the time resolution is equal to the input sampling frequency (and setifreq invokes setafreq to maintain this behavior if the input sampling frequency is changed).

This function has no effect on output annotation files that are already open when it is invoked, nor on annotations read from input annotation files (for which the time fields always are expressed in units equal to the input sample intervals).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

getafreq

 
WFDB_Frequency getafreq(void)

Return:

>0

output annotation time resolution, if previously set by setafreq

0

otherwise

This function returns the current output annotation time resolution in ticks per second if it has been set using getafreq.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]

George B. Moody (george@mit.edu)