Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use MATLAB to automatically compute your heartrate in beats per minute. I am usi

ID: 2085934 • Letter: U

Question

Use MATLAB to automatically compute your heartrate in beats per minute. I am using an analog discovery and a heart rate monitor to get my data of heart rate. I now need to use MATLAB to compute my heartrate based off that waveform.

My current code to get the heartrate data is:

% Determine the Device ID (Digilent Analog Discovery)

fprintf('Please wait while the device is being configured!! ');

daq.getDevices; % May take upto 30 sec

% Begin Session

s = daq.createSession('digilent');

% Add Digilent Analog Input Channel(1: orange): Output from HR circuit

ch1 = addAnalogInputChannel(s, 'AD1', 1, 'Voltage');

% Adding Digilent Analog Output Channel(W1 yellow): To power the HR circuit

ch2 = addAnalogOutputChannel(s, 'AD1', '1', 'Voltage');

% Select Session and channel properties

Fs = 10e3; % Define Sample rate (Hz)

s.Rate = Fs; % Set device sample rate (Hz)

% Define Output Waveform: +5V used to power the Heart rate monitor

duration = 10; % Duration of Data collection (sec)

t = (1:(duration*Fs))/Fs; % Time vector

len = length(t); % Length of time vector

output = 5*ones([len 1]); % +5V signal to power HR sensor

disp(['Please wait for ', num2str(duration),' seconds: Data Acquisition in Progress!!!']);

% Output Waveform to Device

queueOutputData(s,output);

[data, timestamps, triggerTime] = startForeground(s);

% Plot the Results

plot(timestamps, data);

xlabel('Time (seconds)');

ylabel('Voltage (Volts)');

title(['Heart Rate of Stephen Bruder Collected on: ' datestr(triggerTime)])

grid

Explanation / Answer

close all,
clear all,
clc,

%{
ProjectPath=pwd;
ECGPath = strcat(ProjectPath,'ECG_N1.txt');

A=[];
fpt_1 = fopen(ECGPath,'r');
A = fscanf(fpt_1,'%g');
x = size(A);
No_of_Data = x(1,1);
fclose(fpt_1);

plot(A);
length(A);
%}
sample_freq = Fs;
cof=cwt(data,3,'coif1');

% Detect R-Peak
cofsq=cof.^2;
threshold=mean(cofsq);
peak=0;
cofsq(1)=0;
cofsq(end)=0;
ntime=6*sample_freq;
for i=1:ntime
if cofsq(i) >=threshold
peak=peak+1;
end
end

% Beats per minute
beats= peak   

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote