我是一名Python學習者,正在開發一個與圖像分析有關的小型項目,以瞭解我試圖理解各種python代碼的概念,但是這次我吸了,可以任何人解釋這一點代碼?特別是FFT部分?fft(快速傅立葉變換)的工作原理
class HeartMonitor(object):
def __init__(self, window_duration, fps = 30, min_bpm = 50, max_bpm = 200):
"""
Class which detects heart-beats in a sequence of image colour samples.
@param window_duration The number of seconds of samples to use
@param fps The nominal sample rate
@param min_bpm Minimum cut-off for possible heartrates
@param max_bpm Maximum cut-off for possible heartrates
"""
self.min_bpm = min_bpm
self.max_bpm = max_bpm
# The maximum number of samples to buffer
self.buf_size = int(window_duration*fps)
# Buffer of (timestamp, value) tuples
self.buf = []
@property
def fps(self):
"""
The average framerate/samplerate of the buffer
"""
return float(len(self.buf))/(self.buf[-1][0] - self.buf[0][0])
def get_fft(self):
"""
Perform an Fast-Fourier-Transform on the buffer and return (magnitude,
phase) tuples for each of the bins.
"""
# Get the "ideal" evenly spaced times
even_times = numpy.linspace(self.buf[0][0], self.buf[-1][0], len(self.buf))
# Interpolate the data to generate evenly temporally spaced samples
interpolated = numpy.interp(even_times, *zip(*self.buf))
# Perform the FFT
fft = numpy.fft.rfft(interpolated)
return zip(numpy.abs(fft), numpy.angle(fft))
是你的問題理解FFT或做它的Python代碼? – 2014-10-09 05:20:08
我知道FFT的神權觀念,但不知道這個python代碼如何實現FFT,所以問題是代碼不是FFT – user3218971 2014-10-09 05:27:42