0

I need to determine the Fourier coefficients that best describe a set of observational data. Now, everything I have read from Wikipedia, Google, and other answers on this site give me many ways of determining the coefficients given a function. However, I don't have a function. All I have are observational data and the time the observation was taken.

What is the proper formulation to use in this case? The only thing I have found that sounds potentially useful is something called a "Discrete Fourier transform," but that seems to give complex values, which is nonsensical for real data. How do I do this?


Edit:

I know precisely what the Fourier coefficients are. They are the $n$ coefficients of the sine and cosine terms that best approximate the function (or data, in this particular case). I learned quite extensively about how to calculate the Fourier series coefficients given a function (integrating them with the function and a sine or cosine term) in my graduate-level Math Methods course (I'm a PhD student in astrophysics). The problem is that that doesn't help when I don't have a function to insert into the integral, so I'm asking how to find them when I don't have a function.

Toby Mak
  • 16,827
mknote
  • 11
  • The function (modeling the data) is real, the discrete Fourier transform is complex. No contradiction. – mjw Aug 06 '20 at 22:32
  • Welcome to MSE. "I need the Fourier coefficients..." seems peculiar, since you don't seem to know what those actually are. I strongly suggest reading enough that you actually understand the Fourier transform before trying to apply it. – John Hughes Aug 06 '20 at 22:41
  • I know precisely what the Fourier coefficients are. They are the n coefficients of the sine and cosine terms that best approximate the function (or data, in this particular case). I learned quite extensively about how to calculate the Fourier series coefficients given a function (integrating them with the function and a sine or cosine term) in my graduate level Math Methods course (I'm a PhD student in astrophysics). The problem is that that doesn't help when I don't have a function to insert into the integral, so I'm asking how to find them when I don't have a function. – mknote Aug 06 '20 at 22:49
  • In fact, though it is different tools, you need the Fourier Transform of your (approx. periodical) data to be able to determine an approximation of the Fourier series ; see for example http://lampx.tugraz.at/~hadley/num/ch3/3.3a.php – Jean Marie Aug 06 '20 at 22:56
  • I should have stated that; apologies. Yes, my data is periodic, a variable star system that repeats itself. – mknote Aug 06 '20 at 22:57
  • Here's an older article I ran across that might be helpful. https://www.ams.org/journals/mcom/1978-32-141/S0025-5718-1978-0468306-4/S0025-5718-1978-0468306-4.pdf . This article is referenced in the Wikipedia page on the subject: https://en.wikipedia.org/wiki/Fast_Fourier_transform – Disintegrating By Parts Aug 11 '20 at 00:58
  • It turns out that this was what I needed, but it wasn't sufficient. Using a fast Fourier transform routine gave me the complex-valued coefficients C, but I needed the real-valued coefficients A and B. I actually had to intuit how to get those as I didn't find an explicit mention, but it turns out that the first A coefficient equals the first C coefficient, and the following A coefficients are equal to half the real-valued portion of the respective C while the B coefficients are half of the imaginary part. I also need to divide all coefficients by the number of data points. – mknote Aug 14 '20 at 23:44

2 Answers2

0

It sounds to me as if you may have data points $\{ (t_i, y_i): i = 1, \ldots, n\}$ and you're trying to estimate coefficients $a,b,c$ for which $y = a + b\cos t + c\sin t$ (or of course you may have $Nt$ rather than $t,$ or a suitable multiple of $t$ depending on the period, and you may want to do this for several values of $N$).

This sort of problem sometimes arises when it is thought that the observed values of $y_i$ are equal to a true value plus a random error whose expected value is $0.$ In that case estimation by least squares is often used. It may also be used in some other cases.

Suppose you have a vector $(u_i : i=1,\ldots, n)$ and other vector $(v_i:i=1,\ldots,n)$ and you want to fit the model $y= a + bu + cv,$ estimating $a,b,c$ by least squares. There are many software packages that do that. Just let $u_i=\cos t_i$ and $v_i = \sin t_i$ and apply the aforementioned software.

0

Put your data in a vector y, and USE Y=fft(y) in MATLAB, you will get the result Y.

If you want Y be real, use Y=dct(y).

  • This didn't precisely solve my issue because I didn't need Y, I needed the coefficients to produce Y. Or rather, I needed the real-valued coefficients A and B to produce the Fourier series. However, these are obtainable from using an FFT routine (I outline how in a reply to my question), so this was an important step to answering my question. – mknote Aug 14 '20 at 23:46
  • Use A=fft(eye(N)); Y=A*y; where N is the length of signal y. – bernarddjb Aug 17 '20 at 02:55