def make_spectrogram(self, seg_length, win_flag=True):
"""Computes the spectrogram of the wave.
seg_length: number of samples in each segment
win_flag: boolean, whether to apply hamming window to each segment
returns: Spectrogram
"""
if win_flag:
window = np.hamming(seg_length)
i, j = 0, seg_length
step = seg_length / 2
# map from time to Spectrum
spec_map = {}
while j < len(self.ys):
segment = self.slice(i, j)
if win_flag:
segment.window(window)
# the nominal time for this segment is the midpoint
t = (segment.start + segment.end) / 2
spec_map[t] = segment.make_spectrum()
i += step
j += step
return Spectrogram(spec_map, seg_length)
评论列表
文章目录