def amplitude_stream(data, sr, fftn, step, lowcut, highcut):
'''returns an iterator with the start time in seconds
and threshold value for each chunk'''
from scipy.signal import hamming
all_fft_freqs = np.fft.fftfreq(fftn, sr** -1)
fft_freqs = (all_fft_freqs >= lowcut) & (all_fft_freqs <= highcut)
window = hamming(fftn)
data = data.ravel()
for i in range(0, len(data) - fftn, step):
x = data[i:i + fftn] * window
fft = np.fft.fft(x, fftn)[fft_freqs]
time = (i + fftn / 2) / sr
yield time, np.mean(np.log(np.abs(fft)))
评论列表
文章目录