本文介绍了离散傅立叶变换的傅立叶级数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过离散傅立叶变换重新创建一个函数.在Matlab中,可以这样进行:
I'm trying to recreate a function from a discrete fourier transform. In Matlab it would be done like this:
function [y] = Fourier(dft,x)
n = length(dft);
y = cos(pi*(x+1)'*(0:n-1))*real(dft)+sin(pi*(x+1)'*(0:n-1))*imag(dft)
end
我在Python中的尝试失败了,因为我不知道如何正确地将所有系数相加
My attempt in Python is falling flat because I don't know how to add up all the coefficients correctly
def reconstruct(dft, x):
n = len(dft)
y = ([(coeff.real)*np.cos(np.pi*x*nn) + (coeff.imag)*np.cos(np.pi*x*nn) for coeff in dft for nn in range(0,n)])
但这是不正确的,因为我需要对n求和并将这些和加在一起.我要去哪里?
But this isn't correct because I need to sum over n and add those sums together. Where am I off?
我要重新创建的方程式如下:
The equation I am trying to recreate is below:
推荐答案
您正在运行两个嵌套循环,而不是一个.试试这个:
You were running two nested loops instead of one. Try this:
y = ([(dft[nn].real)*np.cos(np.pi*x*nn) + (dft[nn].imag)*np.cos(np.pi*x*nn) for nn in range(0,n)])
这篇关于离散傅立叶变换的傅立叶级数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!