i'm trying recreate function discrete fourier transform. in matlab done 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
my attempt in python falling flat because don't know how add 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) coeff in dft nn in range(0,n)])
but isn't correct because need sum on n , add sums together. off?
the equation trying recreate below:
you running 2 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) nn in range(0,n)])
Comments
Post a Comment