Fseries Example Matlab
Fseries Example Matlab
series approximation
Table of Contents
........................................................................................................................................ 1
The Example ...................................................................................................................... 1
Use of the Traditional FFT function ....................................................................................... 2
This code is used to test the Fseries approximation of a random fft graph. It uses the method of least squares to make
this approximation.
Important Commands
clear all;
close all;
clc;
The Example
Data Generation
x = linspace(0,2,41)';
y = mod(2*x,1);
[a,b,yfit] = Fseries(x,y,10);
Evaluate on finer grid This part of the code just creates smaller intervals so that the fit can be more
accurate
xfine = linspace(0,2)';
yfine = Fseriesval(a,b,xfine);
figure(1);
plot(x,y,'-x',x,yfit,'-k',xfine,yfine,'-m')
grid on;
legend('Initial Data','Initial Fit','Final Fit');
title('Graph Showing Fourier Series Approximation');
1
Simple real Fourier se-
ries approximation
nfft = length(x);
yfft = fft(y,nfft)/nfft;
absy = 2*abs(yfft);
figure(2);
plot(x,absy,'-or');
grid on;
title('Graph Showing traddional FFT approximation');
2
Simple real Fourier se-
ries approximation
figure(3);
plot(x,absy,'-or',xfine,yfine,'-om');
grid on;
legend('Tradditonal FFT','FFT Approximation');
title('Graph Showing both Approximations');
3
Simple real Fourier se-
ries approximation