What resample method can I use for time series that increases nonlinearly?

조회 수: 36 (최근 30일)
I have a time series of data (that I have in a structure) that goes from 0 to 360 (degrees), which only increases from one sample in the time series to the next (i.e., always something like: 0, 1, 2, 3, 4 ... 360, never 0, 1, 2, 1, 2, 3, ... 360). The time series does not increase in a linear fashion, one data point to the next may increase by any amount between 0 and 360. I want to resample this time series to increase/decrease the number of samples within it. I've tried the standard resample() function as well as some other methods involving linspace() that did not work. I need the retain the fact that the time series only increases from one sample to the next, and never decreases. Is there a resample method that would work here?

채택된 답변

John D'Errico
John D'Errico 2023년 6월 14일
This is really an interpolation problem. You can call it a resampling, but interpolation is all it is. And you can do everything using just interp1. Simplest is to just use a linear interpolation. Here is a simple series that is monotonic, but is also difficult to interpolate if you want a monotonic interpolant.
y = cumsum(randi(10,1,10).^3);
ny = numel(y);
x = 1:ny;
plot(x,y,'o')
Now, if I were to use a spline, for example, it would produce results that are not monotonic.
xint = linspace(1,ny,5*ny - 4); % 4 new points between each original point.
yspl = interp1(x,y,xint,'spline'); % this won't be monotone
ylin = interp1(x,y,xint,'linear'); % linear MUST be monotonic
ypchip = interp1(x,y,xint,'pchip'); % pchip is also always monotonic
plot(x,y,'ro',xint,yspl,'r-',xint,ylin,'g-',xint,ypchip,'k-')
grid on
legend("Original series","Spline","Linear","Pchip")
So the red curve (the spline) is not monotonic on this crappy series. The green one is, but it is just connect the dots linear interpolation. It is not bad, but nothing spectacular. The black curve is as smooth as possible, and also monotonic.
  댓글 수: 3
John D'Errico
John D'Errico 2023년 6월 14일
NO. Think about how linspace works. It generates a vector of length that third argument. If you want to decrease the number of points, then you would use a SMALLER value than ny.
y = cumsum(randi(10,1,30).^3);
ny = numel(y)
ny = 30
How long is y? y has 30 elements here. If you wanted to have only 10 elements, then specify a SMALLER number than 30.
xint = linspace(1,ny,10);
Spencer Ferris
Spencer Ferris 2023년 6월 14일
Okay, I think I understand now, thanks for the clarification. So if I had a time series y with a length of 100 and wanted to decrease the length to 90, I would run this and then pass it to one the interporlation methods, correct?
y = cumsum(randi(10,1,100).^3);
ny = numel(y);
x = 1:ny;
xint = linspace(1,ny,90);
This goes a bit beyond the Matlab aspect of it so no worries if you have no advice for this, but if this is the method I use, would it generally be better (in terms of maintaining the fidelity of the curves and trajectories of my data) to increase each time series in length rather than decrease them?

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by