Curve Fitting Toolbox Fourier Coefficient 9+?
2 views (last 30 days)
Hello, so there isn't a code in particular that I would like to share; however, I'm trying to use the fit function to create a fourier fit. For exploratory purposes I would like to see if there is a way to implement a fourier series with at least 9 coefficients. I don't know if there's any way that I'd be able to do this as the fit function only goes up to 'fourier8'. If I were to create a custom equation it wouldn't work and I don't know if this is because there isn't a normalized mean. Is there any way to normalize the mean and standard deviation so that I may have a higher order fourier series fit?
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.