Solved – Possible to do Fourier decomposition using Linear Regression

fourier transformregression

I was wondering whether it's possible to do Fourier decomposition using linear regression.

Let me explain this.

Given the samples $(x_1 y_1), \dots, (x_n, y_n)$ with $x_i, y_i \in \mathbb R$, we can maximize the likelihood
$$
\begin{pmatrix}
y_1 \\ \vdots \\ y_n
\end{pmatrix}
\sim \mathcal N\left(Xw, I\sigma^2\right)
$$
of $y_1, \dots, y_n$ w.r.t. the vector $w$, where
$$
X = \begin{pmatrix}
\varphi\left(x_1\right) \\ \vdots \\ \varphi\left(x_n\right)
\end{pmatrix}
$$
and $\varphi : \mathbb R \to \mathbb R^m$ is a non-linear transformation, by choosing
$$
w = \left(X^\mathsf{T} X\right)^{-1} X^\mathsf{T} y
\text.
$$

Clearly, the vector $w$ weights the contribution of the features $\varphi_1, \dots, \varphi_m$ to the linear model.

Now, assume that all $x_i \in \left[0; 1\right]$ and that we choose
$$
\varphi_i\left(x\right) = \cos\left( \frac{2\pi}{i} x + \beta_i \right)
\text.
$$
I believe, that if we knew the correct phase $\beta_i$ of the frequency $2\pi/i$ in the Fourier spectrum $\hat x$ of $x$ on $\left[0; 1\right]$, then $w$ would recover the magnitudes of the frequencies $2\pi/1, \dots, 2\pi/m$ in $\hat x$, wouldn't it? If yes, is there any chance to estimate $\beta_i$? Of course, without actually computing $\hat x$.

Best Answer

You can do that (estimate the magnitudes via regression), but you can actually estimate the magnitudes and the phases using regression, so it will still work when the phases are unknown, and it will work in the presence of noise in $y$ (in the sense at least that you can still estimate those coefficients, though themselves with some noise).

Specifically, rather than just fitting $\cos$ terms, if you fit both $\sin$ and $\cos$ terms, you can obtain both magnitude and phase.

Using trigonometric terms in this way is discussed here, which discusses fitting several harmonics of the period, as well as estimation of both phase and amplitude.

If frequency is also unknown you have a nonlinear problem and in that case you would use other approaches (such as nonlinear regression discussed in another answer to the first question linked here).

Related Question