1

The original data is on the google drive. It is a two columns data, t and x. I did the following discrete fft transform. I don't quite understand that the main peak(sharp one) has a lower height than the side one. The second the subplot shows that it is indeed that the sharp peak(most close to 2.0) is the main frequency. The code and the figure is as follows:

import numpy as np
import math
import matplotlib.pyplot as plt
from scipy.fftpack import fft,fftfreq

freqUnit=0.012/(2*np.pi)
data = np.loadtxt(fname='data.txt')
t = data[:,0]
x = data[:,1]
n=len(t)
d=t[1]-t[0]

fig=plt.figure()
ax1=fig.add_subplot(3,1,1)
ax2=fig.add_subplot(3,1,2)
ax3=fig.add_subplot(3,1,3)

y = abs(fft(x))
freqs = fftfreq(n, d)/freqUnit

ax1.plot(t, x)
ax2.plot(t, x)
ax2.set_xlim(40000,60000)
ax2.set_ylim(0.995,1.005)
ax3.plot(freqs,y,'-.')
ax3.set_xlim(0,4)
ax3.set_ylim(0,1000)
plt.show()

enter image description here

an offer can't refuse
  • 4,245
  • 5
  • 30
  • 50
  • I'm not sure I understand your argument why the main frequency is 2; I'm also not sure where the 0.012 in your freqUnit comes from. –  Nov 18 '15 at 04:45
  • How is the data in `data.txt` generated? – fjarri Nov 18 '15 at 05:04
  • I suggest the 2.05 frequency is actually (almost) the dominant frequency (2.0 and 2.05 are probably equal). You're seeing the 2.0 most clearly, but you also see their difference: the f=0.05 envelope. Thus, unless you have some compelling reason to *know* that your dominant frequency is 2.0, the result is simply that this is a combination of f = 2.0 and f = 2.05. –  Nov 18 '15 at 06:15
  • @Evert The reason from the figure is that 2.0 frequency is sharp. – an offer can't refuse Nov 18 '15 at 07:35
  • @fjarri from a research problem. – an offer can't refuse Nov 18 '15 at 07:35

1 Answers1

0

You need to apply a window function prior to your FFT, otherwise you will see artefacts such as the above, particularly where a peak in the spectrum does not correspond directly with an FFT bin centre.

See "Why do I need to apply a window function to samples when building a power spectrum of an audio signal?" question for further details.

Community
  • 1
  • 1
Paul R
  • 208,748
  • 37
  • 389
  • 560
  • Do you also suggests my frequency is not 2.0, but the larger one? Or do you suggest that the material you provided may make my main peak (in my opinion is 2.0) larger after apply a window function? – an offer can't refuse Nov 18 '15 at 08:21
  • You will get a much more accurate peak if you apply a window function - and yes, depending on the exact frequencies of the two components, you may well see a relative change in the magnitudes of the two peaks in your example above. – Paul R Nov 18 '15 at 08:41