next up previous
Up: ECG-based Indices of Physical Previous: Bibliography

Appendix

The C program below determines the period of minimum activity using the techniques described above. Its input should be a list of instantaneous heart rates (in bpm) at uniform intervals of 0.5 seconds; tach[3] can produce these data given a list of beat arrival times. The program makes a measurement of the activity index once every 2.5 minutes; each measurement reflects activity over the previous five minutes.

#include <stdio.h>
#include <math.h>
#define DT (0.5)
#define N 300

main()
{
  double a, amin = -1.0, h[2*N], hs0, hs1, mh,
         p, s;
  int i = 0, i0 = N;
  long t, tmin;

  for (t = 1L; scanf("%lf", &h[i]) == 1; t++) {
    if (++i >= i0+N) {
      if (amin < 0.)
        for (i = 0, hs0 = 0.; i < N; i++)
          hs0 += h[i];
      else hs0 = hs1;
      for (i = i0, hs1 = 0.; i < i0+N; i++)
        hs1 += h[i];
      mh = (hs0 + hs1)/(2*N);
      s = fabs(hs0 - hs1)/N;
      for (i = 0, p = 0.; i < 2*N; i++)
        p += (h[i] - mh)*(h[i] - mh);
      p /= 2*N;
      if (p > 100.) p = 100.;
      a = sqrt((mh-40)*(mh-40) + 10*s*s + 100*p);
      if (mh < 25.) a += 25. - mh;
      if (a < amin || amin < 0.) {
        amin = a;
        tmin = t;
      }
      i = i0 = N - i0;
    }
  }
  if (amin >= 0.)
    printf("Minimum activity from %g to %g\n",
           (tmin - 2*N)*DT, tmin*DT);
}

Author's address: MIT Room E25-505A, Cambridge, MA 02139 USA.


George B. Moody 2002-04-18