Python: calculates the highest Fourier coefficient of a signal

I am trying to determine the most dominant signal frequency. However, by artificially creating a 50 Hz signal and applying enough nulling to enhance the fft resolution, I get a maximum 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()

Please note that a factor of 49997 corresponds to a frequency of 49.997 Hz due to zero filling.

Editing: an array is exactly 1 second with a 50 Hz signal. The last 999 seconds are zeros to increase the fft resolution to 1 MHz. I have only 1 second of the available signal, from which I need a high frequency, accuracy to mHz

fs = 2**8 49.999, , ...

+4
2

1000 50 : , np.fft.fft, 1 , 999 ). , FFTs , .

, 50000, :

import numpy as np
import matplotlib.pyplot as plt

fs = 2**12

x = np.linspace(0,1000,fs*1000)

signal = np.sin(50*2*np.pi*x)
spect = abs(np.fft.fft(signal))

plt.figure('Four Coef')
plt.plot(spect)
print np.argmax(spect), np.max(spect)

plt.show()

:

50000 2047497.79244

NB1/ , "" ( 1 ).

NB2/ rfft rfftfreq, .

+2

, . ( Sinc- FFT, ) .

0

Source: https://habr.com/ru/post/1598214/


All Articles