I'm playing with FFT at the moment and I try to get periods from noisy signals by recreating this example. While experimenting, I've noticed that after smoothing a quite noisy signal, the result of
fft() is actually the same signal again - which is what I don't understand.
Here is a full example which can be run in an IPython Notebook (You can create a notebook here and run the code if you want).
%matplotlib inline import numpy as np import pandas as pd import matplotlib.pyplot as plt figsize = (16,8) n = 500 ls = np.linspace(0,2*np.pi, n) x_target = np.sin(12*ls) + np.sin(52*ls) x = np.sin(12*ls) + np.sin(52*ls) + np.random.rand(n) * 3.5 x = x - np.mean(x) x_smooth = pd.rolling_mean(pd.DataFrame(x), 14).replace(np.nan, 0.0).as_matrix() x_smooth = x_smooth - np.mean(x_smooth) x_smooth = np.roll(x_smooth, -7) # Getting shwifty and showing what we've got plt.figure(figsize=(16,8)) plt.scatter(ls, x, s=3, c=[1.0,0.0,0.0,1.0]) plt.plot(ls, x_target, color=[1.0,0.0,0.0, 0.3]) plt.plot(ls, x_smooth) plt.legend(["Target", "Smooth", "Noisy Data"]) # Target x_fft = np.abs(np.fft.fft(x_target)) pd.DataFrame(x_fft).plot(figsize=figsize) # Looks like it should x_fft = np.abs(np.fft.fft(x)) pd.DataFrame(x_fft).plot(figsize=figsize) # Plots the same signal? x_fft = np.abs(np.fft.fft(x_smooth)) pd.DataFrame(x_fft).plot(figsize=figsize)
Below you find the resulting plots of this script.
Noisy data with smoothed signal and target function:
FFT of the target
FFT of the noisy data
FFT of the smoothed data
I don't really get why this is the case here. Can somebody explain this to me or am I doing something wrong here?