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

sum of sine 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

Best 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))
Related Question