I have a signal that looks like this
It has regularly occurring peaks 50 units apart, and offset from 0 by approximately 20. I thought I could apply the DTFT to this signal and extract the period (expected value 50) and the phase offset (expected value 20). So in graphical terms, I thought I could find the sinusoid in orange, which is created with the following code:
period = 50 offset = 20 x = np.arange(len(sig)) freq = 1/period * 2 * np.pi y = 40000 * np.sin(x*freq-offset)
So I apply the FFT using scipy as follows:
from scipy.fft import fft, fftfreq yf = fft(sig) xf = fftfreq(len(sig))
I then plot it with the expectation that the frequency with the maximum magnitude value would be close to the one I found by eyeballing. But that is not the case, and there are several frequency values which have higher magnitudes than the one I was expecting (.125).
fig = plt.figure(figsize=(14, 5)) fig.suptitle("FFT") ax = fig.add_subplot() ax.plot(xf[s], np.abs(yf[s])) ax.vlines(freq, 0, 1, transform=ax.get_xaxis_transform(), colors='r', label="expected max freq value") ax.legend();
Can I use the FFT on this signal to find both the phase offset (20), and the period (50)? From the graph it seems obvious that the signal is dominated by that one sinusoid, but perhaps my intuition is off because this is like a rectified signal.
The full jupyter notebook is available here