try++

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from scipy import *
from scipy import gplt
from scipy import fftpack
y = [[], [], [], []]
power = period = p_data = [[], [], [], []]
nyquist=1./2
for i in range(32):
y[0].append(math.sin(j)/100.)
y[1] = y[2] = y[3] = y[0]
for i in range(32):
y[1][i] += random.random()
for i in range(1, 64, 2):
if ( random.random() >= 0.85 ) and ( i <= len(y[3]) ):
y[2].insert(y[3][i-1])
y[3].insert(y[2][i-1])
for i in range(0, 4):
Y = fft(y[i])
ni = len(Y)/2
nf = len(Y)/2.0
freq = array(range(ni))/(nf)*nyquist
power[i] = abs( Y[i][1:ni] )**2
period[i] = 1./freq
p_data[i] = Gnuplot.PlotItems.Data(period[i][1:len(period[i])], power[i],y[i])
gplt.plot(p_data[0], p_data[1], p_data[2], p_data[3])
gplt.xaxis((0,64))
gplt.ytitle('|FFT|**2')
gplt.grid("off")
gplt.output('sunspot_period.png','png medium transparent picsize 600 400')