Fourier Fit
Version 1.0.1 (1,84 KB) von
D.Dozor
Fits a scalar, truncated Fourier Series of user selected order (aka harmonics) to a data sequence and returns a parameter vector and RSE.
[q,RSE]=FourierFit(x,y,n) outputs a parameter vector of length 2n+1 and the square root of the sum of the squared error given two column vectors of equal length, where x is in radians and y is in user selected units.
Unlike fft(), this is a functional approximation using a least squared method (rather than Cooley-Tookey, which provides parameters for n =k/2 (Nyquist), where k is the number of samples (or number of elements in the sequence).
One benefit is that the calculation can be done for ANY n, where n is the order of the (truncated) Fourier Series (and the number of parameters is 2n+1). Another benefit is that the definition and construction of the "t-vector" can be reindexed to limit the specific "harmonics" (for example, rather than all up to n, only the "odds" or "evens" or some other indexable relationship.) Another is that n can be varied to provide a fit that is "adequate" based on some criteria, like RSE (root sum of squared error).
Originally scripted/coded in 2002 for use in precision optomechanical systems (Laser Radar and Space-borne instruments) for uses including calibrating and compensating for "bearing wobble", "encoder cycle error", and similar, the simple algorithm has been recently optimized to allow the user to choose the order n of the Fourier Series.
This allows the function to be called, for example, inside of a loop, where n can be incremented to achieve some metric, such as the returned RSE (root of the sum of squared error).
The code is simple and lean exploiting key mathematical properties and by using Matlab's vector, array, and matrix functions. Have a look and connect directly if you'd like the more descriptive and detailed write up (2 pages).
Zitieren als
Dozor, David (2025). Fourier Fit (https://www.mathworks.com/matlabcentral/fileexchange/<...>), MATLAB Central File Exchange. Retrieved September 21, 2025.
Kompatibilität der MATLAB-Version
Erstellt mit
R2024b
Kompatibel mit allen Versionen
Plattform-Kompatibilität
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Live Editor erkunden
Erstellen Sie Skripte mit Code, Ausgabe und formatiertem Text in einem einzigen ausführbaren Dokument.
| Version | Veröffentlicht | Versionshinweise | |
|---|---|---|---|
| 1.0.1 | added paragraphs 2 and 3 to help understand the benefits of the algorithm. |
||
| 1.0.0 |
