1

I have been tasked to write a program in matlab which will approximate a function $f(t)$ as a sum of sines and cosines given that it is defined in the domain $0 - 2\pi$. I have a set of points that $f(t)$ evaluates to for 12 points within this domain. I've been given the equation

$$ f(t) \approx \frac{a_0}2 + \sum_{k=1}^n(a_k\cos(kt) + b_k\sin(kt), (0 \le t \le 2\pi), n\in \Bbb N $$

where the Fourier coefficients are

$$ a_k = \frac1\pi \int_0^{2\pi} f(t) \cos(kt)dt, k = 0,1,2,3..., $$ $$ b_k = \frac1\pi \int_0^{2\pi} f(t) \sin(kt)dt, k = 0,1,2,3..., $$

and been asked to evaluate the first 4 coefficients for $a_k$ and $b_k$ for $k = 0,1,2,3$. I initially thought that the second $t$ was the variable we were integrating, but ( for the first coefficient at least ) this evaluates to $0$ for all values of $k$. So, for each $k$ should I take the corresponding value of $t$ and $f(t)$ and substitute into the equations giving the Fourier coefficients? Say the second value of my $t$ points is $\frac\pi6$ and $f\left(\frac\pi6\right) = 1.52$, do I simply substitute these into the coefficient equations?

Thanks for any help, and if anyone could point me in the direction of some material that would help me understand better what I'm doing, that'd be great too.

Davide Giraudo
  • 172,925

1 Answers1

2

As I admitted frankly in the comments, I don't know how to use the formulas you were given to solve this problem. (How can you evaluate those integrals if you only know $f$ at a dozen points?)

However, if the bottom line is to approximate $f(t)$ on $[0,2\pi)$ by a sum of sines and cosines based on a sample of data, that can be done. Probably in more sophisticated, easier ways than I'm about to describe. But here is one way.

Let your time-sampled data be the 12 points $(t_1, f_1),\dots,(t_{12},f_{12})$. You want to approximate these data by a function of the form $F(t) = a_0/2 + a_1\cos t + \dots + b_3\sin 3t$. So construct the objective function $$\phi(a_0, a_1, a_2, a_3, b_1, b_2, b_3) = \sum_{i=1}^{12}\left(F(t_i) - f_i\right)^2\,.$$

Find the values of the $a$'s and $b$'s that minimize the objective function.

Jason Zimba
  • 2,585
  • I don't fully understand your method, but I've since talked to my tutor who explained the functions to me. It turns out I was supposed to calculate the integral of the curve defined for the points I was given for each value of k, where k is the number of a's and b's. I found the notation quite confusing! – PointToPoint Mar 19 '14 at 14:55
  • 1
    Ok - thanks for getting back to me! Basically the above approach is a nonlinear least squares fit. – Jason Zimba Mar 19 '14 at 16:24
  • The form of the function is incorrect. The functions you put in to sum for F(t) is not linearly independent. – TeeJ Lockwood Aug 09 '17 at 21:04
  • 1
    @TeeJLockwood Thanks, I think there was a typo. I think it is fixed. – Jason Zimba Aug 11 '17 at 00:19