I am trying to write a program to compute the magnitude and phase of a specific, non-integer frequency component (i.e. given a sampled finite signal of length $N$, I want to know the magnitude and phase of the spectrum at frequency 40.678 Hz).
I tried using the equation for the Discrete Time Fourier Transform:
$$ X(\omega) = \sum_{n=-\infty}^{\infty} x[n] e^{-j\omega n} = \sum_{n=0}^{N-1} x[n] e^{-j\omega n} $$
such that
$$ X(2\pi\cdot40.678) = \sum_{n=0}^{N-1} x[n] e^{-j 2\pi\cdot40.678\cdot n} $$
I did this as follows:
t = np.linspace(0,1,100)
x = np.sin(2*np.pi*40.678*t)
Xf = 0
for n in range(len(x)):
Xf += (x[n]*np.exp((-np.complex(0,1))*2*np.pi*40.678*n))
print(abs(Xf))
Which printed $0.6149015687259044$.
I know that this is wrong because if I do an FFT as follows:
X = np.fft.fft(x)
plt.figure();
plt.plot(abs(X))
I can see peaks of magnitude $50$ at around (what I assume after correcting the axis is) 40.678 Hz.
What is the reason for this difference? I also tried the equation of the DFT just like I did with the DTFT code above this time to measure magnitude at 50 Hz of a sinusoid of frequency 50 Hz and I got a completely wrong value again as compared to what the plot of the FFT shows.
What causes this discrepancy?
Thank you.