1
votes

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?

1
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).chthonicdaemon
Thank you, I didn't realize that I actually increased the frequency!Jim GB

1 Answers

4
votes

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