Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np
import matplotlib.pyplot as plt
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
from pyqtgraph.Qt import QtCore, QtGui, QtWidgets
from src.microphone import MicrophoneRecorder


Expand All @@ -27,17 +27,24 @@ def generatePgColormap(cm_name):
N_FFT = 4096
FREQ_VECTOR = np.fft.rfftfreq(N_FFT, d=TIME_VECTOR[1] - TIME_VECTOR[0])
WATERFALL_FRAMES = int(1000 * 2048 // N_FFT)
TIMEOUT = TIME_VECTOR.max()
TIMEOUT = int(TIME_VECTOR.max())
EPS = 1e-8


app = pg.mkQApp()

recorder = MicrophoneRecorder(sample_rate=SAMPLE_RATE, chunksize=CHUNKSIZE)
recorder.start()

win = pg.GraphicsWindow()
win = QtWidgets.QMainWindow()
cw = pg.GraphicsLayoutWidget()
win.show()
win.resize(1000, 600)
win.setCentralWidget(cw)
win.setWindowTitle('pyqtgraph spectrographer')

waveform_plot = win.addPlot(title="Waveform")

waveform_plot = cw.addPlot(title="Waveform")
waveform_plot.showGrid(x=True, y=True)
waveform_plot.enableAutoRange('xy', False)
waveform_plot.setXRange(TIME_VECTOR.min(), TIME_VECTOR.max())
Expand All @@ -61,7 +68,7 @@ def update_waveform():
timer.timeout.connect(update_waveform)
timer.start(TIMEOUT)

fft_plot = win.addPlot(title='FFT plot')
fft_plot = cw.addPlot(title='FFT plot')
fft_curve = fft_plot.plot(pen='y')
fft_plot.enableAutoRange('xy', False)
fft_plot.showGrid(x=True, y=True)
Expand All @@ -86,10 +93,10 @@ def update_fft():
timer_fft.timeout.connect(update_fft)
timer_fft.start(TIMEOUT)

win.nextRow()
cw.nextRow()

image_data = np.random.rand(20, 20)
waterfall_plot = win.addPlot(title='Waterfall plot', colspan=2)
waterfall_plot = cw.addPlot(title='Waterfall plot', colspan=2)
waterfall_plot.setLabel('left', "Frequency", units='Hz')
waterfall_plot.setLabel('bottom', "Time", units='s')
waterfall_plot.setXRange(0, WATERFALL_FRAMES * TIME_VECTOR.max())
Expand All @@ -99,7 +106,11 @@ def update_fft():
lut = generatePgColormap('viridis')
waterfall_image.setLookupTable(lut)
# set scale: x in seconds, y in Hz
waterfall_image.scale(CHUNKSIZE / SAMPLE_RATE, FREQ_VECTOR.max() * 2. / N_FFT)
scale_factor = CHUNKSIZE / SAMPLE_RATE, int(FREQ_VECTOR.max()) * 2. / N_FFT
tr = QtGui.QTransform()
tr.scale(*scale_factor)
waterfall_image.setTransform(tr)
#waterfall_image.scale(scale_factor)


def update_waterfall():
Expand All @@ -119,6 +130,5 @@ def update_waterfall():

if __name__ == '__main__':
import sys

if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
pg.exec()
14 changes: 7 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
cycler==0.10.0
cycler==0.11.0
kiwisolver==1.1.0
matplotlib==3.1.1
numpy==1.17.3
PyAudio==0.2.11
numpy~=1.21.6
PyAudio==0.2.13
pyparsing==2.4.2
PyQt5==5.13.1
PyQt5-sip==12.7.0
pyqtgraph==0.10.0
PyQt5~=5.15.9
PyQt5-sip~=12.12.2
pyqtgraph==0.13.3
python-dateutil==2.8.0
scipy==1.3.1
scipy~=1.11.2
six==1.12.0