interpolate data in timeseries
118 views (last 30 days)
Show older comments
Hi all,
I have a timeseries vector lets say with 7 points : v=[0.18 3.15 0.18 0.16 0.17 0.58 0.33 ];
I would like to create a new vector by interpolating data so I have extra 3 points among two values: somethng like:
v_new=[0.18 ... ... ... 3.15 ... ... 0.18... and so on ]
could you help me with that?
thanks!!
0 Comments
Accepted Answer
dpb
on 2 Dec 2021
v=[0.18 3.15 0.18 0.16 0.17 0.58 0.33 ]; % example data
% the engine
nI=3; % number points to insert
N=numel(v); % initial vector size
NN=(N-1)*nI+N; % new N for augmented v
xv=linspace(1,N,NN); % uniform spacing along 1:N NN points
vv=interp1(1:N,v,xv); % linear interpolation
vvv=interp1(1:N,v,xv,'pchip'); % or pchip interpolation
Illustrate results...
plot(v,'o-')
hold on
plot(xv,vv,'x')
plot(xv,vvv,'d-')
legend('Original','Linear','PChip')
produces
"Choose your poison" as far as what interpolant you actually want.
If you have Signal Processing TB, there's also resample you could play with.
0 Comments
More Answers (1)
Jon
on 2 Dec 2021
Edited: dpb
on 2 Dec 2021
Although you say you have a "time series" it looks like v is just an ordinary vector. Assuming you have another "t" vector to go along with this data you could do something like this:
t = [0 9 10 15 20 25 33] % made up example time vector, not necessarily evenly space
v = [0.18 3.15 0.18 0.16 0.17 0.58 0.33 ]; % your v vector
t_new = [0 2 3 9 9.5 9.8 10 11 12 15 20 21 21.2 25 29 30 33] % vector of times you want to have data for including original
v_new = interp1(t,v,t_new)
v_new =
Columns 1 through 11
0.1800 0.8400 1.1700 3.1500 1.6650 0.7740 0.1800 0.1760 0.1720 0.1600 0.1700
Columns 12 through 17
0.2520 0.2684 0.5800 0.4550 0.4237 0.3300
2 Comments
Jon
on 2 Dec 2021
My answer shows generally how to interpolate extra points. I see @dpb gave you more precisely what you asked for, an approach to insert exactly n points between your existing points assuming the original "t" values (independent variable) is equally spaced. From your description I wasn't sure if you could assume that.
See Also
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!