# Curve Fitting Toolbox Fourier Coefficient 9+?

2 views (last 30 days)

Show older comments

##### 0 Comments

### Answers (1)

William Rose
on 30 Jun 2022

@Isaias Trevino, The Fourier decomposition of a signal is orthogonal. That means that the best fit coefficients at the different frequencies are independent. That means that if you find the best fit for the first 9 coefficients, and then try again with 10 or 20 coefficients, your answer for the first 9 will not be affected, because the fit is independent at the different harmonics. This is not true if you fit a poynomial, because the value you get for the slope term of a straight line will usually change if you then add a squared term to your fitting function. So if you want to fit with nine Fourier terms, you can just compute Y=fft(x), and then ignore all terms above the ninth harmonic.

If you want to reconstruct the fitted signal with only the first 9 frequencies, then set the values in Y (the FFT array) to zero at the higher frequencies, and then do the inverse FFT. If you do this, make sure to keep the elements that correspond to the "negative" first 9 frequencies, and zero out the higher negative frequencies. If you don't do this, the result of the inverse FFT will almost certainly be complex, and will not be what you want.

I hope that helps. Good luck.

##### 2 Comments

William Rose
on 13 Jul 2022

Regarding your formula:

I assume that x is the independent variable, which you have measured, and that w is frequency. Your formula suggests that frequency of each component is the same, since you do not have a subscript "i" on the w's. I assume that is an oversight, and that you intend for the frequency to be a multiple of i, since that is Fourier's formula. In other words, we should replace ω with , where , where is the fundamental frequency, in radians per unit of x. You have to decide, based on your knowledge of your data, what value to use for . If you have a signal that you recorded for duration T, then it is common to choose , so that one cycle of the fundamenal frequency is exactly as long as the signal you recorded.

Notice that a0 and c0 in the formula are redundant: they are both constants. Therefore you would get the exact same fit with a0=1,c0=0; and with a0=0,c0=1; and with a0=-100,c0=101; and so on. If you do not eliminate one of these terms, you will not be able to find a unique best fit, because there are an infinite number of combinations of a0 and c0 that give the exact same fit. Therefore you must eliminate one of them from the fitting function. Let's eliminate c0.

The same comment as above also applies to ai versus cj, and to bi versus dj. Notice that is identical to , expect for the label on the constant, a_i versus c_j. Therefore you must eliminate ai or cj, and you must eliminate bi or dj. Let's eliminate cj and dj.

Therore, the formula which I think you should use, to get a unique fit, is

I have used index k instead of i, to avoid confusion with .

How does this sound to you? I want to know your opinion, before moving to the next step, which is finding the a's and b's. Perhaps you would be willing to share some example data.

### See Also

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!