?? ecgdemo.m
字號:
% ECGDEMO ECG PROCESSING DEMONSTRATION - R-PEAKS DETECTION
%
% To run the demo successfully "ecgdemomex.dll", ecgdemodata1.mat"
% and "ecgdemodata2" should be in MatLab's "work"
% directory
% We are processing two data samples to demonstrate two different situations
for demo = 1:2:3
% Clear our variables
clear ecg samplingrate corrected filtered1 peaks1 filtered2 peaks2 fresult
% Load data sample
switch(demo)
case 1,
plotname = 'Sample 1';
load ecgdemodata1;
case 3,
plotname = 'Sample 2';
load ecgdemodata2;
end
% Remove lower frequencies
fresult=fft(ecg);
fresult(1 : round(length(fresult)*5/samplingrate))=0;
fresult(end - round(length(fresult)*5/samplingrate) : end)=0;
corrected=real(ifft(fresult));
% Process data and get result
[filtered1, peaks1, filtered2, peaks2] = ecgdemomex(corrected, samplingrate);
% Create figure - stages of processing
figure(demo); set(demo, 'Name', strcat(plotname, ' - Processing Stages'));
% Original input ECG data
subplot(3, 2, 1); plot((ecg-min(ecg))/(max(ecg)-min(ecg)));
title('\bf1. Original ECG'); ylim([-0.2 1.2]);
% ECG with removed low-frequency component
subplot(3, 2, 2); plot((corrected-min(corrected))/(max(corrected)-min(corrected)));
title('\bf2. FFT Filtered ECG'); ylim([-0.2 1.2]);
% Filtered ECG (1-st pass) - filter has default window size
subplot(3, 2, 3); stem((filtered1-min(filtered1))/(max(filtered1)-min(filtered1)));
title('\bf3. Filtered ECG - 1^{st} Pass'); ylim([0 1.4]);
% Detected peaks in filtered ECG
subplot(3, 2, 4); stem(peaks1);
title('\bf4. Detected Peaks'); ylim([0 1.4]);
% Filtered ECG (2-d pass) - now filter has optimized window size
subplot(3, 2, 5); stem((filtered2-min(filtered2))/(max(filtered2)-min(filtered2)));
title('\bf5. Filtered ECG - 2^d Pass'); ylim([0 1.4]);
% Detected peaks - final result
subplot(3, 2, 6); stem(peaks2);
title('\bf6. Detected Peaks - Finally'); ylim([0 1.4]);
% Create figure - result
figure(demo+1); set(demo+1, 'Name', strcat(plotname, ' - Result'));
% Plotting ECG in green
plot((ecg-min(ecg))/(max(ecg)-min(ecg)), '-g'); title('\bf Comparative ECG R-Peak Detection Plot');
% Show peaks in the same picture
hold on
% Stemming peaks in dashed black
stem(peaks2.*((ecg-min(ecg))/(max(ecg)-min(ecg)))', ':k');
% Hold off the figure
hold off
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -