identify q, r, s peaks of a ecg in matlab

You can identify the q, r, s peaks of an ECG signal in MATLAB using the findpeaks function from the Signal Processing Toolbox. Here is an example code snippet to do this:

main.m
% Assuming you have loaded your ECG signal in a variable called ecg

% Find R peaks
[~,r_locs] = findpeaks(ecg, 'MinPeakHeight', max(ecg)*0.6, 'MinPeakDistance', 0.2*fs); % adjust thresholds as needed

% Find Q and S peaks by searching before and after each R peak
q_locs = zeros(size(r_locs));
s_locs = zeros(size(r_locs));

for i = 1:length(r_locs)
    [~,q_loc] = findpeaks(-ecg(max(1, r_locs(i)-0.08*fs):r_locs(i)), 'MinPeakDistance', 0.02*fs); % adjust thresholds as needed
    [~,s_loc] = findpeaks(-ecg(r_locs(i):min(length(ecg), r_locs(i)+0.08*fs)), 'MinPeakDistance', 0.02*fs); % adjust thresholds as needed

    q_locs(i) = q_loc + r_locs(i) - 0.08*fs;
    s_locs(i) = s_loc + r_locs(i) - 1;
end

% Plot ECG signal with identified QRS peaks
figure;
plot(ecg);
hold on;
plot(r_locs, ecg(r_locs), 'ro', 'MarkerSize', 10);
plot(q_locs, ecg(q_locs), 'g*', 'MarkerSize', 10);
plot(s_locs, ecg(s_locs), 'b*', 'MarkerSize', 10);
legend('ECG Signal', 'R Peaks', 'Q Peaks', 'S Peaks');
xlabel('Samples');
ylabel('Amplitude');
title('ECG Signal with QRS Peaks');
1063 chars
29 lines

In this code, ecg is your ECG signal, and fs is the sampling frequency of the signal in Hz. Adjust the threshold values in findpeaks to suit your specific ECG signal. Note that this is a basic approach and may need further refinement based on the characteristics of your ECG signal.

related categories

gistlibby LogSnag