# How to determine the sine Fourier coefficients of discrete data?

The following relation gives me the measurements of interest $$w$$ at equally distanced locations $$x_j$$ in space:

$$w_j=\sum_{m=1}^{11}A_m\sin\left(\frac{mπx_j}{L}\right)$$

where $$A_m$$ are the Fourier coefficients of sine series and $$L$$ the total length is physical space. I also assume $$m = 1,2,...,11$$.

Now, how can I obtain the coefficients $$A_m$$ given the data $$w_j$$ ?

• i think this question is better suited for signal proc. SE.
– gunes
Aug 31, 2020 at 11:34
• You equation doesn't make sense to me. Did you mean something more like this? $$w_j=\sum_{m=1}^{L}A_m\sin\frac{mπx_j}{L}$$ Also, are your $x_j$ locations uniformly spaced? Sep 1, 2020 at 0:36
• You are right. I edited my question. Thank you. Sep 2, 2020 at 9:00

With the correction, it can now be answered.

I will assume that you have also have 11 readings. Fewer and you are underdetermined, with more you are overdetermined.

Express your problem in matrix form.

$$\begin{bmatrix} w_1 \\ w_2 \\ w_3 \\ : \\ w_{11} \\ \end{bmatrix} = \begin{bmatrix} \sin\left(\frac{ \pi x_1}{L}\right) & \sin\left(\frac{2 \pi x_1}{L}\right) & \sin\left(\frac{3 \pi x_1}{L}\right) & \dots & \sin\left(\frac{11 \pi x_1}{L}\right) \\ \sin\left(\frac{ \pi x_2}{L}\right) & \sin\left(\frac{2 \pi x_2}{L}\right) & \sin\left(\frac{3 \pi x_2}{L}\right) & \dots & \sin\left(\frac{11 \pi x_2}{L}\right) \\ \sin\left(\frac{ \pi x_3}{L}\right) & \sin\left(\frac{2 \pi x_3}{L}\right) & \sin\left(\frac{3 \pi x_3}{L}\right) & \dots & \sin\left(\frac{11 \pi x_3}{L}\right) \\ : & : & : & ::: & : \\ \sin\left(\frac{ \pi x_{11}}{L}\right) & \sin\left(\frac{2 \pi x_{11}}{L}\right) & \sin\left(\frac{3 \pi x_{11}}{L}\right) & \dots & \sin\left(\frac{11 \pi x_{11}}{L}\right) \\ \end{bmatrix} \begin{bmatrix} A_1 \\ A_2 \\ A_3 \\ : \\ A_{11} \\ \end{bmatrix}$$

This can be seen as:

$$W = S A$$

The solution is:

$$A = S^{-1} W$$

This is very similar to my two answers here:

Reconstructing a sine wave from an interval shorter than half its wavelength

In the overdetermined case:

$$W = S A$$

$$S^T W = S^T S A$$

$$A = (S^T S)^{-1} S^T W$$

This is done inside np.linalg.solve, so you just need to use that (or your platform equivalent).

• This looks nice. But what if I have more than 11 readings as my case? In that case matrix manipulations are not applicable.. Sep 2, 2020 at 14:15
• @DimitrisGeorgiadis If you have more readings, you are overdetermined. In this case you will get a best fit solution. See followup. Sep 2, 2020 at 14:25
• I get the determinant of S equal to zero. Any solutions? Sep 3, 2020 at 7:40
• @DimitrisGeorgiadis Or if the determininant of $(S^TS)^{-1}$ is zero, you are underdetermined. You can get a solution but it won't be unique. It is probably better to reduce your model size from 11. Since $S$ is based on the $x_j$ values, and not your $w_J$ values, it means you don't have enough distinct domain points. Sep 3, 2020 at 11:55

In accordance with the case of a continuous function $$f(x)$$ where $$b_n=\frac{2}{L}\int_{0}^Lf(x)\sin\left(\frac{mπx}{L}\right)dx$$ I came with the following expression: $$A_m=\frac{1}{N-1}\sum_{n=1}^{N}w_n\sin\left(\frac{mπx_n}{L}\right)$$

Can anyone confirm or not that solution?