Lets say I have a sinusoidal function $s$ that looks like
import numpy as np import matplotlib.pyplot as plt s = lambda t: np.sin(2 * np.pi * t / 13) s_sampled = np.array([p1(i) for i in range(50)]) plt.plot(s_sampled)
Now I want to take the Discrete Fourier transform of the signal and reconstruct the whole original signal. As the signal only has a period of 13. It should be enough to Fourier transform the first 13 points.
fourier_coefficients = np.fft.fft(s_sampled[:13])
However, using the numpy's inverse transform I can only get back 13 points.
How can I get the rest of the (now just repeating) signal back? I have tried to build a function myself, but it does not quite work out...
def inverse_fourier(x, t): """Evaluate Fourier coefficients at point t. Args: x: The Fourier coefficients. t: The time point at which to evaluate the function. """ x = x.flatten() n = len(x) k = np.arange(n) y = x @ np.exp(2j * np.pi * t * k / n) return y / n plt.plot(np.array([inverse_fourier(fourier_coefficients, t) for t in range(50)]))
To give a bit more detail on the problem. I want to take the approximate difference between to signals that vary between different sinusoids over time, but are inherently phase shifted. So my idea was to take the last $k$ timepoints, estimate the Fourier coefficient, take the difference in Fourier space and evaluate the resulting function represented by the coefficients at time point $t$. Therefore, I want to know how I can evaluate the coefficients at $t$. I know the periods of the signals that I am varying between, so can go back enough $k$ points to capture all relevant frequencies.