fft.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:pulseviz 作者: pckbls 项目源码 文件源码
def _sample(self):
        super()._sample()

        self._fft_values[:] = numpy.abs(numpy.fft.rfft(self._window_function * self.buffer))

        if self._output == 'fft':
            pass
        elif self._output == 'psd':
            # Reminder for future-self:
            # Our Input signal is clamped between -1.0 and +1.0 yet if we convert the values above ^ into dB
            # we get values way beyond 0dB which makes no sense. Turns out we have to normalize the resulting
            # vector.
            # Thank you my hero: https://dsp.stackexchange.com/a/32080
            # TODO: This can be pre-calculated!
            self._fft_values[:] = numpy.power(self._fft_values * 2.0, 2) \
                / numpy.power(self._window_function_sum * self._reference_value, 2)
        else:
            raise PulsevizException('This should not happen.')

        if self._scaling == 'lin':
            pass
        elif self._scaling == 'log':
            numpy.seterr(divide='ignore')
            self._fft_values[:] = 10.0 * numpy.log10(self._fft_values)
            numpy.seterr(all='raise')  # TODO: Use result of numpy.geterr instead?
        else:
            raise PulsevizException('This should not happen.')

        if self._scaling == 'log':
            self._fft_values[:] += self._fft_weights
        else:
            self._fft_values[:] *= numpy.power(10, self._fft_weights / 20)  # TODO: Test this.
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号