-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclifft
executable file
·35 lines (28 loc) · 1.18 KB
/
clifft
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python
import sys
import numpy as np
import math
import subprocess
def main():
bins = 128
signal = np.frombuffer(sys.stdin.read(), dtype=np.complex64)
window = 0.5 * (1.0 - np.cos((2 * math.pi * np.arange(bins)) / bins))
window /= np.sqrt(np.sum(window**2))
segment = int(bins / 2)
nsegments = int(len(signal) / segment)
m = np.repeat(np.reshape(signal[0:segment * nsegments], (nsegments, segment)), 2, axis=0)
t = np.reshape(m[1:len(m) - 1], (nsegments - 1, bins))
psd = np.sum(np.abs(np.fft.fft(np.multiply(t, window)))**2, axis=0) / nsegments
psd = np.concatenate((psd[len(psd)//2:len(psd)], psd[0:len(psd)//2]))
y_axis = np.log10(psd)*10
x_axis = np.arange(len(y_axis), dtype=np.float32)/len(y_axis) - 0.5
gnuplot_cmds = "set terminal dumb 120 36; set xrange [-0.5:0.5];" \
"set yrange [-80:0]; plot \"-\" using 1:2 with lines notitle;"
cmdline = ["gnuplot", "-e", gnuplot_cmds]
process = subprocess.Popen(cmdline, stdin=subprocess.PIPE)
for x, y in zip(x_axis, y_axis):
process.stdin.write(b"%f\t%f\n" % (x, y))
process.stdin.close()
process.wait()
if __name__ == "__main__":
main()