What resample method can I use for time series that increases nonlinearly?
35 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Spencer Ferris
il 14 Giu 2023
Commentato: Spencer Ferris
il 14 Giu 2023
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?
0 Commenti
Risposta accettata
John D'Errico
il 14 Giu 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 Commenti
John D'Errico
il 14 Giu 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)
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);
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Interpolation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!