通过numpy FFT进行数值微分 [英] Numerical differentiation via numpy FFT

查看:370
本文介绍了通过numpy FFT进行数值微分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习如何使用numpy进行快速傅立叶变换微分.在下面的代码中,我创建了一个简单的正弦函数,并尝试获取余弦.结果显示在图像中,似乎有一个归一化因子,尽管阅读了文档我还是不明白,这使我无法获得正确的结果.

I am learning how to use numpy for Fast Fourier transform differentiation. In the code below, I create a simple sine function and try to get the cosine. The result is shown in the image, there seems to be a normalization factor which I do not understand despite reading the documentation and which prevents me from getting the correct results.

您能告诉我如何摆脱标准化因子,或者我是否以其他方式失败? 另外请解释为什么数组长度为奇数时,奈奎斯特频率不存在.

Can you tell me how to get rid of the normalization factor or if I am failing in a different way? Also please explain why the Nyquist frequency is not present when the array is length is odd.

x = np.arange(start=-300., stop=300.1, step=0.1)
sine = np.sin(x)

Y = np.fft.rfft(a=sine, n=len(x))
L = 2.*np.pi #period
N = size(Y)

for k, y in enumerate(Y):
    Y[k] *= 2.*np.pi*1j*k/L

# if N is even, the last entry is the Nyquist frequency.
#if N is odd, there it is not there.
if N%2 == 0:
    Y[-1] *= 0.

cosine = np.fft.irfft(a=Y, n=len(x))

推荐答案

您能告诉我如何摆脱标准化因子,或者我是否以其他方式失败?

Can you tell me how to get rid of the normalization factor or if I am failing in a different way?

为术语2.*np.pi*1j*k/L添加np.exp().该术语似乎是相位旋转量,因此其范数应为1.

Add np.exp() for the term 2.*np.pi*1j*k/L. This term seems to be the amount of phase rotation, so their norm should be 1.

for k in range(N):
    Y[k] *= np.exp(2.*np.pi*1j*k/L)

还请解释为什么数组长度为奇数时,奈奎斯特频率不存在.

Also please explain why the Nyquist frequency is not present when the array is length is odd.

这是离散傅里叶变换的本质.简而言之,当采样点 N 的个数为奇数时,不存在等于 N/2 的整数.

It's a nature of discrete Fourier transformation. Briefly, when the number of sampling points N is odd, there is no integer that equals to N/2.

这篇关于通过numpy FFT进行数值微分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆