Notebook for exploring ffts for signal processing spectra

Runs 2017/1/9


In [1]:
%matplotlib inline
from __future__ import division
import numpy as np
from scipy import signal 
from matplotlib import pyplot as plt

In [2]:
# num of points
N = 1000

# spacing
T = 1/1000

# evenly spaced data
x = np.linspace(0, T*N, N)

# add random noise in the y-direction
y = 10*np.sin(50* 2*np.pi*x) + 10*np.sin(80 *2*np.pi*x) + 10*np.sin(70 *2*np.pi*x) + 50*np.random.random(1000)

In [3]:
plt.plot(x, y)


Out[3]:
[<matplotlib.lines.Line2D at 0x7f409cc72a90>]

In [4]:
from scipy.fftpack import fft
# half of the freq
xf = np.linspace(0, 1/(2*T), N/2)
yf = fft(y)
plt.plot(xf, 2/N * np.abs(yf[0:int(N/2)]))
plt.grid()
plt.ylim(0,20)


Out[4]:
(0, 20)