Interpolating data based on the time segments.
3 次查看(过去 30 天)
显示 更早的评论
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]
0 个评论
采纳的回答
Walter Roberson
2015-9-28
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 个评论
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
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!