Interpolate data in array to match specified length of data in another vector.
42 views (last 30 days)
Show older comments
I have a matrix (A) of data recorded at 100Hz and another matrix (B) recorded at 2000Hz over the same period of time. The data is synchronised so start and end time points match. How can I upsample the data in matrix A to match the length of the data in matrix B? I understand interp1 is the tool to use but am unsure how to implement this.
I tried something like this, but ended up with NaNs in A_new after the length of A;
Here, A is a 1267 x 3 and B is a 52820 x 1.
for i = 1:3
x1 = 1:1:size(A(:,i))
v1 = (A(:,i))'
xq1 = 1:1:size(B,1) %Define num of points for finer sampling range over x.
A_new(:,i) = (interp1(x1,v1,xq1))'; %Interpolate the function at the query points.
end
Thanks.
0 Comments
Accepted Answer
KSSV
on 26 Mar 2021
m = size(A,1) ; % m = 1267
n = size(B,1) ; % n = 52820
A_new = zeros(n,3) ;
xi = (1:n)' ;
x = linspace(1,n,m)' ;
for i = 1:3
Ai = interp1(x,A(:,i),xi) ;
A_new(:,i) = Ai ;
end
More Answers (0)
See Also
Categories
Find more on Multirate Signal Processing 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!