Interpolating data based on the time segments.

Hello everybody,
I have a time series with the average sample 1 second but samples some time delay more or less than that. I want to interpolate between those segments so i will have a sampling rate of 10ms, ie. creating 100 samples out of that. I know how to do it with a loops and logical expressions but was wandering if matlab has functions and tricks to do it faster. This is a piece of data i want to interpolate.
t=[0
0.391912101000000
1.32177628400000
2.41211658700000
3.40585991000000
4.91603845400000
5.41236075000000
6.35266290000000
7.39591026800000
8.33071875300000
9.35080115800000
10.3286128480000
11.3210437940000
12.3288264900000
13.3216847220000
14.3908438870000
15.3411872390000
16.9984129380000
17.3812299690000
18.3304135490000
19.3526934200000
20.3328551780000
21.9144513930000
22.3394475780000
23.3421944120000
24.3500686680000
25.3540363150000
26.6359224740000
27.3324889320000
28.3450633250000]
so out of 30 samples i want to create around 2834 samples.
thanks in advance.
if i will create let say:
for i=2:length(t);
ti=[];
ti=t(i-1):0.1:t(i);
tn{i-1}=interp1((t(i-1):t(i)),(t(i-1,1):t(i,1)),ti);
end
will fail because
ti=[0 0.100 0.200 0.300]
which is not the same as
(t(i-1):t(i))=[0,0.39]

 採用された回答

Walter Roberson
Walter Roberson 2015 年 9 月 28 日

0 投票

Presuming that you also have a data array that you want to interpolate:
new_t = t(1):0.01:t(end);
new_data = interp1(t, YourData, new_t);

5 件のコメント

DuckDuck
DuckDuck 2015 年 9 月 28 日
編集済み: Walter Roberson 2015 年 9 月 28 日
i know this, but i want to use this time series to interpolate other data, and some times in the interval the data do not change and interpolation fails.
for instance:
data=[
0 50 284.500000000000 12.5000000000000
0.391912101000000 49 285.300000000000 10.5000000000000
1.32177628400000 48 285 8.75000000000000
2.41211658700000 49 275.700000000000 7.75000000000000
3.40585991000000 49 255.800000000000 7.50000000000000
4.91603845400000 49 231.800000000000 8
5.41236075000000 49 208 9.25000000000000
6.35266290000000 49 195.100000000000 10.5000000000000
7.39591026800000 48 193 11.5000000000000
8.33071875300000 48 194.200000000000 13
9.35080115800000 48 194.500000000000 14
10.3286128480000 47 193.300000000000 15
11.3210437940000 47 193.800000000000 15.5000000000000
12.3288264900000 47 192.600000000000 16
13.3216847220000 47 192.300000000000 16.5000000000000
14.3908438870000 47 194.500000000000 17
15.3411872390000 46 196.800000000000 16.7500000000000
16.9984129380000 46 195.700000000000 15.7500000000000
17.3812299690000 46 196.400000000000 18
18.3304135490000 46 196.900000000000 16.5000000000000
19.3526934200000 46 196.400000000000 17.2500000000000
20.3328551780000 46 194.400000000000 18.7500000000000
21.9144513930000 46 193.400000000000 18.7500000000000
22.3394475780000 46 193.300000000000 18.7500000000000
23.3421944120000 47 194.800000000000 17.5000000000000
24.3500686680000 47 194.100000000000 17.2500000000000
25.3540363150000 46 193.300000000000 17
26.6359224740000 46 192.100000000000 16.7500000000000
]
As you can see the interp1 will fail with the data from the 2nd column as they do not increment. and i have to implement logical if else which is not that elegant in matlab.
Walter Roberson
Walter Roberson 2015 年 9 月 28 日
I do not see the problem.
new_t = data(1,1):0.1:data(end,1);
new_data2 = interp1(data(:,1), data(:,2), new_t);
new_data3 = interp1(data(:,1), data(:,3), new_t);
new_data4 = interp1(data(:,1), data(:,4), new_t);
You always use your time as your x and your interpolated time as the x to interpolate at, but vary the data associated with the times as appropriate.
DuckDuck
DuckDuck 2015 年 9 月 28 日
if i will create let say:
for i=2:length(t);
ti=[];
ti=t(i-1):0.1:t(i);
tn{i-1}=interp1((t(i-1):t(i)),(t(i-1,1):t(i,1)),ti);
end
will fail because
ti=[0 0.100 0.200 0.300]
which is not the same as
(t(i-1):t(i))=[0,0.39]
Walter Roberson
Walter Roberson 2015 年 9 月 28 日
So don't do that?
new_t = unique([(t(1):0.1:t(end)).'; t(:)]);
[~, idx] = ismember(t, new_t);
tn = mat2cell(new_t(1:end-1), diff(idx), 1);
Note: this tn array will never include t(end) in it. Your existing loop produces one fewer cell arrays than you have original t elements and this code preserves that behavior. Your code might possibly have generated t(end) at some point, but only if t(end) happened to be an integer that was an exact multiple of 0.1 from the previous element t(end-1). You are interpolating points between, and that always includes t(i) itself since that is the start of the colon operation, but t(end) might not be there (if it is is then should it be allocated to both ranges?) I used consistency about including each t(i) at the beginning of the range and not including t(end) as that would be the start of a final range with just the one point.
Peter Perkins
Peter Perkins 2015 年 9 月 28 日
effess, you said, "some times in the interval the data do not change and interpolation fails". Just for the record, interp1 expects the x values (time, in your case) to be monotonically increasing, but the y variable (or variabels in your case) can be anything. This, for example
interp1(data(:,1),data(:,2:end),0:.01:26.7)
will absolutely not fail.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by