Sum of sines fitting algorithm: What is happening to the phase value?

I am trying to figure out what is happening with the sine fit function in matlab. To do this I have input a sine function with known parameters, then use the sine fitting function in the curve fitting toolbox to reproduce my results. The fit values for the amplitude and frequency make sense, but I cant make sense of the phase value.
Here is an example:
time=[2007.1
2007.2
2007.3
2007.4
2007.6
2007.7
2007.8
2008.0
2008.1
2008.3]; %Time in decimal years
A=10; % meters
f=2*pi; %wavelength of 1 year
phi=0; %no phase shift
y=A*sin(f*time+phi)
The sine fitting function spits out this:
A=10
f=2*pi
phi= -2601
What is the meaning of -2601 radians? I entered phi = 0 , so why is this not zero?
Thanks,
Al

 Accepted Answer

Hi, the basic least-squares estimates work fine here:
time=[2007.1
2007.2
2007.3
2007.4
2007.6
2007.7
2007.8
2008.0
2008.1
2008.3]; %Time in decimal years
A=10; % meters
f=2*pi; %wavelength of 1 year
phi=0; %no phase shift
y=A*sin(f*time+phi);
X = ones(10,3);
X(:,2) = cos(f*time)';
X(:,3) = sin(f*time)';
beta = X\y;
Ampest = sqrt(beta(2)^2+beta(3)^2)
phiest = atan2(beta(2),beta(3))
phi=pi/4; %no phase shift
y=A*sin(f*time+phi);
beta = X\y;
Ampest = sqrt(beta(2)^2+beta(3)^2)
phiest = atan2(beta(2),beta(3))

More Answers (1)

Your function is periodic so there is an infinite phase shifts, that will be a good answer.
You could add a constraints in fit options.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!