-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfft_spectrum.py
55 lines (50 loc) · 1.83 KB
/
fft_spectrum.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
Author: RedFantom
License: GNU GPLv3
Copyright (c) RedFantom 2019
Convert the results of an FFT transform saved to a log file into a CSV
file. These files can be obtained with the Spectrum Analyzer utility
of the ElvisNX software.
"""
import pandas
import os
folder = "INSERT_PATH_TO_FFT_LOG_DATA"
os.chdir(folder)
wave = "waveformSource signal"
fft = "FFT waveform"
dictionary = dict()
for file in sorted(os.listdir(os.getcwd())):
if not file.endswith(".txt"):
continue
print("Processing:", file, "...", end=" ")
with open(file, "r") as fi:
lines = [l.strip() for l in fi.readlines()]
column = ""
dictionary.clear()
dt = 0.0
for line in lines:
if "waveform" in line:
column = line.replace("\t", "")
if column not in dictionary:
dictionary[column] = {"k": list(), "v": list()}
continue
if "delta" in line:
dt = float(line.split("\t")[1].lower().replace(",", "."))
if line == "" or ("t" in line and "0" in line) or "Unit" in line:
continue
try:
k = float(line.split("\t")[0].lower().replace(",", ".")) / 1000
except ValueError:
k = line.split("\t")[0]
v = float(line.split("\t")[1].lower().replace(",", "."))
dictionary[column]["k"].append(k)
dictionary[column]["v"].append(v)
length = len(dictionary[wave]["k"])
dictionary[wave]["k"] = [t * dt for t in range(length)]
waveform = {"Time": dictionary[wave]["k"], "Value": dictionary[wave]["v"]}
fft_wave = {"Frequency": dictionary[fft]["k"], "Value": dictionary[fft]["v"]}
wave_d = pandas.DataFrame(waveform)
wave_d.to_csv("{}_waveform.csv".format(file.split(".")[0]))
fft_d = pandas.DataFrame(fft_wave)
fft_d.to_csv("{}_fft.csv".format(file.split(".")[0]))
print("Done.")