Objective
To gain practical experience of computer programming and design using MATLAB.
Introduction
A team of engineers has developed a novel robotic device for interventional procedures. Based on pre-acquired 3D images (known as “road maps”), a target trajectory of the device is first generated to define an optimal route to reach an anatomical target. The robotic device is then automatically advanced based on the pre-defined target trajectory.
Instructions
In a first experiment, the target trajectory and actual trajectory achieved by the device have been
stored into two separates files. Each file contains one trajectory and is of the
following format:
-0.00314 -0.08847 0.01996
-0.00345 -0.08737 0.01995
-0.00377 -0.08628 0.01994
...
where each line represent one 3D position in space in metres (as three comma separated numbers).
Note that the sampling frequency in this file is 1000 Hz (i.e. one position every ms).
You are required to write MATLAB code (avoiding code duplication) to perform the following
operations:
1.Read in the data from the files targetTrajectory.txt and actualTrajectory.txt. If a file does not exist report an error and stop the program. If the files contain different numbers of measurements, the program should also report an error. (Hint: Look at the MATLAB documentation for the exist function.)
2.Determine the mean distance (MeanD) and maximum distance (MaxD) between the actual trajectory and the target trajectory, ignoring the first and last 50 samples of both trajectories. The Euclidean distance should be used to compute the distance between each pair of points of the two trajectories. The use of the built-in function norm is not allowed in this implementation.
3.Determine the temporal delay (i.e. temporal shift) of the actual trajectory with respect to the target trajectory. A delay can be observed due to imperfect response of the system. Find the delay leading to the best temporal alignment of the two trajectories (i.e. the lowest MeanD). To find this delay, implement an exhaustive search for a range of realistic delays (from 0 ms to 50 ms, in steps of 1 ms) and identify the delay leading to the smallest MeanD. The MeanD metric should again be computed by ignoring the first and last 50 samples of both trajectories.
4.Compute the MeanD and MaxD after correction of the delay, as described in Step 2.
5. Determine the total time when the delay-corrected actual trajectory was more than 2 millimetres away from the target trajectory. As such cases could happen due to measurement noise in the actual trajectory, report the total time when the delay-corrected actual trajectory was more than 2 millimetres away from the target trajectory for at least 3 ms (i.e. for three successive measurements).
6. Display the original actual trajectory and the target trajectory in subplot 1 and the delaycorrected actual trajectory and the target trajectory in subplot 2 as shown in Figure 1. Only the first 200 samples should be shown on these plots to facilitate visualisation. Annotate your plots appropriately. Display to the command window the following information: the delay, the total time away from the target trajectory by more than 2 mm, the consistent time away from the target trajectory by more than 2 mm (i.e. for at least 3 ms), and the MeanD and MaxD before and after delay correction. The MeanD and MaxD should be displayed with 7 digits after the decimal point. For example, for the provided files, the command window output should be similar to this:
delay: 10
totalTimeAwayFromTraj: 98
consistentTimeAway: 0
meanD (init: 0.0000078; corrected: 0.0000033)
maxD (init: 0.0000206; corrected: 0.0000087)
The plot should look similar to that shown in Figure 1. Note that you should write your program in such a way that it will work for any input files with the same format as those provided. Your code will be tested using files from different experiments .