Function or Process For Time Series Correction
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have 20 time series of kicking actions, however the time series are all different lengths (e.g. 30 - 60 frames).
I am looking for a function or process which can help _ maintain the shape and magnitude of the curve_ while extending/reducing outliers to a single time length (e.g. return all curves to 45 frames).
Thank you in advanced.
Nick
0 Commenti
Risposte (2)
dpb
il 13 Ago 2017
Modificato: dpb
il 15 Ago 2017
Many ways to do this depending...if have the Signal Processing TB, there's resample in it using a polyphase filter or there's a slightly less sophisticated version in current base product for the builtin time series object if you're using it.
Or, there's something as simple as interp1 for linear to spline interpolants...take your pick.
ADDENDUM Incorporate comments and sample code--dpb
OK, for your kind of problem I'd forgotten that resample is subject to serious end effects as it assumes signal is 0 on ends and yours is quite large numerically. There are ways around it, but with pretty smooth data as you have and to simply "shrink" or "stretch" it, I'd just use a spline (linear is probably almost as good as smooth as the data are, but it's really no harder with spline in Matlab) and recompute the positions needed to make a fit of 1:N points that you have for each trace match up to the M (say 46) points you want.
displ=PaulAs...; % get a shorter name for brevity
M=46; % the target number of points/trace
N=sum(isfinite(displ),2); % the number of data points in each trace
m=(N-1)./(M-1); % slope of line between 1,1 and N,M vs 1:M
b=1-m; % and intercept for the interpolant
nTr=size(displ,1); % number traces
d=zeros(nTr,M); % preallocate the output array
for i=1:nTr
d(i,:)=spline(1:N(i),displ(i,1:N(i)),polyval([b(i) m(i)],1:M));
end
The above simply does a linear transformation of the N points to M scaled to 1:M so the output of the spline fit will be the same at the two end points but there will be the same number of points (M) in each trace.
d will thus be array of nTr by M points with each trace having 46 points and having same values at end points as do the original traces at beginning and last finite point of each.
The above can be more fully vectorized although I'm not sure it would be any faster.
John BG
il 16 Ago 2017
Hi Nick
the problem of obtaining same length is solved choosing the optimal values of interpolation and decimation:
1.
Loading data
load('.mat')
2.
Loading 1 line
trial = PaulAsisDisplacement(1,:)'; % read line
3.
Removing NaNs
trialvalues = trial(~any(isnan(trial),2),:) % remove NaNs
4.
So far your code, now consider that to go from whatever length of no NaN values to 45 you can always find a fraction, either to increase or decrease the amount of samples, to end up with the target length 45.
Ntarget=45;
[N1 D1]=rat(Ntarget/length(trialvalues)) % calculate interpolation Decimation optimal values
trialvalues45=decimate(interpolate(trialvalues,D1),N1)
Apply this to any line of the data and you end up with your data correctly interpolated.
if you find this answer useful would you please be so kind to consider marking my answer as Accepted Answer?
To any other reader, if you find this answer useful please consider clicking on the thumbs-up vote link
thanks in advance
John BG
0 Commenti
Vedere anche
Categorie
Scopri di più su Curve Fitting Toolbox 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!