Simple real Fourier series approximation
Includes two functions: Fseries.m and Fseriesval.m
[a,b] = Fseries(X,Y,n) fits an nth-order Fourier expansion of the form
y = a_0/2 + Sum_k[ a_k cos(kx) + b_k sin(kx) ]
to the data in the vectors X & Y, using a least-squares fit.
Y = Fseriesval(a,b,X) evaluates the Fourier series defined by the coefficients a and b at the values in the vector X.
Extra arguments allow for rescaling of X data and sin-only or cosine-only expansions.
Example:
% Generate data
x = linspace(0,2,41)';
y = mod(2*x,1);
% Use FSERIES to fit
[a,b,yfit] = Fseries(x,y,10);
% Evaluate on finer grid
xfine = linspace(0,2)';
yfine = Fseriesval(a,b,xfine);
% Visualize results
plot(x,y,'x',x,yfit,'o',xfine,yfine)
This generates the attached image of a 10-term Fourier series approximation of a sawtooth wave.
Cite As
Matt Tearle (2024). Simple real Fourier series approximation (https://www.mathworks.com/matlabcentral/fileexchange/31013-simple-real-fourier-series-approximation), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- AI and Statistics > Statistics and Machine Learning Toolbox > Industrial Statistics >
- Sciences > Mathematics > Analysis > Fourier Series >
Tags
Acknowledgements
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.1 | Made a quick hack to the input-parsing utility to deal with the change in precedence rules. It should now work in 19b and in previous versions. Hasn't been really thoroughly tested, though, so please report any problems. |
||
1.0.0.1 | Updated license |
||
1.0.0.0 |