I am trying to determine the most dominant frequency of a signal. However, when artificially creating a 50 Hz signal and applying sufficient zeropadding to enhance fft resolution, I get a top frequency of 49,997 Hz. For my application this is a significant difference. Did I do something wrong here?
import numpy as np
import matplotlib.pyplot as plt
fs = 2**12
x = np.linspace(0,1,fs+1)
signal = np.sin(50*2*np.pi*x)
spect = abs(np.fft.fft(np.append(signal,np.zeros(999*fs))))
plt.figure('Four Coef')
plt.plot(spect)
plt.axis([49995,49999,2048.01,2048.05])
plt.show()
Note that coefficient 49997 corresponds to a frequency of 49,997 Hz due to the zero-padding.
Edits: The array represents exactly 1 seconds of 50 Hz signal. The last 999 seconds are zeros in order to increase the fft "resolution" to 1 mHz. I have only 1 second of signal available, from which i need the top frequency, accurate up to the mHz
Changing the the sample rate fs = 2**8
gives a maximum of 49.999 so i suppose the way of sampling is critical here...