import csv
import numpy
import scipy.signal
import matplotlib.pyplot as plt
def main() -> None:
with open('7 — копия (2).csv') as csvfile:
reader = csv.reader(csvfile, delimiter=';', quotechar='\'')
times = []
sticks = []
for i, row in enumerate(reader):
if i > 1:
times.append(float(row[0]))
sticks.append(float(row[1]))
times = numpy.asarray(times)
sticks = numpy.asarray(sticks)
dtt = times[1:]-times[:-1]
time_step = numpy.mean(dtt)
frequencies, times, zxx = scipy.signal.stft(sticks, fs=1/time_step, nperseg=256, noverlap=256-4, boundary=None, detrend='constant')
plt.pcolormesh(times, frequencies[:21], numpy.abs(zxx[:21]), vmin=0, vmax=2.5, shading='auto', cmap='rainbow')
plt.colorbar()
plt.xlabel('time [s]')
plt.ylabel('frequency [hz]')
plt.show()
if __name__ == '__main__':
main()