From fae45d8ca319f7da354ce19b5f25e8c77d22b9aa Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 27 Dec 2018 22:47:44 +0100 Subject: [PATCH] Returning only the real part of the FFT --- platypush/plugins/sound/core.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/platypush/plugins/sound/core.py b/platypush/plugins/sound/core.py index 6018fc58fa..0f4b00a78d 100644 --- a/platypush/plugins/sound/core.py +++ b/platypush/plugins/sound/core.py @@ -160,8 +160,8 @@ class Sound(object): def fft(self, t_start=0., t_end=0., samplerate=_DEFAULT_SAMPLERATE, freq_range=None, freq_buckets=None): """ - Get the Fourier transform associated to a time-bounded sample of this - sound + Get the real part of the Fourier transform associated to a time-bounded + sample of this sound :param t_start: Start offset for the wave in seconds. Default: 0 :type t_start: float @@ -189,7 +189,8 @@ class Sound(object): freq_range = (0, int(samplerate/2)) wave = self.get_wave(t_start=t_start, t_end=t_end, samplerate=samplerate) - fft = np.fft.fft(wave.reshape(len(wave)))[freq_range[0]:freq_range[1]] + fft = np.fft.fft(wave.reshape(len(wave))) + fft = fft.real[freq_range[0]:freq_range[1]] if freq_buckets is not None: fft = np.histogram(fft, bins=freq_buckets) @@ -321,8 +322,8 @@ class Mix(object): def fft(self, t_start=0., t_end=0., samplerate=Sound._DEFAULT_SAMPLERATE, freq_range=None, freq_buckets=None): """ - Get the Fourier transform associated to a time-bounded sample of this - mix + Get the real part of the Fourier transform associated to a time-bounded + sample of this mix :param t_start: Start offset for the wave in seconds. Default: 0 :type t_start: float @@ -350,7 +351,8 @@ class Mix(object): freq_range = (0, int(samplerate/2)) wave = self.get_wave(t_start=t_start, t_end=t_end, samplerate=samplerate) - fft = np.fft.fft(wave.reshape(len(wave)))[freq_range[0]:freq_range[1]] + fft = np.fft.fft(wave.reshape(len(wave))) + fft = fft.real[freq_range[0]:freq_range[1]] if freq_buckets is not None: fft = np.histogram(fft, bins=freq_buckets)