Why does FFT not have an effect on my smoothed signal? 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?
The answer is that the resulting vector from 

x_smooth = pd.rolling_mean(pd.DataFrame(x), 14).replace(np.nan, 0.0).as_matrix()


was not flat.

I just had to change

x_smooth = x_smooth - np.mean(x_smooth)


to

x_smooth = (x_smooth - np.mean(x_smooth)).flatten()


which changes a vector from

[...
 [  3.53890989e-01]
 [  1.21347337e-01]
 [ -3.39968386e-01]
 [ -5.37617124e-01]
 [ -5.20015023e-01]
 [ -5.57602781e-01]
 [ -5.89304486e-01]
 [ -6.27991220e-01]
 [ -7.61544946e-01]
 ...]


to something like:

[...
 -0.56731051 -0.59901221 -0.63769895 -0.77125267 -0.89067055 -1.28890512
 -1.49325225 -1.59707353 -1.6298505  -1.42489726 -1.296161   -1.01562861
 -0.76996748 -0.75370003 -0.80788025 -0.8353555  -0.78678532 ...]


and we finally get