Note
Go to the end to download the full example code
Spectrogram
Generate spectrogram from tradb. The vallenae.io.TraDatabase.read_continuous_wave
method is used
to read the transient data as a continuous array.
Read transient data as continous array
The signal is exactly cropped to the given time range (time_start, time_stop). Time gaps are filled with 0’s.
Compute Short-Time Fourier Transform (STFT)
Plot time data and spectrogram
fig, ax = plt.subplots(
nrows=2,
sharex=True,
figsize=(8, 6),
tight_layout=True,
gridspec_kw={"height_ratios": (1, 2)},
)
ax[0].plot(t, y * 1e3)
ax[0].set(xlabel="Time [s]", ylabel="Amplitude [mV]", title="Waveform")
ax[1].pcolormesh(tz, fz / 1e3, np.abs(zxx), norm=LogNorm())
ax[1].set(xlabel="Time [s]", ylabel="Frequency [kHz]", title="STFT")
plt.show()
Total running time of the script: (0 minutes 2.220 seconds)