fix the button action
[beacon-rx-433.git] / output_to_audio.py
1 from pylab import *
2 import scipy.signal as signal
3 import sys, wave, struct, re
4
5 INT = "([-+]?[0-9][0-9]*)"
6
7 wav_fond = wave.open("filter_fond.wav", "w")
8 wav_fond.setnchannels(1)
9 wav_fond.setsampwidth(2)
10 wav_fond.setframerate(5000)
11 wav_harm1 = wave.open("filter_harm1.wav", "w")
12 wav_harm1.setnchannels(1)
13 wav_harm1.setsampwidth(2)
14 wav_harm1.setframerate(5000)
15 wav_other = wave.open("filter_other.wav", "w")
16 wav_other.setnchannels(1)
17 wav_other.setsampwidth(2)
18 wav_other.setframerate(5000)
19
20 pow_fond = []
21 pow_harm1 = []
22 pow_other = []
23 cpt_filter = []
24 detected = []
25
26 while True:
27     l = sys.stdin.readline()
28     if l == "":
29         break
30     m = re.match("%s pow_fond=%s pow_harm1=%s pow_other=%s cpt_filter=%s detected=%s"%(INT, INT, INT, INT, INT, INT), l)
31     if m:
32         n, val_fond, val_harm1, val_other, val_cpt_filter, val_detected = map(int, m.groups())
33         print "pow", n, val_other, val_harm1, val_other, val_cpt_filter, val_detected
34         pow_fond.append(val_fond)
35         pow_harm1.append(val_harm1)
36         pow_other.append(val_other)
37         cpt_filter.append(val_cpt_filter)
38         detected.append(val_detected*500)
39     m = re.match("%s fil_fond=%s fil_harm1=%s fil_other=%s"%(INT, INT, INT, INT), l)
40     if m:
41         n, val_fond, val_harm1, val_other = map(int, m.groups())
42         print "fil", n, val_fond, val_harm1, val_other
43         wav_fond.writeframes(struct.pack("<h", val_fond))
44         wav_harm1.writeframes(struct.pack("<h", val_harm1))
45         wav_other.writeframes(struct.pack("<h", val_other))
46
47 subplot(211)
48 print pow_fond
49 plot(range(len(pow_fond)), pow_fond)
50 plot(range(len(pow_fond)), pow_harm1)
51 plot(range(len(pow_fond)), pow_other)
52 ylabel('Power')
53 xlabel(r'Samples')
54 subplot(212)
55 plot(range(len(cpt_filter)), cpt_filter)
56 plot(range(len(detected)), detected)
57 ylabel('Detected')
58 xlabel(r'Samples')
59
60 # save in a file or display
61 if len(sys.argv) >= 2:
62     savefig(sys.argv[1])
63 else:
64     show()
65
66 sys.exit(0)