Question
Suppose I take a signal $y(t) = \cos(2\pi \cdot 4.1t + 2)$ and I sample it uniformly up to 2 seconds.
Given only these time samples, how would I design an algorithm that finds the pair of values (freq=4.1 Hz, phase=2 Rad)?
Notes
I do not want the DFT. The DFT assumes the signal is circular at the boundaries and works by using many values in many frequency bins. What I want is to find the best singular phase and frequency that minimise mean squared error between the input data and the reconstructed signal.
For reference, the DFT power spectrum at 400 samples gives this:
My Attempt
I attempted a grid search approach. I choose 1000 phases $\phi$ in $[0, 2\pi)$ and 1000 frequencies $f$ up to the nyquist frequency ($100$ Hz)
Once I had my grid of cos waves, I evaluated the signal at each pair ($\phi$, $f$)
$$y_\text{guess}[n] = \cos(2\pi \cdot f \cdot t[n] + \phi)$$
And calculated the mean square error between the guess and the original signal $$MSE = \frac{\sum_n(y[n] - y_\text{guess}[n])^2}{N}$$ where $N$ is the number of samples.
Running this algorithm, I found the pair with the lowest MSE was ($\phi$ = 2.0357..., $f$=4.0938...) with an MSE of 0.000247.
Those are pretty good values. Problem is, it's really slow. I can't help but feel like there's probably a better, more elegant way to do what I want to do.
I will also mention that while it isn't in the scope of this question, once I have figured this out this algorithm I would like an approach where I try to reconstruct a signal with N sin waves (say, N=5 would find the parameters for 5 sin waves that best minimise error).