本文整理汇总了Python中Math.windowed_fft方法的典型用法代码示例。如果您正苦于以下问题:Python Math.windowed_fft方法的具体用法?Python Math.windowed_fft怎么用?Python Math.windowed_fft使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Math
的用法示例。
在下文中一共展示了Math.windowed_fft方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_spectrum
# 需要导入模块: import Math [as 别名]
# 或者: from Math import windowed_fft [as 别名]
def get_spectrum(self, start, stop):
data = self.get_data(start, stop)
if not len(data) > 0:
return numpy.array([]), numpy.array([])
rate = self.caps[0]["rate"]
samples = min(MAX_FFT_SAMPLES, len(data)) # number of data points to consider for each fft
ffts = len(data) / int(samples / 2.0) - 1 # number of ffts
# calculate average over powers
power = 0.0
for i in xrange(ffts):
shift = int(0.5 * i * samples)
power += Math.windowed_fft(data[shift : shift + samples])
power /= ffts
# calculate frequencies
bands = len(power)
frq = 0.5 * (numpy.arange(bands) + 0.5) * rate / bands
return frq, power
示例2: test
# 需要导入模块: import Math [as 别名]
# 或者: from Math import windowed_fft [as 别名]
def test(self, widget):
if not self.project:
return
marker = self.project.timeline.ruler.get_playback_marker()
if not marker:
return
start, duration = marker
power = numpy.array(self.project.appsinkpipeline.get_data(start, start + duration)) ** 2.0
rate = self.project.appsinkpipeline.caps[0]["rate"]
delta_t = self.builder.get_object("delta_t").get_value()
decay = self.builder.get_object("decay").get_value()
separation = self.builder.get_object("beat_separation").get_value()
# delta_t = 0.01
# decay = 0.5 # time needed to get to 1/e
# k*decay = 1
# power(t) = exp(-1)*power(t-decay)
# power(t) = exp(-k*decay)*power(t-decay)
# power(t) = exp(-k*delta_t)*power(t-delta_t)
decay_per_chunk = numpy.exp(-delta_t / decay)
samples = int(rate * delta_t)
limit = numpy.average(power[0:samples])
t = []
level = []
lim = []
tp1 = []
w = Analyze.Analyze()
for i in xrange(1, int(len(power) / samples)):
limit *= decay_per_chunk
chunk = power[samples * i : samples * (i + 1)]
avg_power = numpy.average(chunk)
power_spectrum = Math.windowed_fft(chunk)
bands = len(power_spectrum)
frqs = 0.5 * (numpy.arange(bands) + 0.5) * rate / bands
time = delta_t * i + start
min_frq_idx = numpy.min(numpy.nonzero(frqs > 80.0))
max_frq_idx = numpy.max(numpy.nonzero(frqs < 1000.0))
min_frq = frqs[min_frq_idx]
max_frq = frqs[max_frq_idx]
print frqs[0], min_frq, max_frq, frqs[-1]
total_power1 = numpy.trapz(power_spectrum[min_frq_idx:max_frq_idx], frqs[min_frq_idx:max_frq_idx])
tp1.append(total_power1)
# if avg_power>=limit*(1.0+separation):
# if avg_power>=limit+separation:
# w.add_line(time, color="g")
if avg_power >= limit:
limit = avg_power
t.append(time)
level.append(avg_power)
lim.append(limit)
w.show_all()
w.simple_plot(numpy.array(t), numpy.array(level), color="r")
w.simple_plot(numpy.array(t), numpy.array(tp1), color="b")
w.simple_plot(numpy.array(t), numpy.array(lim), color="g")
# markers
for tap in self.project.timeline.rhythm.taps:
time = tap.get_time()
if not start < time and time < start + duration:
continue
if type(tap.weight) == float:
pass
else:
w.add_line(time, color="r")