fft over a rolling sample window for greater bin precision
This commit is contained in:
parent
cf8a9dcfc1
commit
8aecf684f9
@ -95,13 +95,18 @@ delta_f = sample_rate / segment_size
|
||||
# Determine the bin range for desired frequency range (100 Hz to 2000 Hz)
|
||||
high_bin = int(max_freq / delta_f)
|
||||
|
||||
seg_off = int(sample_rate * 0.1)
|
||||
act_segs = len(filtered_data) // seg_off
|
||||
|
||||
# Initialize a 2D array to store DFT results (magnitude spectrum)
|
||||
# Only store the bins within the desired frequency range
|
||||
dft_results = np.zeros((num_segments, high_bin))
|
||||
dft_results = np.zeros((act_segs, high_bin))
|
||||
|
||||
for i in range(num_segments):
|
||||
start = i * segment_size
|
||||
end = start + segment_size
|
||||
for i in range(act_segs):
|
||||
end = (i+1) * seg_off
|
||||
start = end - segment_size
|
||||
|
||||
try:
|
||||
segment = filtered_data[start:end]
|
||||
|
||||
# Step 4: Apply the DFT
|
||||
@ -122,7 +127,9 @@ for i in range(num_segments):
|
||||
|
||||
codes = get_largest_two_indices(scores, 3.0)
|
||||
if codes:
|
||||
print([frequencies[code] for code in codes])
|
||||
print([frequencies[code] for code in sorted(codes)])
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
# Step 5: Plot the spectrogram
|
||||
|
||||
Loading…
Reference in New Issue
Block a user