Is there any way to do LFIT (general linear least-squares fit ) on the time series data using MATLAB?

조회 수: 3 (최근 30일)
How to do the attched linear least-square fitting equation on time series data in matlab?
y = a + b*t + c*t^2 + d*sin(2*pi*t) + e*cos(2*pi*t) + f*sin(2*pi*t*2) + g*cos(2*pi*t*2)
a,b,c ... are parameters. t is time and y is dependent variable.

답변 (1개)

Star Strider
Star Strider 2021년 7월 27일
That depends entirely on what you want to do.
One approach:
syms a b c d e f g t
y = a + b*t + c*t^2 + d*sin(2*pi*t) + e*cos(2*pi*t) + f*sin(2*pi*t*2) + g*cos(2*pi*t*2);
yfcn = matlabFunction(y, 'Vars',{[a b c d e f g],t})
yfcn = function_handle with value:
@(in1,t)in1(:,1)+in1(:,2).*t+in1(:,5).*cos(t.*pi.*2.0)+in1(:,7).*cos(t.*pi.*4.0)+in1(:,4).*sin(t.*pi.*2.0)+in1(:,6).*sin(t.*pi.*4.0)+in1(:,3).*t.^2
This will work in the Optimization Toolbox and Statictics and Machine Learning Toolbox nonlinear parameter estimation funcitons. Specify the initial parameter estimates as a row vector.
tv = linspace(0, 10, 50); % Create Data
yv = exp(-(tv-5).^2) + randn(size(tv))/10; % Create Data
B0 = rand(1,7); % Choose Appropriate Initial Parameter Estimates
B = nlinfit(tv(:), yv(:), yfcn, B0)
B = 1×7
-0.1691 0.2401 -0.0259 -0.0227 -0.0012 0.0266 -0.0076
The Curve Fitting Toolbox does it differently:
yfit = fittype('a + b*t + c*t^2 + d*sin(2*pi*t) + e*cos(2*pi*t) + f*sin(2*pi*t*2) + g*cos(2*pi*t*2)', 'independent',{'t'});
yfit = fit(tv(:) ,yv(:), yfit,'start',B0)
yfit =
General model: yfit(t) = a + b*t + c*t^2 + d*sin(2*pi*t) + e*cos(2*pi*t) + f*sin(2*pi*t*2) + g*cos(2*pi*t*2) Coefficients (with 95% confidence bounds): a = -0.1691 (-0.4125, 0.07436) b = 0.2401 (0.1275, 0.3526) c = -0.02595 (-0.03684, -0.01506) d = -0.02275 (-0.1431, 0.09761) e = -0.001153 (-0.1193, 0.117) f = 0.02665 (-0.09346, 0.1468) g = -0.007593 (-0.1257, 0.1105)
Experiment to get the result you want.
.
  댓글 수: 6
DIPENDRA007
DIPENDRA007 2021년 7월 28일
@Star Strider residuals (t)=original data(t)- fitted equation data(t). The residuals are filtered to define short term variations and interannual variations that are not determined by the polynomial terms of the equations as well as for smoothing. Can we filter the residual two times using the attached low pass filter equation?
Where fc is chosen such that h(f) = 0.5 at f=fc.
thanks in advance.
Star Strider
Star Strider 2021년 7월 28일
I still do not understand what you want to do.
If you want to filter the data, use the lowpass (or bandpass, to eliminate the baseline offset and drift) functions. I have no idea what you want to do, however
[yr_filt,lpdf] = lowpass(yr, 4E-3, Fs, 'ImpulseResponse','iir');
will work for the lowpass filter, and
[yr_filt,bpdf] = bandpass(yr,[1E-5, 4E-3], Fs, 'ImpulseResponse','iir');
for the bandpass design (although it might be necessary to experiment with the lower passband edge).
.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by