Fit a repeated pattern
10 次查看(过去 30 天)
显示 更早的评论
I have the following time series that i want to model.
The graph shows several 'events' that have a repeated pattern (i consider as an 'event' the data points between the long straight lines). I can fit each event (the parts between the straight lines) separately with a 3rd or 4th level polynomial but what i want is to create a continuous model to fit several plots like this one automatically.All events should have the same shape (the reason why they do not look exactly the same is because of some noise is added). Does anyone know how to create a model for this whole plot if i know the shape of one of those events? I have included the dataset in text files.
0 个评论
采纳的回答
Star Strider
2018-6-27
Getting the ensembles (data between the vertical lines) takes a bit of experimentation. It is then possible to put those data into a matrix of ensembles. Those data are then your to work with.
The Code —
x = load('x.txt');
y = load('y.txt');
[pks,locs] = findpeaks(-y, 'MinPeakHeight',-20, 'MinPeakDistance',100); % Find Indices Of Vertical Lines
figure(1)
plot(x, y)
hold on
plot(x(locs), -pks, 'vr')
hold off
ensblen = min(diff(locs))-20; % Length Of Each Vector, Eliminating Vertical Lines At Both Ends
ensbmtx = zeros(ensblen, numel(locs)-1); % Preallocate
for k1 = 1:size(ensbmtx,2)
ensbmtx(:,k1) = y(locs(k1)+[0:size(ensbmtx,1)-1]+15); % Create Ensemble
end
figure
ribbon((1:size(ensbmtx,1)), ensbmtx, 0.2, 'EdgeColor','w') % View Results (Optional)
grid on
The ‘ensbmtx’ (‘ensemble matrix’) result is (1886x10). Each vector is a column.
2 个评论
Star Strider
2018-6-27
My pleasure.
It depends on how you want to fit them, and the polynomial you want to use. If you want to fit the mean of your data, this works:
indep = (0:size(ensbmtx,1)-1)'*x(1);
meanensb = mean(ensbmtx,2);
p = polyfit(indep, meanensb, 4);
f = polyval(p, indep);
figure
plot(indep, mean(ensbmtx,2), '.b')
hold on
plot(indep, f, '-r')
hold off
grid
A polynomial fit is likely not going to be meaningful if you actually want information from your data. A much better approach would be to use a mathematical model of the process that created your data, and then use it as your objective function in a nonlinear parameter estimation function (such as lsqcurvefit) to do the fit.
更多回答(1 个)
Michiele Ogbagabir
2018-6-27
If you know the shape of one of those events, you may try implementing an iterative solution by wrapping around the x-interval of one such event. Lets say one such pattern spans an x-interval (0, 200). In this case you can modify your single-event-polynomial by passing it x % 200 instead of x and turn it into a model for this whole plot. But this would require prior knowledge of the pattern's intervals which may not be possible depending on what your application is.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!