Marking peaks in an ECG signal

2019-09-18 07:13发布

问题:

I am working on ECG signal processing. I am using the MIT-BIH Arrhythmia database found here.

After loading the signal, I marked the R peaks correctly. Then I was trying to extract QRS complex, but I couldn't.

I want to make marks on peaks like in this image:

. . . . . . .

Here is my code:

 clear all;
    clc;
    close all;
    load ('G:\1.Thesis\data set\100\100m')
    %% Remove base & gain
    %%figure (1)
    val = (val - 1024)/200;    
    ECGsignal = val(1,1:3600);  
    SAMPLES2READ = 3600;       
    time = (0:length(ECGsignal)-1)/SAMPLES2READ; 
    plot(time,ECGsignal); title('ECG Signal')

    %% Finding Maxima or Peaks
    figure (2)
    [pks,locs] = findpeaks(ECGsignal);
    plot(time,ECGsignal,time(locs),pks,'rv','MarkerFaceColor','r'); grid on
    xlabel('Time'); ylabel('Voltage')
    title('Find All Peaks'); legend('ECG Signal','Peaks')

    %% Measuring Distance Between Peaks
    %Find R peaks
    figure (3)
    [pks_Rwave,locs_Rwave] = findpeaks(ECGsignal,'MinPeakHeight',0.5,'MinPeakDistance',200);
    fprintf('locs_Rwave = \n');
    disp (locs_Rwave)
    pks_Rwave1 = pks_Rwave*100;
    fprintf('pks_Rwave = \n');
    disp (pks_Rwave1)
    plot(time,ECGsignal,time(locs_Rwave),pks_Rwave,'rv','MarkerFaceColor','r'); grid on
    xlabel('Time'); ylabel('Voltage');
    title('Find Prominent Peaks');

%% Q wave     
    ECG_inverted = -ECGsignal;
    [pks_Qwave,locs_Qwave] = findpeaks(ECG_inverted,'MinPeakHeight',0.2,'MinPeakDistance',200);
    k = 1:length(ECGsignal);
    figure(5)
    hold on 
    plot(k,ECGsignal);
    plot(locs_Qwave,ECGsignal(locs_Qwave),'rs','MarkerFaceColor','g');
    plot(locs_Rwave,ECGsignal(locs_Rwave),'rv','MarkerFaceColor','r');
    grid on
    axis([50 400 -0.8 2]); 
    legend('ECG signal','Q-wave','R-wave','S-wave');
    xlabel('Samples'); ylabel('Voltage(mV)')
    title('Q-wave , R-wave and S-wave');

回答1:

I'm not sure I understood you correctly, but here's one way to get markings like in the chart you showed:

rng(41826521);
sig = 1.6*randn(100,1); % Y-vector
smpl_id = 1:numel(sig); % X-vector; Or you can use find(idx) instead of smpl_id(idx).

figure(); plot(sig); grid on; hold on; grid minor;
idx =  2   < sig;             plot(smpl_id(idx),sig(idx),'rv','MarkerFaceColor','r');
idx = -2.5 < sig & sig < -2;  plot(smpl_id(idx),sig(idx),'rs','MarkerFaceColor','g');
idx = sig < -2.5;             plot(smpl_id(idx),sig(idx),'rs','MarkerFaceColor','b');

This gives: