0% found this document useful (0 votes)
146 views4 pages

Fseries Example Matlab

Fourier Series Example

Uploaded by

AJR365
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
146 views4 pages

Fseries Example Matlab

Fourier Series Example

Uploaded by

AJR365
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Simple real Fourier

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);

Use of the Function to fit

[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);

Plot of results from the approximation's example

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

Use of the Traditional FFT function


We will be using the same data generated above so as to make an accurate comparison

nfft = length(x);
yfft = fft(y,nfft)/nfft;
absy = 2*abs(yfft);

Plot of tradditional FFT

figure(2);
plot(x,absy,'-or');
grid on;
title('Graph Showing traddional FFT approximation');

2
Simple real Fourier se-
ries approximation

Plot of both graphs on same figure

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

Published with MATLAB® R2016a

You might also like