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
3 changes: 3 additions & 0 deletions songmatch/addfingerprintstodatabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ def addfingerprintstodatabase (fingerprints):
printToSong[holderfingerprint[0]] = (1,holderfingerprint[1])






25 changes: 13 additions & 12 deletions songmatch/findthreshold.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,26 @@
Outputs: cutoff_log_amplitude - Threshold value between foreground/background of spectrogram
"""





def findthreshold (specArray):
flattenedArray = specArray.flatten()
absArray = np.abs(flattenedArray)
loggedArray = np.log(absArray)
print(loggedArray.shape)
return np.percentile(loggedArray,90)

with open("/Users/caseygoldstein/Week1_Student/Day2/data/trumpet.txt", 'r') as R:
trumpet_audio = np.asarray([int(i) for i in R])

hist,bins = np.histogram(loggedArray,len(loggedArray)//2,density = True)
cumulative_distr = np.zeros(len(hist))
binsize = np.diff(bins)
cumulative_distr = (np.cumsum(hist*binsize))

print('hist:' + str(len(hist)))
bin_index_of_cutoff = np.searchsorted(cumulative_distr, 0.9)
cutoff_log_amplitude = bins[bin_index_of_cutoff]
return cutoff_log_amplitude

sampling_rate = 44100 # sampling rate in Hz

fig,ax = plt.subplots()
S, freqs, times, im = ax.specgram(trumpet_audio, NFFT=4096, Fs=sampling_rate,
window=mlab.window_hanning,
noverlap=4096 // 2)

print(newfindthreshold(S))