How to resample (or interpolate) trajectory from x original values to 100 values?

17 ビュー (過去 30 日間)
I have recorded multiple trajectories of varying timepoints and length. I wanted to see how correlated the trajectory patterns are to each other. To do so, I wanted to resample them to 100 points and make all the trajectories of equal timepoints so that we compare the pattern itself without the dependency of time.
To do so I used the following code:
resample_rate = 100;
xypos_resampled = zeros(resample_rate, trialno*2); % make space for multiple trajectories
trialtotest = 1; % say we are interested in trial (trajectory) 1
% Given 1 trajectory data
xypos = [0.0490, 0.0660;
0.2100, 0.2070;
0.4500, 0.4700;
0.6300, 0.8560;
0.6630, 1.3350;
0.5440, 1.8850;
0.3350, 2.4840;
0.2110, 3.0910;
0.2150, 3.6720;
0.3260, 4.2250;
0.5120, 4.7020;
0.7960, 4.9150;
1.1640, 4.8790;
1.5980, 4.7660;
2.0980, 4.6230;
2.6560, 4.4960;
3.2650, 4.4080;
3.9080, 4.3560;
4.5510, 4.3390];
xypos = cell2mat(tWin_unconcatenated_whole (1, trialtotest)) ;
xypos_resampled (:,trialtotest*2-1:trialtotest*2) = resample(xypos,resample_rate, length(xypos));
I got the following:
The top is the original trajectory and the bottom is the resampled one.
How to get rid of the unnecessary points or how to resample more effectively?
P.S. I tried gridded interpolant (but it needs to sort the data which I dont want to do).
Any insight would be appreciated.

採用された回答

Star Strider
Star Strider 2023 年 8 月 8 日
resample_rate = 100;
% xypos_resampled = zeros(resample_rate, trialno*2); % make space for multiple trajectories
trialtotest = 1; % say we are interested in trial (trajectory) 1
% Given 1 trajectory data
xypos = [0.0490, 0.0660;
0.2100, 0.2070;
0.4500, 0.4700;
0.6300, 0.8560;
0.6630, 1.3350;
0.5440, 1.8850;
0.3350, 2.4840;
0.2110, 3.0910;
0.2150, 3.6720;
0.3260, 4.2250;
0.5120, 4.7020;
0.7960, 4.9150;
1.1640, 4.8790;
1.5980, 4.7660;
2.0980, 4.6230;
2.6560, 4.4960;
3.2650, 4.4080;
3.9080, 4.3560;
4.5510, 4.3390];
% xypos = cell2mat(tWin_unconcatenated_whole (1, trialtotest)) ;
% xypos_resampled (:,trialtotest*2-1:trialtotest*2) = resample(xypos,resample_rate, length(xypos));
t = (0:size(xypos,1)-1).';
% % [xypos_resampled1,tr1] = resample(xypos, t, 100);
tr2 = linspace(min(t), max(t), 100).';
xypos_resampled2 = interp1(t, xypos, tr2);
figure
plot(xypos(:,1), xypos(:,2), '.-')
% % figure
% % plot(xypos_resampled1(:,1), xypos_resampled1(:,2), '.-')
figure
plot(xypos_resampled2(:,1), xypos_resampled2(:,2), '.-')
The resample call did not produce an acceptable result, so I commented it out.
The interp1 call appears to be more appropriate. For that, ‘tr2’ can either be as stated or:
tr2 = linspace(min(t), max(t), resample_rate*size(xypos,1)).';
depending on how you want to define it. Both should work.
.
  2 件のコメント
Poulomi
Poulomi 2023 年 8 月 14 日
Thnk you so much! This is exactly what I needed!
Star Strider
Star Strider 2023 年 8 月 14 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by