add spectrum plot
This commit is contained in:
parent
ba62a6cd7d
commit
cca9bb710d
|
@ -0,0 +1,39 @@
|
|||
import PyQt5
|
||||
import pyqtgraph as pg
|
||||
from pyqtgraph.Qt import QtGui, QtCore
|
||||
import numpy as np
|
||||
from scipy.signal import hilbert
|
||||
from scipy.fft import fft, fftfreq
|
||||
from scipy.signal.windows import hamming
|
||||
|
||||
a = 250000
|
||||
b = 450000
|
||||
ch1 = np.load("siglent_ch1.npy")[a:b]
|
||||
ch2 = np.load("siglent_ch2.npy")[a:b]
|
||||
|
||||
ch1 = ch1 - np.mean(ch1)
|
||||
ch2 = ch2 - np.mean(ch2)
|
||||
|
||||
out_samples = []
|
||||
prev_ref = ch1[0]
|
||||
for sample, ref in zip(ch1, ch2):
|
||||
if prev_ref*ref < 0:
|
||||
out_samples.append(sample)
|
||||
prev_ref = ref
|
||||
|
||||
|
||||
app = QtGui.QApplication([])
|
||||
mainwindow = QtGui.QMainWindow()
|
||||
|
||||
widget = pg.PlotWidget()
|
||||
mainwindow.setCentralWidget(widget)
|
||||
|
||||
mainwindow.show()
|
||||
|
||||
out_samples = out_samples*hamming(len(out_samples))
|
||||
|
||||
widget.clear()
|
||||
widget.plot(2*473.6*fftfreq(len(out_samples))[:len(out_samples)//2], np.abs(fft(out_samples))[:len(out_samples)//2])
|
||||
|
||||
app.exec_()
|
||||
|
Loading…
Reference in New Issue