1

I have some data that was acquired from an individual that moved a cursor from one target that was presented on a screen to another straight-ahead target that was 10 centimeters away from the original start position. I have 15 movements from this person. The data I have is the instantaneous x-position x(t) and y-position y(t)of the cursor for each movement. Because the individual did not move the mouse at the exact same speed from one movement to another, the number of samples for each movement is not the same. Below, I am showing the x-positions, y-position, and complete x-y trajectory for all movements. A link to download the data is here as well. Hopefully this gives a sense for the nature of the data. Note that the cursor position always start at the [0,0] point, but don't always exactly end at the [0,10] point.

Fig 1

Fig 2

I am tasked with linearly interpolating the x-positions of the cursor onto a vector of y-positions every 0.05cm in order to align the cursor measurements across movements (that is, I must obtain x(y). I would like to present my code below and get some feedback about whether or not I am doing this correctly:

%% Try interpolating x as a function of y (i.e., transform x(t) to x(y))
%Goal is to linearly interpolated the x-positions of the cursor onto a
%vector of y-positions every 0.05cm to align the hand path measurements
%across movements

clear all;
close all;
home;

%load the data: xpos & ypos
load('pos_data.mat')

%create cell array that will hold interpolated data
x_interp = cell(size(xpos));
y_interp = cell(size(ypos));

%construct grid vector
ypos_grid = [0:0.05:10];
num_interp_samples = length(ypos_grid);

%loop through each movement
for k=1:num_movements
    %get data for the current movement
    xp = xpos{k};
    yp = ypos{k};
    
    %to deal with duplicate samples, I add a very small offset to each
    %sample to make them all unique
    offset = cumsum([0:length(yp)-1]*1e-16);
    yp2 = yp+offset(:);
    
    %interpolate xp wrt yp
    x_interp{k} = interp1(yp2, xp, ypos_grid);
    
    %interpolate yp so that it is the same size as x_interp
    t = linspace(1,length(yp2),length(yp2));
    ti = linspace(1,length(yp2),num_interp_samples);
    y_interp{k} = interp1(t, yp2, ti);
    
end

I think this should be relatively simple, but when I plot the interpolated data, it looks a bit strange to me. See below:

Fig3

Namely, the trajectories seem to have lost much of its "curvature", which has me worried. Note when plotting the interpolated trajectories, I am simply doing:

figure; hold on;
for k=1:num_movements
    plot(x_interp{k}, y_interp{k}, 'color', 'k');
end
xlabel('x-position (cm)');
ylabel('y-position (cm)');
title('Examples of complete trajectories (interpolated data)');
axis equal;

Here are my specific questions:

(1) Am I interpolating correctly?

(2) If the answer to (1) is yes, then am I interpreting the interpolated result correctly? Specifically, why do the shapes of the trajectories appear as they doo (lacking curvature)?

(3) Am I perhaps missing a step where after obtaining x(y), I should re-transform the data back into x(t)?

John Alperto
  • 157
  • 8

0 Answers0