Reputation: 763
The data in the array freq below is not sorted.
Is there any convenient way to remove the the unecessay straight line from left to right in my plot?
import pylab as pl
import numpy as np
timepoints=np.loadtxt("timesequence",usecols=(1,),unpack=True,delimiter=",")
t=np.histogram(timepoints,bins=500)[0]
sp = np.fft.fft(t)
freq = np.fft.fftfreq(t.shape[-1],d=0.0005)
print freq
pl.plot(freq*2*np.pi, np.sqrt(sp.real**2+sp.imag**2))
pl.show()
Upvotes: 3
Views: 855
Reputation: 1991
As you have it, the plot starts at the peak zero point, then works its way to the right, then jumps to the far left and works its way back to the middle. It is NOT a simple left-to-right kind of time-series (in case that's what you think it is).
One workaround is to plot the positive points in 'freq' separately from the negative points in 'freq'. Replace your pl.plot line of code with the following:
mask = freq>=0
pl.plot(freq[mask]*2*np.pi, np.sqrt(sp[mask].real**2+sp[mask].imag**2))
pl.plot(freq[~mask]*2*np.pi, np.sqrt(sp[~mask].real**2+sp[~mask].imag**2))
ps, You'll need to set the colors so they match.
Upvotes: 1