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.
0 个评论
回答(1 个)
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})
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)
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)
Experiment to get the result you want.
.
6 个评论
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 Center 和 File Exchange 中查找有关 Descriptive Statistics 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!