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

24 views (last 30 days)
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?

Accepted Answer

John D'Errico
John D'Errico on 14 Jun 2023
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 Comments
John D'Errico
John D'Errico on 14 Jun 2023
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 on 14 Jun 2023
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?

Sign in to comment.

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!