In [1]:
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [8]:
A = 100 # amplitude
dt = 1/6. # sampling in hours
f = 2.0 # 2 per hours

t = np.arange(0,24, dt)

signal = A*np.sin(2*np.pi*f*t)

fig = figure(figsize=(11,5))
plt.plot(t,signal)
plt.xlabel("Time (hours)")


Out[8]:
<matplotlib.text.Text at 0x7fa1045c87d0>

Fourier


In [9]:
n = len(signal) # length of the signal

k = np.arange(n)

dt = 1/6. # in hours

T = n*dt # sampling points in hours

frq = k/T # two sides frequency range

frq = frq[range(n/2)] # one side frequency range

Y0 = np.fft.fft(signal)/n # fft computing and normalization

Y0 = Y0[range(n/2)] # take only half of the possible frequencies

In [10]:
fig = figure(figsize=(11,5))

plt.plot(frq, abs(Y0), color = 'darkgreen') # plotting the spectrum


plt.xlabel('Freq (hours)')
plt.ylabel('|Y(freq)|')
#plt.ylim(ymax = 0.1)


Out[10]:
<matplotlib.text.Text at 0x7fa1045c8e90>

In [ ]: