Help interpolating irregular time series to regular time series

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 commentaires

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.
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!

Connectez-vous pour commenter.

 Réponse acceptée

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 commentaire

If your time series is acceleration, spline interpolation may be more appropriate than the default linear.
xi = interp1(t,x,ti,'spline');

Connectez-vous pour commenter.

Plus de réponses (1)

Oleg
Oleg le 10 Juin 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')

Catégories

En savoir plus sur Interpolation dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by