Question: Assignment 1: Heart Rate Detection The goal of this assignment is to introduce you to ECG data processing as you quantify the heart rate of

Assignment 1: Heart Rate Detection The goal of this assignment is to introduce you to ECG data processing as you quantify the heart rate of various ECG signals. You will create a MATLAB function that receives three input variables and then outputs five variables. Input variables S this variable contains the ECG signal in mV. The signal is sampled at sfecg Hz. . . ipeaks This variable contains the labels for segments of the ECG signal stored in s: The value O means that there is not an ECG event at that time. The value 1 indicates the location of every identified P wave. The value 2 indicates the location of every identified Q wave. The value 3 indicates the location of every identified R wave. The value 4 indicates the location of every identified S wave. The value 5 indicates the location of every identified T wave. The first value in ipeaks ( ipeaks(1) ) is always a 3, indicating that s always starts at the location of an R peak. The last non-zero value in ipeaks is always a 2, though it is likely that several Os will follow the final 2. sfecg This variable contains the sample rate (in Hertz) of the ECG signal stored in s. Your function Your task is to create a function that outputs the five variables described below. You may use the example code included uploaded with this document as the shell for your function. There are three basic calculations that you will compute: (1) the average heart rate over the entire ECG signal, (2) the instantaneous heart rate with their corresponding time points, and (3) the beat-to-beat heart rate with 6-beat averaging with corresponding time points. Each of these calculations is explained below. (1) Average heart rate Recall that the average heart rate is a value expressed in beats per minute. To obtain this value, you may use the equation discussed in class: H Raverage 60 (T; +T2 + Tz + ... + T. +In - [BPM), where n is the total number of beats and Tn is the time (in seconds) between the R wave of beat n and the R wave of beat n-1. The same result may also be obtained by simplifying: 60 HRaverage = (BPM), (Ten -TR), where Ton is the time (in seconds) of the final R wave in the average window and TR is the time (in seconds) of the first R wave in the average window. (2) Instantaneous heart rate Recall that the instantaneous heart rate at beat n can be calculated using the equation: 60 HRinstantaneous.Rn [BPM), (Trn - Tri-) where Ton is the time (in seconds) of the most recent Rwave (n), and Trr: is the time (in seconds) of the R wave that occurred before beat n. Because HRinstantaneous,Rm is dependent on two R waves, HRinstantaneous,Ron can only be determined for times when you have at least two R waves recorded. So, the first Rwave cannot yield a value for HRinstantaneous,Rn. Thus, RR1 and its corresponding time array (t1) will only begin at the second Rwave. (3) Beat-to-beat heart rate with 6-beat averaging Recall that the beat-to-beat heart rate with 6-beat averaging can by obtained by modifying the average heart rate equation to take the average heart rate over the last 6 RR intervals (7 beats required): 60 HR6-beat average, -[BPM), (Ten - Trad) where Ton is the time (in seconds) of the final R wave in the average window and Trno is the time (in seconds) of the first R wave in the average window (7 beats ago). Because H R6-beat average.n is dependent on two 7 waves, HR6-beat average.n can only be determined for times when you have at least 7 R waves recorded. So, the first six R waves cannot yield a value for HRinstantaneous,Rn. Thus, RR6 and its corresponding time array (t2) will only bepin at the seventh R wave Output variables The output of your function must be exactly right in order to get credit for your assignment. Please see the format of the output variables below: avgHR This variable holds a single value that is the average heart rate of the entire ECG signal, calculated from the first R wave to the final Rwave. Do not round any value. As an example, for an ECG signal that has 8 recorded R waves, occurring at the time values below, the RR1 and t1 arrays should look contain the following values: Rwaves located at the following times: 0 1 2.5 3 4 5 6.25 avgHR 60 7 RR1 This variable holds an array of values that contain the instantaneous heart rate (BPM) corresponding to the time values stored in ti. ti This variable holds an array of time values for the times at which the instantaneous heart rate (RR1) is calculated. As an example, for an ECG signal that has 8 recorded R waves, occurring at the time values below, the RR1 and 1 arrays should look contain the following values: R waves located at the following times: 0 1 2.5 3 4 5 6.25 7 RR1 1 1.5 0.5 1 1 ti 1 2.5 3 4 5 6.2 7 1.2 0.75 RR6 This variable holds an array of values that contain the beat-to-beat with 6-beat averaging heart rate (BPM) corresponding to the time values stored in t6. t6 This variable holds an array of time values for the times at which the instantaneous heart rate (RR6) is calculated. As an example, for an ECG signal that has 8 recorded R waves, occurring at the time values below, the RR1 and t1 arrays should look contain the following values: Rwaves located at the following times: 0 1 2.5 3 4 5 6.25 7 RR6 57.6 60 T6 6.25 7 Submission Format and Grading You must submit your file as a function with the name: "HR_#########.m", where ######### is replaced by your student ID number. For example, if my student ID number is 1234567890, then I would submit my function saved as "HR_1234567890.m". For grading, your function will be used to output all five output variables for 10 sets of input variables that I give you. Five of the input sets are uploaded as "examplel.mat", "example2.mat"... "example5.mat". The other five input sets are unknown to you but will have the same formatting as the other input sets. You code will be called like this, after the input set variables are loaded into the workspace: >> (avgHR, t1, RR1, t6, RR6 ] HR_key (s, ipeaks, sfecg); If your output variables (avgHR, t1, RR1, t6, RR6) are the correct values, you will get full credit for that run (5/5). If your function does not run or returns an error, you will receive 0/5 for that run. For any of the 5 outputs that not exactly the right answer, you will lose 1/5 for that run. Your code will be run a total of 10 times with different input sets, so the total possible score is 50/50. To help you check and score yourself for the five given input sets, each example input set also contains the correct answers saved as the appropriate variable name with _ans" added to the end of the variable name. If you score below 60% (30/50) on your first submission, you will be allowed to submit again with corrected code, but your score will be multiplied by a factor of 0.6, so your maximum possible score on your resubmission is 30/50. Your code will be checked rigorously for plagiarism. You may help people only by describing how the code should work with your words, by drawing a flow chart/algorithm or by recommending certain operations. You may not show anyone your code. Assignment 1: Heart Rate Detection The goal of this assignment is to introduce you to ECG data processing as you quantify the heart rate of various ECG signals. You will create a MATLAB function that receives three input variables and then outputs five variables. Input variables S this variable contains the ECG signal in mV. The signal is sampled at sfecg Hz. . . ipeaks This variable contains the labels for segments of the ECG signal stored in s: The value O means that there is not an ECG event at that time. The value 1 indicates the location of every identified P wave. The value 2 indicates the location of every identified Q wave. The value 3 indicates the location of every identified R wave. The value 4 indicates the location of every identified S wave. The value 5 indicates the location of every identified T wave. The first value in ipeaks ( ipeaks(1) ) is always a 3, indicating that s always starts at the location of an R peak. The last non-zero value in ipeaks is always a 2, though it is likely that several Os will follow the final 2. sfecg This variable contains the sample rate (in Hertz) of the ECG signal stored in s. Your function Your task is to create a function that outputs the five variables described below. You may use the example code included uploaded with this document as the shell for your function. There are three basic calculations that you will compute: (1) the average heart rate over the entire ECG signal, (2) the instantaneous heart rate with their corresponding time points, and (3) the beat-to-beat heart rate with 6-beat averaging with corresponding time points. Each of these calculations is explained below. (1) Average heart rate Recall that the average heart rate is a value expressed in beats per minute. To obtain this value, you may use the equation discussed in class: H Raverage 60 (T; +T2 + Tz + ... + T. +In - [BPM), where n is the total number of beats and Tn is the time (in seconds) between the R wave of beat n and the R wave of beat n-1. The same result may also be obtained by simplifying: 60 HRaverage = (BPM), (Ten -TR), where Ton is the time (in seconds) of the final R wave in the average window and TR is the time (in seconds) of the first R wave in the average window. (2) Instantaneous heart rate Recall that the instantaneous heart rate at beat n can be calculated using the equation: 60 HRinstantaneous.Rn [BPM), (Trn - Tri-) where Ton is the time (in seconds) of the most recent Rwave (n), and Trr: is the time (in seconds) of the R wave that occurred before beat n. Because HRinstantaneous,Rm is dependent on two R waves, HRinstantaneous,Ron can only be determined for times when you have at least two R waves recorded. So, the first Rwave cannot yield a value for HRinstantaneous,Rn. Thus, RR1 and its corresponding time array (t1) will only begin at the second Rwave. (3) Beat-to-beat heart rate with 6-beat averaging Recall that the beat-to-beat heart rate with 6-beat averaging can by obtained by modifying the average heart rate equation to take the average heart rate over the last 6 RR intervals (7 beats required): 60 HR6-beat average, -[BPM), (Ten - Trad) where Ton is the time (in seconds) of the final R wave in the average window and Trno is the time (in seconds) of the first R wave in the average window (7 beats ago). Because H R6-beat average.n is dependent on two 7 waves, HR6-beat average.n can only be determined for times when you have at least 7 R waves recorded. So, the first six R waves cannot yield a value for HRinstantaneous,Rn. Thus, RR6 and its corresponding time array (t2) will only bepin at the seventh R wave Output variables The output of your function must be exactly right in order to get credit for your assignment. Please see the format of the output variables below: avgHR This variable holds a single value that is the average heart rate of the entire ECG signal, calculated from the first R wave to the final Rwave. Do not round any value. As an example, for an ECG signal that has 8 recorded R waves, occurring at the time values below, the RR1 and t1 arrays should look contain the following values: Rwaves located at the following times: 0 1 2.5 3 4 5 6.25 avgHR 60 7 RR1 This variable holds an array of values that contain the instantaneous heart rate (BPM) corresponding to the time values stored in ti. ti This variable holds an array of time values for the times at which the instantaneous heart rate (RR1) is calculated. As an example, for an ECG signal that has 8 recorded R waves, occurring at the time values below, the RR1 and 1 arrays should look contain the following values: R waves located at the following times: 0 1 2.5 3 4 5 6.25 7 RR1 1 1.5 0.5 1 1 ti 1 2.5 3 4 5 6.2 7 1.2 0.75 RR6 This variable holds an array of values that contain the beat-to-beat with 6-beat averaging heart rate (BPM) corresponding to the time values stored in t6. t6 This variable holds an array of time values for the times at which the instantaneous heart rate (RR6) is calculated. As an example, for an ECG signal that has 8 recorded R waves, occurring at the time values below, the RR1 and t1 arrays should look contain the following values: Rwaves located at the following times: 0 1 2.5 3 4 5 6.25 7 RR6 57.6 60 T6 6.25 7 Submission Format and Grading You must submit your file as a function with the name: "HR_#########.m", where ######### is replaced by your student ID number. For example, if my student ID number is 1234567890, then I would submit my function saved as "HR_1234567890.m". For grading, your function will be used to output all five output variables for 10 sets of input variables that I give you. Five of the input sets are uploaded as "examplel.mat", "example2.mat"... "example5.mat". The other five input sets are unknown to you but will have the same formatting as the other input sets. You code will be called like this, after the input set variables are loaded into the workspace: >> (avgHR, t1, RR1, t6, RR6 ] HR_key (s, ipeaks, sfecg); If your output variables (avgHR, t1, RR1, t6, RR6) are the correct values, you will get full credit for that run (5/5). If your function does not run or returns an error, you will receive 0/5 for that run. For any of the 5 outputs that not exactly the right answer, you will lose 1/5 for that run. Your code will be run a total of 10 times with different input sets, so the total possible score is 50/50. To help you check and score yourself for the five given input sets, each example input set also contains the correct answers saved as the appropriate variable name with _ans" added to the end of the variable name. If you score below 60% (30/50) on your first submission, you will be allowed to submit again with corrected code, but your score will be multiplied by a factor of 0.6, so your maximum possible score on your resubmission is 30/50. Your code will be checked rigorously for plagiarism. You may help people only by describing how the code should work with your words, by drawing a flow chart/algorithm or by recommending certain operations. You may not show anyone your code
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
