简体   繁体   English

使用NumPy进行快速傅立叶变换:为什么看起来像这样?

[英]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: 我一直在使用NumPy数学库,因此使用以下代码进行这样的绘图也是如此:

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 在我看来,它必须看起来像d(x-1)+ d(x-10)... // d是增量函数

(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. 它看起来像“ d(x-0.1)+ d(x-1.5)...”,我想知道为什么。 Problems with fftfreq? fftfreq有问题吗?

It's been many a year since I studied this ... 自从我研究这个以来已经有一年了...

You're expecting to see peaks at 1 and 10 Hz (cycles/sec)? 您是否希望看到1和10 Hz(周期/秒)的峰值? Then you need to change the arguments of the sin functions. 然后,您需要更改sin函数的参数。 sin takes radians for arg. 罪恶将弧度取为arg。 1 Hz is 2*pi radians/sec and 10 Hz is 10*2*pi rad/sec 1 Hz为2 * pi弧度/秒,10 Hz为10 * 2 * pi弧度/秒

Change your signal =np.sin(2*np.pi*t) + np.sin(10*2*np.pi*t) # optimize math as desired. 更改信号= np.sin(2 * np.pi * t)+ np.sin(10 * 2 * np.pi * t)#根据需要优化数学。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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