Help interpolating irregular time series to regular time series

3 views (last 30 days)
Hello,
I have irregular time series data: (time, X-acceleration, Y-acceleration, Z-acceleration)
19:24:26.850, -0.11492168, 0.038307227, 9.634268
19:24:26.859, -0.12449849, 0.038307227, 9.662998
19:24:26.872, -0.1340753, 0.05746084, 9.672575
19:24:26.884, -0.12449849, 0.02873042, 9.615114
19:24:26.889, -0.15322891, 0.047884032, 9.643845
19:24:26.902, -0.10534488, 0.06703765, 9.662998
19:24:26.909, -0.076614454, 0.076614454, 9.624691
19:24:26.921, -0.095768064, 0.05746084, 9.653421
19:24:26.935, -0.05746084, 0.095768064, 9.624691
19:24:26.939, -0.06703765, 0.05746084, 9.672575
etc.
How can I interpolate/resample(?) the data so that I can get accelerations every 0.010 seconds? I can add the date to the time string with no problems, I'll even have too soon. Thank you very much!
Oleg
  2 Comments
Jan
Jan on 9 Jun 2014
Please explain the format of your data. Is "19:24:26.850" a string? Is this a cell array? When you post the data in a valid Matlab syntax, creating an meaningful answer is easier.
Oleg
Oleg on 9 Jun 2014
I'm sorry, I'm very new to MatLab. Yes, it's a string from a log file that I read in like this:
fid = fopen('c:\MatLabData\log.txt', 'rt');
a = textscan(fid, '%s %f %f %f', ... 'Delimiter',',', 'CollectOutput',1);
fclose(fid);
format short g
M = [datenum(a{1}) a{2}]
RtSumSqsCol = sqrt(M(:,2).^2+M(:,3).^2+M(:,4).^2)
RtSumSqsColNoGrav = RtSumSqsCol-9.8
M = [M RtSumSqsColNoGrav]
to get data that looks like this:
7.356e+05 -1.245 4.7884 11.281 2.5187
7.356e+05 -1.1109 5.1427 11.435 2.7871
7.356e+05 -0.99599 5.3439 11.358 2.7919
7.356e+05 -0.74699 5.4779 11.262 2.7461
7.356e+05 -0.74699 5.4779 11.262 2.7461
7.356e+05 -0.73741 5.5641 11.253 2.7749
but I need it at a regular time interval. I will try the answers soon, thanks so far!

Sign in to comment.

Accepted Answer

Chad Greene
Chad Greene on 9 Jun 2014
Letting t be column 1 and x be column 2, interpolate values xi corresponding to ti:
ti = yourStartingTime + 0:.010:3; % this represents 3 seconds at 0.010 second intervals.
xi = interp1(t,x,ti);
  1 Comment
Chad Greene
Chad Greene on 9 Jun 2014
If your time series is acceleration, spline interpolation may be more appropriate than the default linear.
xi = interp1(t,x,ti,'spline');

Sign in to comment.

More Answers (1)

Oleg
Oleg on 10 Jun 2014
Thank you for pointing me in the right direction! I was able to use your answer to get this:
Torig=M(:,1)
Acc = M(:,5)
plot(Torig,Acc)
datetick('x')
Ti=[Torig(1):1/24/60/60/1000:Torig(end)]';
Acci=interp1(Torig,Acc,Ti,'spline');
plot(Ti,Acci);
datetick('x')

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!