From Sampled Functions to Coefficients
Suppose a signal has been recorded at a finite list of times, and we want to describe its sampled values using familiar functions such as a constant, a sine, and a cosine. Each function becomes a column: evaluate it at every sample time, then place the results in a vector. If these columns are orthogonal, each coefficient can be found separately with a dot product. The calculation is a finite-data counterpart of the Fourier-series idea that a function can be described through its components along orthogonal sine and cosine functions.
Work over \(\mathbb{R}\). For columns \(\mathbf{u},\mathbf{v}\in\mathbb{R}^m\), their dot product is \(\mathbf{u}^{\top}\mathbf{v}\), and their squared length is \(\|\mathbf{u}\|^2=\mathbf{u}^{\top}\mathbf{u}\). The columns are orthogonal when their dot product is zero. A data vector \(\mathbf{y}\in\mathbb{R}^m\) records one value at each of the \(m\) sample times. A model using columns \(\mathbf{q}_1,\dots,\mathbf{q}_p\) has fitted vector \(c_1\mathbf{q}_1+\cdots+c_p\mathbf{q}_p\), where the real numbers \(c_j\) are its coefficients.
The denominator matters unless the column has squared length \(1\). A column with a larger length can have a larger dot product with the data even when its coefficient is unchanged. Dividing by its squared length corrects for that scaling. In Fourier-series language, a dot product is replaced by a finite sum over sampled times, while the denominator accounts for the sampled function’s length. The exact coefficients depend on which times were sampled and which columns were included; they need not equal coefficients obtained from a continuous function or a different sampling scheme.
A Four-Point Sine-and-Cosine Grid
Take four equally spaced sample times \(t=0,\tfrac14,\tfrac12,\tfrac34\), and evaluate the constant function, \(\cos(2\pi t)\), and \(\sin(2\pi t)\). Their sampled columns are
Direct dot products give \(\mathbf{u}^{\top}\mathbf{c}=0\), \(\mathbf{u}^{\top}\mathbf{s}=0\), and \(\mathbf{c}^{\top}\mathbf{s}=0\). Their squared lengths are \(\mathbf{u}^{\top}\mathbf{u}=4\), \(\mathbf{c}^{\top}\mathbf{c}=2\), and \(\mathbf{s}^{\top}\mathbf{s}=2\). Thus these three columns meet the definition, but they are not all unit length. The constant coefficient is an average over the four entries; the sine and cosine coefficients have denominator \(2\), not \(4\).
Worked Example: Constant, Cosine, and Sine Coefficients
For the data \(\mathbf{y}=\begin{bmatrix}5&2&1&0\end{bmatrix}^{\top}\), compute its coefficients along \(\mathbf{u},\mathbf{c},\mathbf{s}\) and check the residual.
First take the three dot products and divide by the matching squared lengths:
The fitted data are \(2\mathbf{u}+2\mathbf{c}+\mathbf{s}\). Entry by entry, this is \(\begin{bmatrix}2+2+0&2+0+1&2-2+0&2+0-1\end{bmatrix}^{\top}=\begin{bmatrix}4&3&0&1\end{bmatrix}^{\top}\). Subtracting gives the residual \(\mathbf{r}=\mathbf{y}-\widehat{\mathbf{y}}=\begin{bmatrix}1&-1&1&-1\end{bmatrix}^{\top}\).
Check: \(\mathbf{u}^{\top}\mathbf{r}=1-1+1-1=0\), \(\mathbf{c}^{\top}\mathbf{r}=1-1=0\), and \(\mathbf{s}^{\top}\mathbf{r}=-1+1=0\). The residual is orthogonal to every included column, as a projection residual should be.
This calculation makes the Fourier analogy concrete: the constant, cosine, and sine columns each receive a coefficient measuring the data’s component in that direction. The fitted vector uses only those components. Any part of the data perpendicular to all three columns remains in the residual.
Why the Formula Gives the Closest Fit
Proof. Set \(\mathbf{r}=\mathbf{y}-\widehat{\mathbf{y}}\). For each \(k\), expand its dot product with \(\mathbf{q}_k\):
The second equality uses pairwise orthogonality to remove all terms with \(j\ne k\); the last uses the coefficient formula. Now take any other \(\mathbf{z}\) in the span. It has the form \(\mathbf{z}=\sum_{j=1}^{p}d_j\mathbf{q}_j\) for some scalars \(d_j\). Then \(\mathbf{y}-\mathbf{z}=\mathbf{r}+\sum_{j=1}^{p}(c_j-d_j)\mathbf{q}_j\). The residual is orthogonal to each column, so it is orthogonal to their linear combination. Expanding the squared length therefore gives
Each \(\|\mathbf{q}_j\|^2\) is positive because \(\mathbf{q}_j\ne\mathbf{0}\). Equality holds only if every \(c_j-d_j=0\), so the minimizing coefficient list is unique. Thus \(\widehat{\mathbf{y}}\) is the unique closest vector in the span, and its residual is orthogonal to each column. \(\square\)
This proof explains why the coefficient formula is more than a convenient calculation. Orthogonality separates the squared error into a residual part and a nonnegative part measuring how far an alternative coefficient list moves from the formula’s coefficients. No other choice can improve the fit.
Reading the Coefficients and the Projection Matrix
Worked Example: Fitting Only the Sine and Cosine Components
Use the same four sample times, but fit only sine and cosine to \(\mathbf{y}=\begin{bmatrix}3&1&-1&-3\end{bmatrix}^{\top}\). The constant column is deliberately excluded, so the fitted vector must lie in \(\operatorname{span}\{\mathbf{c},\mathbf{s}\}\).
The coefficients are \(c_{\mathbf{c}}=(3+1)/2=2\) and \(c_{\mathbf{s}}=(1+3)/2=2\), since \(\mathbf{c}^{\top}\mathbf{y}=3+1=4\) and \(\mathbf{s}^{\top}\mathbf{y}=1+3=4\). Hence \(\widehat{\mathbf{y}}=2\mathbf{c}+2\mathbf{s}=\begin{bmatrix}2&2&-2&-2\end{bmatrix}^{\top}\). The residual is \(\begin{bmatrix}1&-1&1&-1\end{bmatrix}^{\top}\).
Check: \(\mathbf{c}^{\top}\mathbf{r}=1-1=0\) and \(\mathbf{s}^{\top}\mathbf{r}=-1+1=0\). The fit is exact within the specified two-column model: it uses no constant component. Adding a constant column would change the model space and could change the fitted vector.
For a matrix description, place the orthogonal columns into \(\mathbf{Q}=\begin{bmatrix}\mathbf{q}_1&\cdots&\mathbf{q}_p\end{bmatrix}\), and let \(\mathbf{D}\) be the diagonal matrix whose \(j\)th diagonal entry is \(\mathbf{q}_j^{\top}\mathbf{q}_j\). The coefficient vector is \(\mathbf{D}^{-1}\mathbf{Q}^{\top}\mathbf{y}\), and the fitted vector is \(\mathbf{P}\mathbf{y}\), where \(\mathbf{P}=\mathbf{Q}\mathbf{D}^{-1}\mathbf{Q}^{\top}\). The inverse exists because every diagonal entry of \(\mathbf{D}\) is positive.
Proof. By the coefficient formula, \(\mathbf{P}\mathbf{y}=\mathbf{Q}\mathbf{D}^{-1}\mathbf{Q}^{\top}\mathbf{y}=\sum_j(\mathbf{q}_j^{\top}\mathbf{y})/(\mathbf{q}_j^{\top}\mathbf{q}_j)\,\mathbf{q}_j\). The theorem just proved shows this is the projection. Since \(\mathbf{D}^{-1}\) is diagonal, it is symmetric; thus \(\mathbf{P}^{\top}=\mathbf{Q}\mathbf{D}^{-1}\mathbf{Q}^{\top}=\mathbf{P}\). Orthogonality gives \(\mathbf{Q}^{\top}\mathbf{Q}=\mathbf{D}\), so
Therefore applying \(\mathbf{P}\) twice gives the same result as applying it once. The first application has already placed the vector in the column span, so a second projection does not change it. \(\square\)
Worked Example: Including a Higher-Frequency Sampled Column
On the four-point grid, add the column \(\mathbf{h}=\begin{bmatrix}1&-1&1&-1\end{bmatrix}^{\top}\), the samples of \(\cos(4\pi t)\). It is orthogonal to \(\mathbf{u},\mathbf{c},\mathbf{s}\): the dot products are \(1-1+1-1=0\), \(1-1=0\), and \(-1+1=0\), respectively. Its squared length is \(4\).
For \(\mathbf{y}=\begin{bmatrix}4&0&2&2\end{bmatrix}^{\top}\), the four coefficients are
Thus \(\widehat{\mathbf{y}}=2\mathbf{u}+\mathbf{c}-\mathbf{s}+\mathbf{h}\). Its four entries are \(2+1+0+1=4\), \(2+0-1-1=0\), \(2-1+0+1=2\), and \(2+0+1-1=2\). Therefore \(\widehat{\mathbf{y}}=\mathbf{y}\), with residual \(\mathbf{0}\).
Check: Substitution into the coefficient formula gives the four dot products \(8,2,-2,4\), divided by squared lengths \(4,2,2,4\), respectively. These reproduce \(2,1,-1,1\), and the displayed combination reconstructs every data entry.
Common Pitfall: Forgetting the Column Length
For the first example, the dot product of the constant column with the data is \(\mathbf{u}^{\top}\mathbf{y}=8\). A tempting but incorrect calculation is to call \(8\) the constant coefficient. That would contribute \(8\mathbf{u}\), whose entries are all \(8\); it is not the projection of the data onto the constant column. The correct coefficient is \(8/(\mathbf{u}^{\top}\mathbf{u})=8/4=2\), so the constant component is \(2\mathbf{u}\). The denominator is essential because the sampled constant column has squared length \(4\), not \(1\).
A second caution is that the shortcut requires orthogonal columns. If sampled sine and cosine columns are not orthogonal on the chosen sample times, the separate dot-product formula does not generally give the closest fit. In that case, the columns interact in the coefficient equations, and the orthogonal formula cannot be used as though their cross-products were zero. Check the sampled dot products before applying it. Also check that no included column is zero: its squared length would be zero, making the formula undefined.
Orthogonal sampled columns are useful because they make coefficient interpretation direct: each coefficient records one component of the data, adjusted for the column’s sampled length. The projection viewpoint also makes the residual meaningful: it contains exactly the part perpendicular to the model columns. For periodic data, this gives a finite-sample analogue of Fourier analysis while keeping the computation grounded in vectors, dot products, and the actual observations.
Check Your Understanding
Use the coefficient formula and, where requested, verify the fit by substituting it back into the sampled columns.
- For \(\mathbf{u}=\begin{bmatrix}1&1&1&1\end{bmatrix}^{\top}\) and \(\mathbf{y}=\begin{bmatrix}2&4&0&2\end{bmatrix}^{\top}\), find the coefficient along \(\mathbf{u}\).
- On the four-point grid, compute the coefficient of \(\mathbf{y}=\begin{bmatrix}1&3&-1&-3\end{bmatrix}^{\top}\) along \(\mathbf{s}\).
- Explain why a coefficient along \(\mathbf{c}\) has denominator \(2\), while a coefficient along \(\mathbf{u}\) has denominator \(4\).
- For pairwise orthogonal nonzero columns, why is the coefficient list giving the closest fit unique?
- What must be checked before using separate dot products to compute coefficients from sampled sine and cosine columns?