示例#1
0
    static void Main(string[] argv) {
	int i, nsig, nsamp = 1000;

	if (argv.Length < 1) {
	    Console.WriteLine("usage: example6 record");
	    // Unlike C programs, C# programs do not have any foolproof way
	    // to discover their own names, so the name is given as a constant
	    // above.  The command needed to run this program within a VM
	    // is platform-dependent and likely to be more complex.
	    Environment.Exit(1);
	}
	if ((nsig = wfdb.isigopen(argv[0], null, 0)) <= 0) Environment.Exit(2);
	WFDB_SiginfoArray s = new WFDB_SiginfoArray(nsig);
	WFDB_SampleArray vin = new WFDB_SampleArray(nsig);
	WFDB_SampleArray vout = new WFDB_SampleArray(nsig);
	if (wfdb.isigopen(argv[0], s.cast(), nsig) != nsig)
	    Environment.Exit(2);
	if (wfdb.osigopen("8l", s.cast(), (uint)nsig) <= 0)
	    Environment.Exit(3);
	while (nsamp-- > 0 && wfdb.getvec(vin.cast()) > 0) {
	    for (i = 0; i < nsig; i++) {
		vout.setitem(i, vout.getitem(i) - vin.getitem(i));
	    }
	    if (wfdb.putvec(vout.cast()) < 0) break;
	    for (i = 0; i < nsig; i++) {
		vout.setitem(i, vin.getitem(i));
	    }
	}
	wfdb.newheader("dif");
	wfdb.wfdbquit();
    }
示例#2
0
    static void Main(string[] argv) {
	int btype, i, j, nbeats = 0, nsig, hwindow, window, stoptime = 0;
	WFDB_Anninfo a = new WFDB_Anninfo();
	WFDB_Annotation annot = new WFDB_Annotation();
		
	if (argv.Length < 2) {
	    Console.WriteLine(
		       "usage: example9 annotator record [beat-type from to]");
	    // Unlike C programs, C# programs do not have any foolproof way
	    // to discover their own names, so the name is given as a constant
	    // above.  The command needed to run this program within a VM
	    // is platform-dependent and likely to be more complex.
	    Environment.Exit(1);
	}
	a.name = argv[0]; a.stat = wfdb.WFDB_READ;
	if ((nsig = wfdb.isigopen(argv[1], null, 0)) < 1) Environment.Exit(2);
	WFDB_SiginfoArray s = new WFDB_SiginfoArray(nsig);
	WFDB_SampleArray v = new WFDB_SampleArray(nsig);
	WFDB_SampleArray vb = new WFDB_SampleArray(nsig);
	if (wfdb.wfdbinit(argv[1], a, 1, s.cast(), (uint)nsig) != nsig)
	    Environment.Exit(3);
	hwindow = wfdb.strtim(".05"); window = 2*hwindow + 1;
	long[,] sum = new long[nsig,window];
	btype = (argv.Length > 2) ? wfdb.strann(argv[2]) : wfdb.NORMAL;
	if (argv.Length > 3) wfdb.iannsettime(wfdb.strtim(argv[3]));
	WFDB_Siginfo s_0_ = s.getitem(0);
	if (argv.Length > 4) {
	    if ((stoptime = wfdb.strtim(argv[4])) < 0)
		stoptime = -stoptime;
	    if (s_0_.nsamp > 0 && stoptime > s_0_.nsamp)
		stoptime = s_0_.nsamp;
	}
	else stoptime = s_0_.nsamp;
	if (stoptime > 0) stoptime -= hwindow;
	while (wfdb.getann(0, annot) == 0 && annot.time < hwindow)
			;
	do {
	    if (annot.anntyp != btype) continue;
	    wfdb.isigsettime(annot.time - hwindow - 1);
	    wfdb.getvec(vb.cast());
	    for (j = 0; j < window && wfdb.getvec(v.cast()) > 0; j++)
		for (i = 0; i < nsig; i++)
		    sum[i,j] += v.getitem(i) - vb.getitem(i);
	    nbeats++;
	} while (wfdb.getann(0, annot) == 0 &&
		 (stoptime == 0L || annot.time < stoptime));
	if (nbeats < 1) {
	    Console.WriteLine("example9: no `" + wfdb.annstr(btype) +
			      "' beats found");
	    Environment.Exit(4);
	}
	Console.WriteLine("Average of {0} `{1}' beats:", nbeats,
			  wfdb.annstr(btype));
	for (j = 0; j < window; j++)
	    for (i = 0; i < nsig; i++)
		Console.Write( "{0:G6}{1}", (double)sum[i,j]/nbeats,
			       ((i < nsig-1) ? "\t" : "\n"));
	wfdb.wfdbquit();
    }
示例#3
0
    static void Main(string[] argv) {
        WFDB_SiginfoArray siarray = new WFDB_SiginfoArray(2);
        if (wfdb.isigopen("100s", siarray.cast(), 2) < 2)
            Environment.Exit(1);
        WFDB_SampleArray v = new WFDB_SampleArray(2);
        for (int i = 0; i < 10; i++) {
            if (wfdb.getvec(v.cast()) < 0)
                break;
	    Console.WriteLine("\t" + v.getitem(0) + "\t" + v.getitem(1));
        }
    }
示例#4
0
    static void Main(string[] argv) {
	double[] c; double vv;
	int i, j, nc = argv.Length - 4, nsig, nsamp, t;
		
	if (argv.Length < 3) {
	    Console.WriteLine(
		 "usage: example7 record start duration [ coefficients ... ]");
	    // Unlike C programs, C# programs do not have any foolproof way
	    // to discover their own names, so the name is given as a constant
	    // above.  The command needed to run this program within a VM
	    // is platform-dependent and likely to be more complex.
	    Environment.Exit(1);
	}
	if (nc < 1) {
	    nc = 1;
	    c = new double[1];
	    c[0] = 1.0;
	}
	else {
	    c = new double[nc];
	}
	for (i = 0; i < nc; i++)
	    c[i] = Double.Parse(argv[i+3]);
	if ((nsig = wfdb.isigopen(argv[0], null, 0)) < 1)
	    Environment.Exit(3);
	WFDB_SiginfoArray s = new WFDB_SiginfoArray(nsig);
	WFDB_SampleArray v = new WFDB_SampleArray(nsig);
	if (wfdb.isigopen(argv[0], s.cast(), nsig) != nsig)
	    Environment.Exit(3);
	if (wfdb.isigsettime(wfdb.strtim(argv[1])) < 0)
	    Environment.Exit(4);
	if ((nsamp = wfdb.strtim(argv[2])) < 1) {
	    Console.WriteLine("example7: inappropriate value for duration");
	    Environment.Exit(5);
	}
	if (wfdb.osigopen("16l", s.cast(), (uint)nsig) != nsig)
	    Environment.Exit(6);
		
	wfdb.sample(0, 0);
	for (t = 0; t < nsamp && wfdb.sample_valid() == 1; t++) {
	    for (j = 0; j < nsig; j++) {
		for (i = 0, vv = 0.0; i < nc; i++)
		    if (c[i] != 0.0) vv += c[i]*wfdb.sample((uint)j, t+i);
		v.setitem(j, (int)vv);
	    }
	    if (wfdb.putvec(v.cast()) < 0) break;
	}
		
	wfdb.newheader("out");
	wfdb.wfdbquit();
    }
示例#5
0
        /// <summary>
        /// Retrieves a frame of data for each signal in the group or record.
        /// </summary>
        /// <param name="frameData">Data class to be initialized and filled with data.</param>
        /// <param name="siArray">Signal Information array for the signals being read.</param>
        /// <param name="numSignals">Number of signals being read (must match the dimension of siArray).</param>
        /// <param name="errMsg">String where error messages, if any, are written.</param>
        /// <returns>True if successful, False otherwise.  If False, then errMsg contains the explanation why.</returns>
        public static bool GetSignalFrame(
            ref WFDB_SampleArray frameData,
            WFDB_SiginfoArray siArray,
            int numSignals,
            ref string errMsg)
        {
            int numSamples;

            numSamples = siArray.getitem(0).spf *numSignals;
            errMsg     = "";
            try
            {
                frameData = new WFDB_SampleArray(numSamples);
                int result = wfdb.getframe(frameData.cast());
                if (result == -1)
                {                       // End of data
                    errMsg = "End of data reached.";
                    return(false);
                }
                else if (result == -3)
                {                       // Failure:  unexpected physical end of file
                    errMsg = "Failure:  unexpected physical end of file.";
                    return(false);
                }
                else if (result == -4)
                {                       // Failure:  checksum error (detected only at end of file)
                    errMsg = "Failure:  checksum error (detected at end of file).";
                    return(false);
                }
                else if (result < numSignals)
                {                       // Something wrong!  We didn't get the signals we expect!
                    errMsg = "Failure:  requested " + numSignals + " signals, but only received data for " + result + ".";
                    return(false);
                }
                // else, it's OK
            }
            catch (Exception getframeException)
            {
                while (getframeException.InnerException != null)
                {                       // Drill down:
                    getframeException = getframeException.InnerException;
                }
                errMsg += getframeException.ToString() + newLine;
                MessageBox.Show("Exception occurred trying getframe(...): \n"
                                + getframeException.ToString() + "\n");
                return(false);
            }
            // No exception?  Success!
            return(true);
        }
示例#6
0
    static void Main(string[] argv) {
	string record = null;

	if (argv.Length < 2) {
	    usage();
	    Environment.Exit(2);
	}

	for (int i = 0; i < argv.Length; i++) {
	    if (argv[i] == "-r") {
		record = argv[++i];
	    } else {
		usage();
	    }
	}

	if (record == null) {
	    usage();
	    Environment.Exit(2);
	}

	int nsig, n=0;    
	nsig = wfdb.isigopen(record, null, 0);
	    
	if (nsig <= 0) {
	    usage();
	    Environment.Exit(2);
	}

	WFDB_SiginfoArray siarray = new WFDB_SiginfoArray(nsig);
	
	wfdb.isigopen(record, siarray.cast(), nsig);
	WFDB_SampleArray v = new WFDB_SampleArray(nsig);		

	while (wfdb.getvec(v.cast()) > 0) {
	    Console.Write(n);
	    for (int i=0; i < nsig; i++) {
		Console.Write("\t" + v.getitem(i));
	    }
	    Console.WriteLine();
	    n++;
	}
	
	wfdb.wfdbquit();
    }
示例#7
0
    static void Main(string[] argv) {
	int filter, time=0, slopecrit, sign=1, maxslope=0, nsig, nslope=0,
	    qtime=0, maxtime=0, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9,
	    ms160, ms200, s2, scmax, scmin = 0;
	WFDB_Anninfo a = new WFDB_Anninfo();
	WFDB_Annotation annot = new WFDB_Annotation();

	if (argv.Length < 1) {
	    Console.WriteLine("usage: example10 record [threshold]");
	    // Unlike C programs, C# programs do not have any foolproof way
	    // to discover their own names, so the name is given as a constant
	    // above.  The command needed to run this program within a VM
	    // is platform-dependent and likely to be more complex.
	    Environment.Exit(1);
	}
	a.name = "qrs"; a.stat = wfdb.WFDB_WRITE;
		
	if ((nsig = wfdb.isigopen(argv[0], null, 0)) < 1)
	    Environment.Exit(2);
	WFDB_SiginfoArray s = new WFDB_SiginfoArray(nsig);
	WFDB_SampleArray v = new WFDB_SampleArray(nsig);
	if (wfdb.wfdbinit(argv[0], a, 1, s.cast(), (uint)nsig) != nsig)
	    Environment.Exit(2);
	if (wfdb.sampfreq(null) < 240.0 || wfdb.sampfreq(null) > 260.0)
	    wfdb.setifreq(250.0);
	if (argv.Length > 1) scmin = wfdb.muvadu(0, Int16.Parse(argv[1]));
	if (scmin < 1) scmin = wfdb.muvadu(0, 1000);
	slopecrit = scmax = 10 * scmin;
	ms160 = wfdb.strtim("0.16"); ms200 = wfdb.strtim("0.2");
	s2 = wfdb.strtim("2");
	annot.subtyp = 0; annot.chan = 0; annot.num = 0; annot.aux = null;
	wfdb.getvec(v.cast());
	t9 = t8 = t7 = t6 = t5 = t4 = t3 = t2 = t1 = v.getitem(0);
		
	do {
	    filter = (t0 = v.getitem(0)) + 4*t1 + 6*t2 + 4*t3 + t4
		            - t5         - 4*t6 - 6*t7 - 4*t8 - t9;
	    if (time % s2 == 0) {
		if (nslope == 0) {
		    slopecrit -= slopecrit >> 4;
		    if (slopecrit < scmin) slopecrit = scmin;
		}
		else if (nslope >= 5) {
		    slopecrit += slopecrit >> 4;
		    if (slopecrit > scmax) slopecrit = scmax;
		}
	    }
	    if (nslope == 0 && Math.Abs(filter) > slopecrit) {
		nslope = 1; maxtime = ms160;
		sign = (filter > 0) ? 1 : -1;
		qtime = time;
	    }
	    if (nslope != 0) {
		if (filter * sign < -slopecrit) {
		    sign = -sign;
		    maxtime = (++nslope > 4) ? ms200 : ms160;
		}
		else if (filter * sign > slopecrit &&
			 Math.Abs(filter) > maxslope)
		    maxslope = Math.Abs(filter);
		if (maxtime-- < 0) {
		    if (2 <= nslope && nslope <= 4) {
			slopecrit += ((maxslope>>2) - slopecrit) >> 3;
			if (slopecrit < scmin) slopecrit = scmin;
			else if (slopecrit > scmax) slopecrit = scmax;
			annot.time = wfdb.strtim("i") - (time - qtime) - 4;
			annot.anntyp = wfdb.NORMAL; wfdb.putann(0, annot);
			time = 0;
		    }
		    else if (nslope >= 5) {
			annot.time = wfdb.strtim("i") - (time - qtime) - 4;
			annot.anntyp = wfdb.ARFCT; wfdb.putann(0, annot);
		    }
		    nslope = 0;
		}
	    }
	    t9 = t8; t8 = t7; t7 = t6; t6 = t5; t5 = t4;
	    t4 = t3; t3 = t2; t2 = t1; t1 = t0; time++;
	} while (wfdb.getvec(v.cast()) > 0);

	wfdb.wfdbquit();		
    }