1

I am currently learning Fourier transformation and using Python to play around with it.

I have a code snippet here:

x = np.arange(0,50,0.1)
T = 5
y = np.sin(T*np.pi*x)
freq = np.fft.rfftfreq(x.size)
y_ft = np.fft.rfft(y)
plt.plot(freq, np.abs(y_ft))

It produces a correct chart as following:

enter image description here

But when I change the T into 10, the chart is like this: enter image description here

I was expecting that I will get a similar chart like the first one with a right shift of the peak, because I just enlarged the cycle time.

Why increasing the cycle time would produces such an unexpected result?

2
  • Just as an aside, you talk about "increasing the cycle time" when you change T from 5 to 10. If you mean to set the period of the sinusoid, the correct formula would be y = np.sin(2*np.pi/T*x). Jul 24, 2015 at 6:29
  • Thank you, I didn't realize that I actually increased the frequency!
    – Jim GB
    Jul 25, 2015 at 7:46

1 Answer 1

4

You are effectively sampling a signal. With your code, the frequency you are sampling at is 1/0.1 or 10 rad/second. The frequency of your first sinusoid is just on the Nyquist frequency (5 rad/second). The frequency of your second sinusoid is beyond Nyquist, therefore your signal is not correctly sampled. Solution: increase your sampling frequency (x = np.arange(0, 50, 0.01) for example).

Look at what your T=10 signal looks like when plotted (you can see it doesn't resemble a single sinusoid at the sampling points):

enter image description here

1
  • Thank you for this professional explanation. Since I don't have any background on Signal Processing, you gives me a different insight to explain this result.
    – Jim GB
    Jul 24, 2015 at 4:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.