Interpolate data in array to match specified length of data in another vector.

조회 수: 31 (최근 30일)
AS
AS 2021년 3월 26일
댓글: AS 2021년 3월 26일
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.

채택된 답변

KSSV
KSSV 2021년 3월 26일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by