Debian Codegraph @

biosig4c++/python/example.py

raw symbols SCIP
1 import biosig
2 import numpy as S
3
4
5 def testsin(sig, sr, freq):
6 quartper = int(sr / freq * .25)
7 x = S.sqrt(sig[:-quartper] ** 2 + sig[quartper:] ** 2)
8 ampl = x.mean()
9 err = x.std()
10 if err > ampl/3:
11 return 0
12 return ampl
13
14 import sys
15
16 if len(sys.argv) < 3:
17 print("usage:\n%s filename.bdf freq" % sys.argv[0])
18 sys.exit(1)
19
20 fname = sys.argv[1]
21 sr = int(sys.argv[2])
22 print("\nexample.py\nchecking file %s" % fname)
23 sig=biosig.data(fname)
24 HDR=biosig.header(fname)
25
26
27 freq = 3
28 print("Looking for sinusoidal signals at %f Hz" % freq)
29 sig = sig - S.mean(sig, axis=1)[:, S.newaxis]
30 a1 = testsin(sig[0], sr, freq)
31 print("channel A1, peak to peak amplitude of sin at %f Hz: %f" % (freq, 2*a1))
32 a2 = testsin(sig[1], sr, freq)
33 print("channel A2, peak to peak amplitude of sin at %f Hz: %f" % (freq, 2*a2))
34 a3 = testsin(sig[0] + 2*sig[1], sr, freq)
35 print("channel A1 + 2*A2, peak to peak amplitude of sin at %f Hz: %f" % (freq, 2*a3))
36 a4 = testsin(sig[2], sr, freq)
37 print("status channel, peak to peak amplitude of sin at %f Hz: %f" % (freq, 2*a4))