Compare commits

..

2 Commits

Author SHA1 Message Date
809d3ce9fe Cleanup spillover into other areas 2024-05-27 11:51:38 +09:30
fa8332acc9 Final bit of cleanup in selcal-fft 2024-05-27 11:47:45 +09:30
5 changed files with 21 additions and 22 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
build/
.*/

View File

@ -5,29 +5,11 @@ from scipy.io import wavfile
from scipy.fft import fft
from filters import anti_alias
from tones import TONES
from utilities import *
import matplotlib.pyplot as plt
import sys
file_name = sys.argv[1]
def decibels(f):
return 10 * np.log10(f)
def find_top_two_keys(d, threshold):
sorted_items = sorted(d.items(), key=lambda item: item[1], reverse=True)
if len(sorted_items) < 3:
return None
top_two = sorted_items[:2]
third_value = sorted_items[2][1]
if top_two[0][1] - third_value < threshold or top_two[1][1] - third_value < threshold:
return None
return top_two[0][0], top_two[1][0]
# Step 1: Read the WAV file
sample_rate, data = wavfile.read(file_name)
# Handle stereo audio by converting to mono if needed
@ -92,7 +74,7 @@ for i in range(num_segments):
# Only import if we're actually plotting, these imports are pretty heavy.
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui, QtWidgets, QtCore, mkQApp
from pyqtgraph.Qt import QtWidgets, QtCore
app = pg.mkQApp("ImageView Example")
window = QtWidgets.QMainWindow()
@ -108,8 +90,7 @@ fft_view.setImage(fft_results)
fft_view.setRect(QtCore.QRectF(0, 0, len(data) // sample_rate, max_freq))
plot.addItem(fft_view)
# Note JMT: Requires matplotlib installed to use this colormap
colormap = pg.colormap.get("CMRmap", source='matplotlib')
colormap = pg.colormap.get("inferno")
colorbar = pg.ColorBarItem( values=(0,1), colorMap=colormap)
colorbar.setImageItem(fft_view, insert_in=plot)

17
scripts/utilities.py Normal file
View File

@ -0,0 +1,17 @@
import numpy as np
def decibels(f):
return 10 * np.log10(f)
def find_top_two_keys(d, threshold):
sorted_items = sorted(d.items(), key=lambda item: item[1], reverse=True)
if len(sorted_items) < 3:
return None
top_two = sorted_items[:2]
third_value = sorted_items[2][1]
if top_two[0][1] - third_value < threshold or top_two[1][1] - third_value < threshold:
return None
return top_two[0][0], top_two[1][0]

Binary file not shown.