简体   繁体   中英

Fast Fourier Transform using NumPy: why it looks like this?

Fast Fourier Transform is fast method of Discrete Fourier Transformation calculation, as far as I understood.

I've been playing with NumPy math library, as so has such plot with this code:

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

t = np.arange(0, 10, step=0.001)
signal = np.sin(t) + np.sin(10*t)
sp = fft(signal)
freq = fftfreq(signal.size, d=0.001)
plt.plot(freq, sp)
plt.show()

It seems to me, that must look just like d(x-1) + d(x-10) ... // d is delta-function

(Discrete Fourier Transformation must look like simple Fourier Transformation, but with sloping edges, as far as I understand)

But it doesn't. it looks like "d(x-0.1) + d(x-1.5) ..." and I wonder why. Problems with fftfreq?

It's been many a year since I studied this ...

You're expecting to see peaks at 1 and 10 Hz (cycles/sec)? Then you need to change the arguments of the sin functions. sin takes radians for arg. 1 Hz is 2*pi radians/sec and 10 Hz is 10*2*pi rad/sec

Change your signal =np.sin(2*np.pi*t) + np.sin(10*2*np.pi*t) # optimize math as desired.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM