Question: Before starting any coding, you should produce a structured design for your program, using structure charts and / or pseudocode. You should then apply an

Before starting any coding, you should produce a structured design for your program, using structure charts and/or pseudocode. You should then apply an incremental development approach to develop your code.
There are many ways that this exercise can be tackled and a good approach is to break the tasks that you need to do down so that they can be implemented in multiple functions that are called by a single main function or script. 1. Read the data: First ask the user for the name of the file. If the file does not exist, the program should flag an error and stop. Otherwise, the program should read in the entire list of 1-dimensional signals from the file and store them in a variable.
2. Calculate the shift (i.e. breathing motion) between the first 1-dimensional signal (which we call the reference signal) and all subsequent ones. To calculate the shift between any 1dimensional signal and the reference signal, you should perform an exhaustive search of all possible shifts (from -10 to 10 in steps of 1) and return the shift that results in the best match between the reference signal and the shifted signal. The best match will be defined as the
Figure 1: 1-dimensional signal acquired at two different phases of the breathing cycle (endinspiration and end-expiration).
one with the smallest mean squared error (MSE). The MSE between two signals (\( s 1\) and \( s 2\)) is defined as follows:
\[
M S E=\frac{1}{\max -\min +1}\sum_{n=\min }^{\max }(s 1(n)-s 2(n))^{2}
\]
where \(\min \) and \(\max \) represent an area of interest in the 1-dimensional signal which contains the liver/lung interface. In our case, \(\min \) and \(\max \) should be set to 20 and 80. This enables the beginning and end of the signal (which may contain signal from other organs) to be ignored.
Hint: Read the documentation of the built-in MATLAB function circshift which can be used to apply a known shift to a 1-dimensional signal.
3. Determine the average shift during the end-expiration position. This should be calculated as the average shift of the \(20\%\) most extreme positions towards the feet of the patient.
4. Calculate the number of measurements that were performed during the end-expiration phase, defined as a shift within \(\pm 5\mathrm{~mm}\) of the end-expiration average shift. We refer to this range as the end-expiration window.
5. Save all the results into a text file which has the following format: 200 rows corresponding to each of the 200 measurements. Each row should contain 2 numbers: 1) the calculated shift and 2) a Boolean indicating whether the measurement was acquired within the end-expiration window \((=1)\) or outside \((=0)\). These two numbers should be separated by a semi-colon.
6. Plot the evolution of the shift as a function of time (during the 10s of acquisition). A blue square should be added to the plot for all measurements performed in the end-expiration window. The window should also be displayed using green dotted lines. The plot should be suitably annotated.
7. Display the following information: 1) the average shift during the end-expiration window, and 2) the number of measurements acquired within the end-expiration window. Expected output
The expected output plot for your program when run on the provided data file is shown in Fig. 2.
Figure 2: Expected output of the program when run on the provided data file.
The expected output at the command window for your program when run on the provided data file is as follows:
Average shift in end-experiatory position: -9.400000
percentage of measurements within gating window: \(35.500000\%\)
Before starting any coding, you should produce a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!