Signal decomposition: getting phase with known amplitude and frequency of main components Suppose you have sampled a signal and you know amplitude $ \alpha_i $ and frequency $ f_i $ of the main components for the decomposition:

$$
y(t) = \sum_{i=0}^N{\alpha_i\cos(2\pi f_i t + \phi_i)}
$$

Which methods would be the fastest and the most accurate to calculate the phase vector $ \phi_i $?

Boundaries:


Signal sample has constant sampling rate
Signal sample length is not guaranteed to be an integer multiple of the signal period, but is longer than one period


EDIT

The simples way I can think of is to minimise the RMS error with some optimisation algorithm as shown in code below. I’m wondering if there is a more efficient and simpler way to achieve the same.

%matplotlib inline

import matplotlib.pyplot as plt
import numpy as np
import scipy.optimize as op

# Build a signal as sum of cosines
def f_signal(t, magnitude=[], frequency=[], phase=[]):
    y = 0
    for m, f, p in zip(magnitude, frequency, phase):
        y += m*np.cos(2*np.pi*f*t+p/180.*np.pi)
    return y

# Length [s] and number of samples of the signal
t_length, N = 0.09, 1000

# Equally spaced time axis
t = np.linspace(0, t_length, N)

# This is the reference signal (we know all information)
y = f_signal(t, [8, 4], [80, 240], [-90, 40])

# Now suppose we lost the phase information and want to reconstruct it

# Lets use the root mean squared error as function to be minimised
def f_rms_error(phase):
    return np.sqrt(np.sum((y - f_signal(t, [8, 4], [80, 240], phase))**2)/len(t))

# Initial guess
phase0 = [0, 0]

# Minimize RMS error with fmin
phase1 = op.fmin(f_rms_error, phase0)

# Print result
print(phase1)

# Reconstruct signal
y_r = f(t, phase=phase1)

# Plot results
plt.figure(1, figsize=[15, 5])
plt.subplot(1,1,1)
plt.plot(t,y)
plt.plot(t,y_r, 'r-‘)
Trying to estimate the phase directly from the following equation requires nonlinear optimization.
$$
y(t) = \sum_{i=0}^N{\alpha_i\cos(2\pi f_i t + \phi_i)}
$$
Since the amplitudes and frequencies are known you can transform your problem to
$$
y(t) = \sum_{i=0}^N{\cos(\phi_i) \alpha_i \cos(2\pi f_i t)} - \sum_{i=0}^N{ \sin(\phi_i) \alpha_i  \sin(2\pi f_i t)}
$$
If you have $M$ samples for $t=t_0,... t_{M-1}$ and define
 $$p_i=\alpha_i \cos(\phi_i)$$ $$q_i=- \alpha_i \sin(\phi_i)$$ as your new parameters. Then you have a classic least square problem with $2N$ parameters.
$$\bf{Y} = A X + \text{noise} $$
where
$${\bf{Y}}=[y(t_0),....,y(t_{M-1})]^T$$

$A$ is a $M\times (2N)$ matrix where 
$$A(j,i)=\alpha_i \cos(2\pi f_i t_{j}) ~~~\text{for}~~~ i=0,..,N-1$$
$$A(j,i)=\alpha_i \sin(2\pi f_i t_{j}) ~~~\text{for}~~~ i=N,..,2N-1$$
and
$${\bf{X}}=[p_0,....,p_{N-1}, q_0,....,q_{N-1}]^T$$
The unknown vector $X$ (and thus all $p_i$ and $q_i$) can be estimated by normal equation (see for https://en.wikipedia.org/wiki/Linear_least_squares_(mathematics)):

$$X=(A^{T}A)^{-1}A^{T}Y$$

After estimating $p_i$ and $q_i$ you can estimate $\phi_i$, with an ambiguity of $\pm 2\pi k$ by taking 4 quadrant inverse $\tan$:
$$\phi_i=\text{atan2}(-q_i,p_i)$$

Also the amplitude $a_i$ can be estimated:
$$a_i =\sqrt{p^2_i+q^2_i}$$