/* file: rrgen.c Entry number : 191 Author(s) : D.C. Lin Organization : Ryerson University email address : derlin at acs.ryerson.ca This program should compile without errors or warnings using: gcc -Wall rrgen.c -lm See http://www.physionet.org/challenge/2002/ for further information on the CinC Challenge 2002. This program was used to generate series rr10 and rr37 of the challenge dataset. */ #include #include #include #define SPS 128 /* >>>>>>>>>>>>>>>>>>>> MY define's <<<<<<<<<<<<<<<<<<<< */ /* N is the maximum number of RR intervals; it must be enough to generate a sequence of up to 48 hours */ #define N 131072 #define J 17 #define max(a,b) ((a>b) ? a:b) #define min(a,b) ((a>b) ? b:a) #define dabs(a) ((a>0) ? a:-a) /* >>>>>>>>>>>>>>>>>>> MY functions <<<<<<<<<<<<<<<<<<<< */ float randn() { float R=2,v1,v2; while (R>1) { v1=2*drand48()-1; v2=2*drand48()-1; R=v1*v1+v2*v2; } return(v2*sqrt(-2*log(R)/R)); } void bsort(int *a, int *b, int n) { int i, j; int temp; for (i=0;ib[j]) { temp=b[j]; b[j]=b[i]; b[i]=temp; } } /* >>>>>>>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<< */ float rr[N]; /* generated RR intervals, in seconds */ void initialize(long seed, long tmax) { float alpha=-0.1264, sig0=0.3; float meanRR, stdRR, per_pvc=0.0025; int i,j,k,nsg,nsg_1,npt_sg,LLid,LRid,RLid,RRid,il,ir; float meanr0=0, stdr0=0, mu0, wleft, wright; float midr; static float sigmaj[J], r0[N]; float *r = rr; int ipvc=0, npvc, itmp; static int id[N]; float jump; float maxRR, minRR, RRspan; srand48(seed); meanRR=1.; stdRR=.1; for (i=0;i 15) { midr=(r[j-1]+r[j])*.5; maxRR=-100; minRR=1000; for (k=j-15;k= N) { fprintf(stderr, "rr array is too short -- increase N and try again\n"); exit(1); } return (rr[i++]); } int main(int argc, char **argv) { float t = 0.0; /* sum of intervals since the beginning of the simulation, in seconds */ long ts = 0; /* t, in sample intervals */ long tsp = 0; /* previous value of ts */ long tmax = 24*60*60; /* 24 hours, in seconds */ long seed; /* a 32-bit random variable that can be used to initialize the generator */ long atol(); if (argc < 2) { fprintf(stderr, "usage: %s seed [tmax]\n", argv[0]); exit(1); } seed = atol(argv[1]); if (argc > 2) tmax = atol(argv[2]); initialize(seed, tmax); while ((t += generate()) < tmax) { /* add RR interval to running time */ /* calculate and output a quantized RR interval */ ts = (long)(SPS*t + 0.5); printf("%5.3f\n", (ts - tsp)/((float)SPS)); tsp = ts; } exit(0); }