The example will show how to calculate Heart-Rate-Variability (HRV)
using the process-plugin 'hrv'. We will perform the following steps:
//
#include <stdio.h>
#include <ra.h>
int main(int argc, char *argv[])
{
ra_handle ra;
struct ra_info *inf;
meas_handle meas;
eval_handle eval;
plugin_handle pl;
struct proc_info *pi;
/* initialize libRASCH */
ra = ra_lib_init();
if (ra == NULL)
{
printf("error initializing libRASCH\n");
return -1;
}
/* open measurement */
meas = ra_meas_open(ra, argv[1], 0);
if (meas == NULL)
{
printf("can't open measurement %s\n", argv[1]);
return -1;
}
/* get default evaluation */
eval = ra_eval_get_def(meas);
if (eval == NULL)
{
printf("no evaluation in measurement %s\n", argv[1]);
return -1;
}
/* get plugin-handle for hrv-plugin */
pl = ra_plugin_get_by_name(ra, "hrv", 0);
if (pl == NULL)
{
printf("can't find plugin 'hrv'\n");
return -1;
}
/* calculate hrv-values using the hrv-plugin */
pi = (struct proc_info *)ra_proc_get(pl);
pi->mh = meas;
pi->rh = ra_rec_get_first(meas, 0);
pi->eh = eval;
if (ra_proc_do(pi) == 0)
{
long num_results, l;
value_handle vh;
/* get number of results */
vh = ra_value_malloc();
if (ra_info_get(pl, RA_INFO_PL_NUM_RESULTS_L, vh) != 0)
{
printf("no results\n");
return -1;
}
num_results = ra_value_get_long(vh);
for (l = 0; l < num_results; l++)
{
char out[200], t[100];
/* set number of result in which we are interested */
ra_value_set_number(vh, l);
/* test if result is a default value (some
non-default results are arrays which we skip in
this example) */
ra_info_get(pl, RA_INFO_PL_RES_DEFAULT_L, vh);
if (ra_value_get_long(vh) == 0)
continue;
out[0] = '\0';
if (ra_info_get(pl, RA_INFO_PL_RES_NAME_C, vh) == 0)
{
strcpy(t, ra_value_get_string(vh));
strcat(out, t);
}
if (ra_info_get(pl, RA_INFO_PL_RES_DESC_C, vh) == 0)
{
sprintf(t, " (%s)", ra_value_get_string(vh));
strcat(out, t);
}
if (ra_proc_get_result(pi, vh) == 0)
{
sprintf(t, ": %lf", ra_value_get_double(vh));
strcat(out, t);
}
printf("%s\n", out);
}
ra_value_free(vh);
}
/* close */
ra_proc_free(pi);
ra_meas_close(meas);
ra_lib_close(ra);
return 0;
} /* main() */
//

- Returns the plugin-handle for the plugin 'hrv'.

- Initialize the proc_info structure (defined in ra_defines.h). In this
structure must be the information set, which will be needed for the
processing (the next 3 lines).
Not all process-plugins need the information of the recording and/or
the evaluation. Please check the plugin-reference section which
information is needed. In case of doubt set all variables.

- This function-call starts the processing. If the processing is
successfull, the function returns 0.

- To select the result, in which you are interessted, the variable
'res_num' in the ra_info structure must be set. The value of the
result as well as information about the result will be returned using
a ra_info structure.

- Information about a result will be obtained using
ra_get_info_id(). The value of the result will be obtained using
ra_get_result().
The output of the above example for the ECG '100s'
is shown here:
SDNN (standard deviation of normal-to-normal intervals):
30.876196
HRVI (HRV-Index): 4.800000
SDANN (standard deviation of averaged normal-to-normal
intervals): nan
rmssd (root mean of squared sucsessive differences): 33.839537
pNN50 (): 7.142857
TP (total power): 482.603096
ULF (ultra low frequency power): 0.000000
VLF (very low frequency power of short-term recordings):
32.889150
LF (low frequency power): 157.213726
LF_NORM (normalised low frequency power): 34.958606
HF (high freuqency power): 292.500220
HF_NORM (normalised high frequency power): 65.041394
LF_HF_RATIO (LF/HF ratio): 0.537482
POWER_LAW (power law behavior): 0.000000