evaluatorShort

PURPOSE ^

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 clear all;
0002 close all;
0003 
0004 record = "infant4_ecg";
0005 proportion =0.05; % Proportion of record that we want to evaluate
0006 
0007 % General algorithm parameters:
0008 ensembleFilter = struct('isOn', 0, 'threshold', 0.2);
0009 madFilter = struct('isOn', 1, 'threshold', 10);
0010 n_missedBeats = struct('isOn', 1, 'threshold', 20);
0011 postProcessing = struct('ensembleFilter', ensembleFilter, 'madFilter', madFilter, 'missedBeats', n_missedBeats);
0012 medianFilter = struct('isOn', 1, 'windowSize', 3);
0013 tachoProcessing = struct('interpolationMethod', 'direct', 'medianFilter', medianFilter);
0014 params = struct('ecgFile', record, 'postProcessing', postProcessing, 'tachoProcessing', tachoProcessing);
0015 
0016 fprintf("Running Algorithm ");
0017 
0018 % Get the algorithm results:
0019 result = hrvDetectShort( params, proportion );
0020 R_locs = result.R_locs;
0021 fs = result.fs;
0022 maxDeviation = fs / 40;  % Quarter of a second is max deviation
0023 
0024 
0025 fprintf("Getting Valid Data ");
0026 
0027 % Get the official annotations:
0028 [R_locs_valid, ecg_sig] = getOfficialResultsShort( record, proportion );
0029 time = 0:(1/fs):((length(ecg_sig)-1)/fs);
0030 
0031 index = 1;
0032 n_missedBeats = 0;
0033 n_extraBeats = 0;
0034 n_acceptable = 0;
0035 jitter = [];
0036 
0037 fprintf("Starting Comparison ");
0038 
0039 for i=1:length(R_locs_valid)
0040     matched = false;
0041     validBeatPos = R_locs_valid(i);
0042     while(~matched)
0043         % Overflow, we continue
0044         if(index > length(R_locs))
0045             n_missedBeats = n_missedBeats + 1;
0046             matched = true;
0047             break;
0048         end
0049         calculatedBeatPos = R_locs(index);
0050         deviation = abs(validBeatPos - calculatedBeatPos);
0051         if(deviation < maxDeviation)
0052             n_acceptable = n_acceptable + 1;
0053             jitter(n_acceptable) = deviation;
0054             index = index + 1;
0055             matched = true;
0056         elseif(calculatedBeatPos < validBeatPos)
0057             n_extraBeats = n_extraBeats + 1;
0058             index = index + 1;
0059         else
0060             n_missedBeats = n_missedBeats + 1;
0061             matched = true;
0062         end
0063     end
0064 end
0065 
0066 timeMinutes = time./60;
0067 
0068 % Make the interval array with the Official beats
0069 interval_valid = diff(R_locs_valid);
0070 BPM_valid = 60*fs./(interval_valid);
0071 interval_locs_valid = R_locs_valid(1:end-1);
0072 interpolated = interp1(R_locs,result.tachogram,1:length(ecg_sig),'spline');
0073 
0074 
0075 
0076 figure;
0077 bx1 = subplot(2,2,1);
0078 hold on;
0079 plot (timeMinutes,ecg_sig);
0080 plot (timeMinutes(R_locs),ecg_sig(R_locs),'rv','MarkerFaceColor','r');
0081 legend('ECG','R - Detected', 'R - Valid');
0082 title('ECG Signal with Computed R points');
0083 xlabel('Time in Minutes');
0084 ylabel('Amplitude');
0085 ylim([-1 2]);
0086 
0087 bx2 = subplot(2,2,3);
0088 hold on;
0089 plot (timeMinutes,ecg_sig);
0090 plot (timeMinutes(R_locs_valid),ecg_sig(R_locs_valid),'bv','MarkerFaceColor','b');
0091 legend('ECG', 'R - Valid');
0092 title('ECG Signal with Valid R points');
0093 xlabel('Time in Minutes');
0094 ylabel('Amplitude');
0095 ylim([-1 2]);
0096 
0097 
0098 %Make the same length (the last beat is discarded in our algo)
0099 if(length(result.tachogram) == length(R_locs) - 1)
0100     result.tachogram(length(result.tachogram) + 1) = result.tachogram(length(result.tachogram));
0101 end
0102 
0103 bx3 = subplot(2,2,2);
0104 hold on;
0105 plot (timeMinutes(result.R_locs),result.tachogram);
0106 scatter (timeMinutes(result.noisyIntervals),interpolated(result.noisyIntervals), ...
0107         'MarkerEdgeColor','r',...
0108         'MarkerFaceColor','r',...
0109         'LineWidth',0.1);
0110 legend('Tachogram', 'Locations where collected data was deemed noisy');
0111 title('Tachogram');
0112 xlabel('Time in Minutes');
0113 ylabel('BPM');
0114 ylim([100 200]);
0115 
0116 
0117 bx4 = subplot(2,2,4);
0118 hold on;
0119 plot (timeMinutes(interval_locs_valid),BPM_valid);
0120 legend('Tachogram');
0121 title('Expected Tachogram');
0122 xlabel('Time in Minutes');
0123 ylabel('BPM');
0124 ylim([100 200]);
0125 linkaxes([bx1,bx2],'xy');
0126 linkaxes([bx3,bx4],'xy');
0127 linkaxes([bx1,bx2,bx3,bx4],'x');
0128 
0129 
0130 averageDeviation = sum(jitter)/length(jitter);
0131 figure;
0132 hist(jitter);

Generated on Thu 15-Mar-2018 13:53:54 by m2html © 2005