Sin Cos calculation for a regression
Mostrar comentarios más antiguos
My aim is to best fit sin waves to a dataset. I am using a data set with 501 days of data with a sample rate of 1 day.
After doing a spectral analysis on the data set (using a separate program) the following cycles have been identified:
31.19552 day cycle 5.87064 day cycle 8.00192 day cycle
Previously on this board I received help on how to code a similar task with a cycle of 3.5678 days.:
y = data(:);
X = ones(501,3);
n = 0:500;
X(:,2) = cos(2*pi*0.2794*n)';
X(:,3) = sin(2*pi*0.2794*n)';
betahat = X\y;
Fit is
yhat = betahat(1)+betahat(2)*cos(2*pi*0.2794*n)+betahat(3)*sin(2*pi*0.2794*n);
My question is: how do I calculate what I am supposed to multiply pi with for both the sin and cosine equations used to complete the regression. In the above example a 3.5678 day cycle has .2794 used in the above equations.
I only partially understand this to be because 140/501 creates the most accurate number = .2794. However a simpler calculation of 1/3.5678 or .2803 could be used without any major significance to the outcome.
But what should I do for the 31.19552 day cycle 5.87064 day cycle 8.00192 day cycle?? is there some easy calculation process that I don't know about?
I'm a beginner...any code or insights would be most helpful! MAJOR props to Wayne for his on going help with this!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Nonlinear Regression en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!