An FFT splits a signal into frequencies. rfft is for real input.
Goal
Find the peak Hertz of an 8 Hz sine plus noise.
from scipy.fft import rfft, rfftfreq
n = 256
t = np.linspace(0, 1, n, endpoint=False)
sig = np.sin(2 * np.pi * 8 * t)
freq = rfftfreq(n, 1 / n)
amp = np.abs(rfft(sig))
print('peak Hz', freq[np.argmax(amp)])from scipy.fft import rfft, rfftfreq
n = 256
t = np.linspace(0, 1, n, endpoint=False)
rng = np.random.default_rng(0)
sig = np.sin(2 * np.pi * 8 * t) + 0.3 * rng.normal(size=n)
freq = rfftfreq(n, 1 / n)
amp = np.abs(rfft(sig))
plt.plot(freq, amp)
plt.xlabel('Hz')
plt.show()
print(freq[np.argmax(amp)])from scipy.fft import fft, ifft
x = np.array([1.0, 2, 3, 4])
print(np.real(ifft(fft(x))).round(6))from scipy.fft import rfftfreq
print(rfftfreq(8, 0.125))