Regression Fit a SinWave to a dataset?
이전 댓글 표시
Ok..I'm almost there. Yesterday I received some help but still have questions (I'm an ultra beginner).
I love baseball and have a data set with the amount of runs scored by the Pittsburgh Pirates for their last 501 games. The data set is sampled by 1. I completed a spectral analysis on that data set and a 3.5678 game cycle is identified in the data set. I would like to know exactly how to: 1.) generate the sin/cos wave with a period of 3.5678 games 2.) fit the newly created sin/cos wave to the Score data set.
Any code or other insight will be MOST appreciated.
댓글 수: 1
Daniel Shub
2012년 5월 1일
http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
http://www.mathworks.com/matlabcentral/answers/8626-how-do-i-get-help-on-homework-questions-on-matlab-answers
채택된 답변
추가 답변 (2개)
Wayne King
2012년 5월 1일
0 개 추천
Because when you do a spectral analysis, the frequency spacing in your case is 1/501. So you only get frequency estimates at 0, 1/501, 2/501,3/501, 4/501. So I was assuming that your spectral analysis really revealed a peak at the closest Nyquist frequency (a multiple of 1/501).
If you want, you can use 0.2803 which is 1/3.5678 for the frequency. That should not change the results much I would think.
댓글 수: 2
Dr. Seis
2012년 5월 1일
He gave you the hint... it is a multiple of 1/501
140/501 = 0.2794...
He chose this because ABS(140/501 - 1/3.5678) < ABS(141/501 - 1/3.5678), which means 140/501 is closer to the frequency you are after.
Clifford Shelton
2012년 5월 1일
Wayne King
2012년 5월 1일
You are not using what I gave you. You are using
%betahat = X/y;
Look at the example I gave you:
y = score(:); %make sure score is a column vector
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;
It's very important which slash you use.
카테고리
도움말 센터 및 File Exchange에서 Number games에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!