mirror of
https://github.com/okalachev/flix.git
synced 2025-07-27 17:49:33 +00:00
Add tool for plotting fft graphs of log entries
This commit is contained in:
parent
dbd413c234
commit
88f7615089
44
tools/fft.py
Executable file
44
tools/fft.py
Executable file
@ -0,0 +1,44 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
"""Show Fast Fourier Transform plot for log entry.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
fft.py <csv_log_file> <log_entry>
|
||||||
|
"""
|
||||||
|
|
||||||
|
import docopt
|
||||||
|
import csv
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
args = docopt.docopt(__doc__)
|
||||||
|
log_file = args['<csv_log_file>']
|
||||||
|
log_entry = args['<log_entry>']
|
||||||
|
|
||||||
|
csv_reader = csv.reader(open(log_file, 'r'), delimiter=',')
|
||||||
|
header = next(csv_reader)
|
||||||
|
log_entry_index = header.index(log_entry)
|
||||||
|
|
||||||
|
data = [[float(value) for value in row] for row in csv_reader]
|
||||||
|
data = sorted(data, key=lambda row: row[0])
|
||||||
|
records = [row[log_entry_index] for row in data]
|
||||||
|
duration = data[-1][0] - data[0][0]
|
||||||
|
sample_rate = len(data) / duration
|
||||||
|
|
||||||
|
print('Duration: ', duration)
|
||||||
|
print('Mean sample rate: ', sample_rate)
|
||||||
|
print('Mean dt: ', 1 / sample_rate)
|
||||||
|
|
||||||
|
N = int(sample_rate * duration)
|
||||||
|
|
||||||
|
yf = np.fft.rfft(records)
|
||||||
|
xf = np.fft.rfftfreq(N, 1 / sample_rate)
|
||||||
|
|
||||||
|
plt.plot(xf, np.abs(yf))
|
||||||
|
plt.title('FFT of ' + log_entry)
|
||||||
|
plt.xlabel('Frequency')
|
||||||
|
plt.ylabel('Amplitude')
|
||||||
|
plt.grid(True, which='both', color='#eeeeee')
|
||||||
|
plt.minorticks_on()
|
||||||
|
plt.get_current_fig_manager().set_window_title(log_entry)
|
||||||
|
plt.show()
|
Loading…
x
Reference in New Issue
Block a user