Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Cannot use explicit loops(for or while) or the if statement. Only Matlab\'s impl

ID: 1797590 • Letter: C

Question

Cannot use explicit loops(for or while) or the if statement. Only Matlab's implicit looping(array operations and intrinsic functions) is allowed. In addition, cannot use anything from the Matlab toolboxes.

P r o b l e m 0 3 – S i m u l a t e d  E C G  S i g n a l
In this problem we will do an abbreviated examination of a simulated ECG Signal.

Task 1: Copy the data file p2_data03.txt from the course web site and store it in your current working
directory. Put in your script file a command that will import this file into MATLAB and store it in a variable
called data_in. The file has two values per line, the first value is a time (in ms) and the second is the ECG
value (in mV). Assign these two column vectors TIME and ECG. (Remember: We will import a different
file when we grade your project. It will have two values per line but a different number of lines!)

Task 2: The first step is to “filter” the ECG by subtracting from each value, the mean of the values in a
"window" about it. We will use a window width of 3. To do this, create a column vector ECG_up by
"shifting up" the entries in ECG, so the first entry in ECG_up is ECG(2), the second entry is ECG(3), etc.,
and then appending, as the last entry in ECG_up the number 0. Likewise, create a column vector
ECG_dn by "shifting down" the entries in ECG so that the second entry in ECG_dn is ECG(1), the third
entry is ECG(2), etc., prepending as the first entry in ECG_dn the number 0. Now all three vectors (ECG,
ECG_up, ECG_dn) are the same length, so we can add them and divide by 3, to "almost" get the vector
we need to subtract from ECG. Almost, because the first and last components will not be correct. Fix
those by replacing the first and last values by taking the mean of the first 3 and last 3 values of ECG
respectively. Finally calculate the "filtered" ECG (call it ECGF). If there are N ECG values, display in a
three column table, the time, ECG, and ECGF values for the first 5, N/2, N/2+1, N/2+2, and the last 5
samples. (We do NOT want to see all of them!)

Task 3: With our current knowledge of Matlab, we cannot find the local peaks or R waves, so, instead,
find the value of the 2nd highest overall ECGF and the first time that it occurred. Display these, clearly
labeled

p2_data03.txt:

Explanation / Answer

[time, ECG] = textread('p2_data03.txt','%f %f') vec_len=length(ECG); ECG_up=zeros(vec_len,1); ECG_up(1:end-1) =ECG(2:end); ECG_dn=zeros(vec_len,1); ECG_dn(2:end) = ECG(1:end-1); ECG_mean=(ECG+ECG_up+ECG_dn)/3; ECG_mean(1)=(ECG(1)+ECG(2)+ECG(3))/3; ECG_mean(vec_len)=(ECG(end)+ECG(end-1)+ECG(end-2))/3; ECGF=ECG-ECG_mean; n_2=ceil(vec_len/2); table = zeros(13,3); table(1:5,1)=time(1:5); table(1:5,2)=ECG(1:5); table(1:5,3)=ECGF(1:5); table(6,1)=time(n_2); table(6,2)=ECG(n_2); table(6,3)=ECGF(n_2); table(7,1)=time(n_2+1); table(7,2)=ECG(n_2+1); table(7,3)=ECGF(n_2+1); table(8,1)=time(n_2+2); table(8,2)=ECG(n_2+2); table(8,3)=ECGF(n_2+2); table(9:13,1)=time(end-4:end); table(9:13,2)=ECG(end-4:end); table(9:13,3)=ECGF(end-4:end); table plot(time, ECGF) sorted = sort(ECGF,'descend') max_2=sorted(2); index_max_2 = find(ECGF==max_2); time_max_2 = time(index_max_2);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote