How can I define the period before fitting a Fourier series to discrete data using MATLAB?

Sam Brockie

I'm using MATLAB's fit function:

fourier_series=(x,y,'fourier8');

to fit an 8th order Fourier series to a set of discrete data (x,y). I need the period of the Fourier series to be 2*pi. However I can't work out how to fix this so that when I call the function it fits the series to my required period. Any suggestions would be greatly appreciated. Thanks.

Background to problem: I am analysing video capture data of cyclist's pedalling which outputs as a cloud of joint positions in 3D space over time. The joint positions change slightly every pedal stroke. I am therefore wishing to fit Fourier series' to these joint positions and joint angles as a function of crank arm angle to find the cyclist's "average" position. The period of the Fourier series' therefore need to be constrained to be 2*pi as the "average" positions must return to the same location when the crank arm angle is zero (i.e. top dead centre, TDC) and the crank arm angle is 2*pi (i.e. TDC after one crank arm rotation).

Currently MATLAB is selecting the period to be slightly greater than 2*pi which means that when I use the Fourier series' to calculate the cyclist's position, the cyclist's position changes for the same crank arm angle on consecutive pedal strokes.

Jommy

The best way to force the fit function on a certain period is to resort to a custom equation model, via fittype. Another option (that will throw a warning) is to fix the lower and upper bounds of the parameter w to the same value, and select as solution method LinearLeastSquares.

A cleaner solution is obtained by observing that, since you already know the period the fitting problem is linear in the parameters, and so you can resort to the linear least-squares method. I'll show hereafter an example of this approach.

%// Build a simple time series with period 2*pi.
t = (0:0.01:4*2*pi)';
y = sawtooth(t);
T = 2*pi;

%// Compute the angular speed and the azimuth.
Omega = 2*pi/T;
alpha = Omega*t;

%// Build the regressor matrix, with n harmonics.
n = 8;
A = ones(length(t), 2*n+1);
for i = 1:n
    A(:,[2*i 2*i+1]) = [cos(i*alpha) sin(i*alpha)];
end

%// Solve the linear system.
%// The parameters are sorted as:
%// p = [y0 a1 b1 a2 b2 ...]'
%// being y0 the average of y, a_i the terms multiplying the sines
%// and b_i the terms multiplying the cosines.
p = A\y;

%// Evaluate the Fourier series.
yApprox = A*p;

%// Compare the solution with the data.
figure();
hold on;
plot(t, y, 'b');
plot(t, yApprox, 'r');

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I define this lazy (infinite?) data structure in F#

From Dev

how can i perform 3d Fourier Transform......?

From Dev

How can I generate big data sample for Postgresql using generate_series and random?

From Dev

Fourier series - Plot in Matlab

From Dev

How can I edit form data before setting a model property using Ember and ember-data?

From Dev

How to compute Discrete Fourier Transform?

From Dev

fftshift before calculating fourier transform: Matlab

From Dev

how to define a 2d discrete delta function that can take array input in matlab

From Dev

How to fit the exponential function using Matlab curve fitting tool?

From Dev

2D Discrete Fourier Transform implementation in MATLAB

From Dev

Issues Translating Custom Discrete Fourier Transform from MATLAB to Python

From Dev

Create scipy curve fitting definitions for fourier series dynamically

From Dev

How can I Fourier phase scramble a grayscale JPEG image in Matlab?

From Dev

How can I create a discrete colorbar using a colormap from mpl_toolkits.basemap.cm?

From Dev

How can I reshape my data before I turn it into a histogram?

From Dev

How can I wait until Asynchronous callbacks are finished before using the data retrieved?

From Dev

How can I define index on inherited fields in MongoDB with Spring Data?

From Dev

How can I add a vertical abline for a graf using ggplot with time series data?

From Dev

How can I skip data/labels in a period of time in Chartjs?

From Dev

How can I define a new data type that is a list of numbers?

From Dev

Why i cannot getting correct Fourier transformed image using matlab?

From Dev

How can I define a widget using javascript

From Dev

2D Discrete Fourier Transform implementation in MATLAB

From Dev

How to perform convolution using Fourier Series

From Dev

How Can i Validate datatable's Data before inserting it using SqlBulkCopy

From Dev

MATLAB: How can I create autocorrelated data?

From Dev

Matlab: How to plot this fourier series, where each index is odd

From Dev

How to define a custom directory so that I can cd directory in Matlab

From Dev

Matlab/Octave 2D Discrete Fourier Transform

Related Related

  1. 1

    How can I define this lazy (infinite?) data structure in F#

  2. 2

    how can i perform 3d Fourier Transform......?

  3. 3

    How can I generate big data sample for Postgresql using generate_series and random?

  4. 4

    Fourier series - Plot in Matlab

  5. 5

    How can I edit form data before setting a model property using Ember and ember-data?

  6. 6

    How to compute Discrete Fourier Transform?

  7. 7

    fftshift before calculating fourier transform: Matlab

  8. 8

    how to define a 2d discrete delta function that can take array input in matlab

  9. 9

    How to fit the exponential function using Matlab curve fitting tool?

  10. 10

    2D Discrete Fourier Transform implementation in MATLAB

  11. 11

    Issues Translating Custom Discrete Fourier Transform from MATLAB to Python

  12. 12

    Create scipy curve fitting definitions for fourier series dynamically

  13. 13

    How can I Fourier phase scramble a grayscale JPEG image in Matlab?

  14. 14

    How can I create a discrete colorbar using a colormap from mpl_toolkits.basemap.cm?

  15. 15

    How can I reshape my data before I turn it into a histogram?

  16. 16

    How can I wait until Asynchronous callbacks are finished before using the data retrieved?

  17. 17

    How can I define index on inherited fields in MongoDB with Spring Data?

  18. 18

    How can I add a vertical abline for a graf using ggplot with time series data?

  19. 19

    How can I skip data/labels in a period of time in Chartjs?

  20. 20

    How can I define a new data type that is a list of numbers?

  21. 21

    Why i cannot getting correct Fourier transformed image using matlab?

  22. 22

    How can I define a widget using javascript

  23. 23

    2D Discrete Fourier Transform implementation in MATLAB

  24. 24

    How to perform convolution using Fourier Series

  25. 25

    How Can i Validate datatable's Data before inserting it using SqlBulkCopy

  26. 26

    MATLAB: How can I create autocorrelated data?

  27. 27

    Matlab: How to plot this fourier series, where each index is odd

  28. 28

    How to define a custom directory so that I can cd directory in Matlab

  29. 29

    Matlab/Octave 2D Discrete Fourier Transform

HotTag

Archive