The program below inverts and differentiates the signals read by
getvec and writes the results with putvec. The output is
readable as record `dif'. A wide variety of simple digital filters
can be modelled on this example; see section Example 7: A General-Purpose FIR Filter, for a more general
approach.
1 #include <stdio.h>
2 #include <ecg/db.h>
3
4 main(argc, argv)
5 int argc;
6 char *argv[];
7 {
8 static DB_Siginfo s[DB_MAXSIG];
9 int i, nsig, nsamp = 1000;
10 DB_Sample vin[DB_MAXSIG], vout[DB_MAXSIG];
11
12 if (argc < 2) {
13 fprintf(stderr, "usage: %s record\n", argv[0]); exit(1);
14 }
15 if ((nsig = isigopen(argv[1], s, DB_MAXSIG)) <= 0) exit(2);
16 if (osigopen("8l", s, nsig) <= 0) exit(3);
17 while (nsamp-- > 0 && getvec(vin) > 0) {
18 for (i = 0; i < nsig; i++)
19 vout[i] -= vin[i];
20 if (putvec(vout) < 0) break;
21 for (i = 0; i < nsig; i++)
22 vout[i] = vin[i];
23 }
24 (void)newheader("dif");
25 dbquit();
26 exit(0);
27 }
Notes:
osigopen
prints an error message.
getvec fails
before 1000 samples have been read, the loop ends prematurely.
osigopen was `8l', we can also
read these files using record `8l'; one reason for making a new
`header' file here is that the `header' file for `8l' may
not necessarily indicate the proper sampling frequency for these
signals.
dbquit to
close the files properly.
Go to the first, previous, next, last section, table of contents.