如何计算Numpy中的傅立叶级数? [英] How to calculate a Fourier series in Numpy?

查看:125
本文介绍了如何计算Numpy中的傅立叶级数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个周期T的周期函数,想知道如何获得傅立叶系数的列表.我尝试使用numpy中的 fft 模块,但是似乎比级数更专注于傅立叶变换. 也许缺乏数学知识,但我看不到如何从fft计算傅立叶系数.

I have a periodic function of period T and would like to know how to obtain the list of the Fourier coefficients. I tried using fft module from numpy but it seems more dedicated to Fourier transforms than series. Maybe it a lack of mathematical knowledge, but I can't see how to calculate the Fourier coefficients from fft.

感谢帮助和/或示例.

推荐答案

最后,最简单的方法(使用riemann和计算系数)是解决我的问题的最可移植/最有效/最可靠的方法:

In the end, the most simple thing (calculating the coefficient with a riemann sum) was the most portable/efficient/robust way to solve my problem:

def cn(n):
   c = y*np.exp(-1j*2*n*np.pi*time/period)
   return c.sum()/c.size

def f(x, Nh):
   f = np.array([2*cn(i)*np.exp(1j*2*i*np.pi*x/period) for i in range(1,Nh+1)])
   return f.sum()

y2 = np.array([f(t,50).real for t in time])

plot(time, y)
plot(time, y2)

给我:

这篇关于如何计算Numpy中的傅立叶级数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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