# from scipy import import Gnuplot from scipy import fftpack import Gnup

 ``` 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 38 39 40 41 42 43 44 45 46 47 48``` ```from scipy import * import Gnuplot from scipy import fftpack import Gnuplot import math import copy y = [[], [], [], []] power = copy.deepcopy(y) period = copy.deepcopy(y) p_data = [ [[],[]] , [[],[]] , [[],[]] , [[],[]] ] nyquist=1./2 for i in xrange(32): y[0].append(math.sin(i)/100.) for i in xrange(1,4): y[i] = copy.deepcopy(y[0]) # randomised y for i in xrange(32): y[1][i] += random.random() # random inserts and doubled range for i in xrange(1, 63, 2): if ( random.random() >= 0.75 ) and ( i < len(y[2]) ): y[2].insert(i-1, y[2][i-1]) y[3].insert(i-1, y[3][i-1]) for i in xrange(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[1:ni] )**2 period[i] = 1./freq data1 = zip(range(len(y[i])-1), y[i]) data2 = zip(period[i][1:len(period[i])], power[i]) p_data[i][0] = Gnuplot.PlotItems.Data(data1, with="lines", title="signal" ) p_data[i][1] = Gnuplot.PlotItems.Data(data2, with="lines", title="fft power" ) plt = Gnuplot.Gnuplot() plt.plot(p_data[0][0], p_data[0][1], p_data[1][0], p_data[1][1], p_data[2][0], p_data[2][1], p_data[3][0], p_data[3][1]) #plt.xaxis((0,64)) #plt.ytitle('|FFT|**2') #plt.grid("off") #plt.output('sunspot_period.png','png medium transparent picsize 600 400') ```