当前位置: 首页>>代码示例>>Python>>正文


Python Math.windowed_fft方法代码示例

本文整理汇总了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
开发者ID:Leberwurscht,项目名称:Python-Guitar-Transcription-Aid,代码行数:27,代码来源:Pipeline.py

示例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")
开发者ID:Leberwurscht,项目名称:Python-Guitar-Transcription-Aid,代码行数:75,代码来源:transcribe.py


注:本文中的Math.windowed_fft方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。