Function or Process For Time Series Correction
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
dpb
2017-8-13
编辑:dpb
2017-8-15
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
2017-8-16
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Curve Fitting Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!