-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfitting_my_function.m
More file actions
34 lines (24 loc) · 1.19 KB
/
Copy pathfitting_my_function.m
File metadata and controls
34 lines (24 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function out = fitting_my_function(params,data)
% scale x so that it goes from zero to one and from the tip of the tail
% from the center of the fish
% t = 2*pi*(x - xmin) / (xmax - xmin)
% scale y so that it is centered around zero and normalized in the same way
% as x with the (half) length of the fish
% q = 2*(y - ymean) / (ymax - ymin)
% Then fit the following function to the fish line
% q = cos({({omega t^{gamma}+phi})})*exp({-beta t})
% y=cos({({5x^{0.9}+1})})|_cdot_exp({-1.5x})
% x and y (t and q) are known
% find omega, gamma, beta and phi. phi is the only parameter which
% eventually changes once the others are known.
t = pi*(data(:,1) - min(data(:,1))) / (max(data(:,1)) - min(data(:,1))); % I multiply by pi and not 2*pi because x goes from the tip of the tail to the centre of the fish
q = (data(:,2) - mean(data(:,2))) / (max(data(:,1)) - min(data(:,1))); % amplitude normalized by fish length
phi = params(1);
omega = params(2);
A = params(3);
gamma = params(4);
beta = params(5);
% functionOft = A*cos(omega*t.^gamma + phi).*exp(-beta*t);
functionOft = A*cos(omega*t.^gamma + phi).*exp(-beta*t);
% minimum squared distance between observed and predicted
out = sum((q - functionOft).^2);