I would like to calculate heart rate by determining threshold for amplitude

2 次查看(过去 30 天)
I'd like to determing the QRS complex and draw rectange pulse and calculating hart rate
this code is what i write,
ecg =importdata ('ecg.txt');
sig=ecg(1:1400);
th=0.5;
count=0;
while (ecg> th)
count=count+1
end
  3 个评论

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2023-3-8
Try this:
% Optional initialization steps
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 18;
ecg = importdata ('ecg.txt');
% Plot it
hFig = figure('Name', "Mary's ECG Signal", 'NumberTitle','off');
plot(ecg, 'b-', 'LineWidth', 2);
grid on;
xlabel('Sample Number', 'FontSize',fontSize);
ylabel('Signal Value', 'FontSize',fontSize)
title("Mary's ECG Signal", 'FontSize',fontSize)
% Define threshold
threshold = 0.5;
% Draw red lines across the thresholds.
yline(threshold, 'Color','r', 'LineWidth', 2);
yline(-threshold, 'Color','r', 'LineWidth', 2);
% Detect samples above threshold
inAPositivePeak = ecg > threshold;
% Count the number of positive peaks using bwlabel() in the Image Processing Toolbox.
[~, numPositivePeaks] = bwlabel(inAPositivePeak)
% Detect samples below a threshold
inANegativePeak = ecg < -threshold;
% Count the number of positive peaks using bwlabel() in the Image Processing Toolbox.
[~, numNegativePeaks] = bwlabel(inANegativePeak)
numPositivePeaks =
67
numNegativePeaks =
67

类别

Help CenterFile Exchange 中查找有关 Signal Processing Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by