Identifying PTT of ECG and PPG signals
I’m trying to detect the pulse transit time between ecg and ppg signals. I have the ecg and ppg signals filtered and normalised around 1. Here is my code so far
clc;
clear;
close all;
All_Data = {}; % set up cell array for all workbook data
Plotted_Data_ECG_PPG = {}; % Set up cell array for ECG and PPG plotted data
% Parameters for moving average filter
windowSize = 2;
ecgThreshold = 0.375;
ppgThreshold = 0.1;
for i = 1:1 % set up loop to run for 11 iterations (no. of workbooks)
filename = sprintf(‘%03d.xlsx’, i); % set up each filename 001-011 to be read on each iteration
opt = detectImportOptions(filename); % import data from filename
sheets = sheetnames(filename); % retrieve names of sheets
for j = 1:numel(sheets) % iterate over each sheet within a workbook
tBC = readtable(filename, opt, ‘Sheet’, sheets{j}); % extract sheets from workbooks
Time_Data = tBC{:, ‘Var4’}; % extract time data from column 4
% Remove invalid rows from table (corresponding to NaN’s in Time_Data
rows2delete = isnan(Time_Data);
tBC(rows2delete,:) = [];
Time_Data = tBC{:, ‘Var4’}; % extract time data from column 4
% Fit a polynomial p of 1st degree to the first points of each staircase (top curve)
xx = (1:numel(Time_Data))’;
dTime_Data = diff(Time_Data);
ind = 1+find(dTime_Data>max(dTime_Data)/100);
ind = ind(2:end); % in some cases the first point is too much off trend and we prefer not to use it.
p = polyfit(xx(ind),Time_Data(ind),1);
% Evaluate the fitted polynomial p and plot:
Time_Data_new = polyval(p,xx);
% % debug plots (to double check)
% figure(j)
% plot(xx,Time_Data,xx,Time_Data_new);
ECG_Data = tBC{:, ‘Var6’}; % extract ECG data from column 6
PPG_Data = tBC{:, ‘Var8’}; % extract PPG data from column 8
SYS_Data = tBC{:, ‘Var10’}; % extract reference systolic pressure data from column 10
DIA_Data = tBC{:, ‘Var12’}; % extract reference diastolic pressure data from column 12
% Filter ECG and PPG data
ECG_Data_smoothed = movmean(ECG_Data, windowSize);
PPG_Data_smoothed = movmean(PPG_Data, windowSize);
% Normalize ECG and PPG data around 0
ECG_Data_normalized = ECG_Data_smoothed – mean(ECG_Data_smoothed);
PPG_Data_normalized = PPG_Data_smoothed – mean(PPG_Data_smoothed);
% Fnd peaks for ECG and PPG data above thresholds
[ecgPeaks, ecgPeakIdx] = findpeaks(ECG_Data_normalized, ‘MinPeakHeight’, ecgThreshold);
[ppgPeaks, ppgPeakIdx] = findpeaks(PPG_Data_normalized, ‘MinPeakHeight’, ppgThreshold);
Time_Formatted = datestr(Time_Data_new, ‘HH:MM:SS:fff’); % Format time data with milliseconds
t = datetime(Time_Formatted,’InputFormat’,’HH:mm:ss:SSS’);
t.Format = ‘HH:mm:ss.SSS’;
Date_Number = datenum(t);
t_plot = datetime(Date_Number, ‘ConvertFrom’, ‘datenum’);
t_plot.Format = ‘HH:mm:ss.SSS’;
%Plotting ECG and PPG Data on the same graph
figure;
plot(t_plot,ECG_Data_normalized, ‘b’, t_plot(ecgPeakIdx), ecgPeaks, ‘ro’, …
t_plot, PPG_Data_normalized, ‘r’, t_plot(ppgPeakIdx), ppgPeaks, ‘go’);
xlabel(‘time’);
ylabel(‘Normalized Data’);
title([‘ECG and PPG Data vs Time – Workbook ‘, num2str(i), ‘sheet’, sheets{j}]);
legend(‘ECG’, ‘ecgPeaks’, ‘PPG’, ‘PPG Peaks’);
% Store the figure handle for later reference if needed
Plotted_Data_ECG_PPG{i,j} = gcf;
Time_Data_Cell = num2cell(Time_Data);
ECG_Data_Cell = num2cell(ECG_Data);
PPG_Data_Cell = num2cell(PPG_Data);
SYS_Data_Cell = num2cell(SYS_Data);
DIA_Data_Cell = num2cell(DIA_Data);
% Place the formatted time data and numerical data in the first row
All_Data{i,j} = [cellstr(Time_Formatted), ECG_Data_Cell, PPG_Data_Cell, SYS_Data_Cell, DIA_Data_Cell];
end
endI’m trying to detect the pulse transit time between ecg and ppg signals. I have the ecg and ppg signals filtered and normalised around 1. Here is my code so far
clc;
clear;
close all;
All_Data = {}; % set up cell array for all workbook data
Plotted_Data_ECG_PPG = {}; % Set up cell array for ECG and PPG plotted data
% Parameters for moving average filter
windowSize = 2;
ecgThreshold = 0.375;
ppgThreshold = 0.1;
for i = 1:1 % set up loop to run for 11 iterations (no. of workbooks)
filename = sprintf(‘%03d.xlsx’, i); % set up each filename 001-011 to be read on each iteration
opt = detectImportOptions(filename); % import data from filename
sheets = sheetnames(filename); % retrieve names of sheets
for j = 1:numel(sheets) % iterate over each sheet within a workbook
tBC = readtable(filename, opt, ‘Sheet’, sheets{j}); % extract sheets from workbooks
Time_Data = tBC{:, ‘Var4’}; % extract time data from column 4
% Remove invalid rows from table (corresponding to NaN’s in Time_Data
rows2delete = isnan(Time_Data);
tBC(rows2delete,:) = [];
Time_Data = tBC{:, ‘Var4’}; % extract time data from column 4
% Fit a polynomial p of 1st degree to the first points of each staircase (top curve)
xx = (1:numel(Time_Data))’;
dTime_Data = diff(Time_Data);
ind = 1+find(dTime_Data>max(dTime_Data)/100);
ind = ind(2:end); % in some cases the first point is too much off trend and we prefer not to use it.
p = polyfit(xx(ind),Time_Data(ind),1);
% Evaluate the fitted polynomial p and plot:
Time_Data_new = polyval(p,xx);
% % debug plots (to double check)
% figure(j)
% plot(xx,Time_Data,xx,Time_Data_new);
ECG_Data = tBC{:, ‘Var6’}; % extract ECG data from column 6
PPG_Data = tBC{:, ‘Var8’}; % extract PPG data from column 8
SYS_Data = tBC{:, ‘Var10’}; % extract reference systolic pressure data from column 10
DIA_Data = tBC{:, ‘Var12’}; % extract reference diastolic pressure data from column 12
% Filter ECG and PPG data
ECG_Data_smoothed = movmean(ECG_Data, windowSize);
PPG_Data_smoothed = movmean(PPG_Data, windowSize);
% Normalize ECG and PPG data around 0
ECG_Data_normalized = ECG_Data_smoothed – mean(ECG_Data_smoothed);
PPG_Data_normalized = PPG_Data_smoothed – mean(PPG_Data_smoothed);
% Fnd peaks for ECG and PPG data above thresholds
[ecgPeaks, ecgPeakIdx] = findpeaks(ECG_Data_normalized, ‘MinPeakHeight’, ecgThreshold);
[ppgPeaks, ppgPeakIdx] = findpeaks(PPG_Data_normalized, ‘MinPeakHeight’, ppgThreshold);
Time_Formatted = datestr(Time_Data_new, ‘HH:MM:SS:fff’); % Format time data with milliseconds
t = datetime(Time_Formatted,’InputFormat’,’HH:mm:ss:SSS’);
t.Format = ‘HH:mm:ss.SSS’;
Date_Number = datenum(t);
t_plot = datetime(Date_Number, ‘ConvertFrom’, ‘datenum’);
t_plot.Format = ‘HH:mm:ss.SSS’;
%Plotting ECG and PPG Data on the same graph
figure;
plot(t_plot,ECG_Data_normalized, ‘b’, t_plot(ecgPeakIdx), ecgPeaks, ‘ro’, …
t_plot, PPG_Data_normalized, ‘r’, t_plot(ppgPeakIdx), ppgPeaks, ‘go’);
xlabel(‘time’);
ylabel(‘Normalized Data’);
title([‘ECG and PPG Data vs Time – Workbook ‘, num2str(i), ‘sheet’, sheets{j}]);
legend(‘ECG’, ‘ecgPeaks’, ‘PPG’, ‘PPG Peaks’);
% Store the figure handle for later reference if needed
Plotted_Data_ECG_PPG{i,j} = gcf;
Time_Data_Cell = num2cell(Time_Data);
ECG_Data_Cell = num2cell(ECG_Data);
PPG_Data_Cell = num2cell(PPG_Data);
SYS_Data_Cell = num2cell(SYS_Data);
DIA_Data_Cell = num2cell(DIA_Data);
% Place the formatted time data and numerical data in the first row
All_Data{i,j} = [cellstr(Time_Formatted), ECG_Data_Cell, PPG_Data_Cell, SYS_Data_Cell, DIA_Data_Cell];
end
end I’m trying to detect the pulse transit time between ecg and ppg signals. I have the ecg and ppg signals filtered and normalised around 1. Here is my code so far
clc;
clear;
close all;
All_Data = {}; % set up cell array for all workbook data
Plotted_Data_ECG_PPG = {}; % Set up cell array for ECG and PPG plotted data
% Parameters for moving average filter
windowSize = 2;
ecgThreshold = 0.375;
ppgThreshold = 0.1;
for i = 1:1 % set up loop to run for 11 iterations (no. of workbooks)
filename = sprintf(‘%03d.xlsx’, i); % set up each filename 001-011 to be read on each iteration
opt = detectImportOptions(filename); % import data from filename
sheets = sheetnames(filename); % retrieve names of sheets
for j = 1:numel(sheets) % iterate over each sheet within a workbook
tBC = readtable(filename, opt, ‘Sheet’, sheets{j}); % extract sheets from workbooks
Time_Data = tBC{:, ‘Var4’}; % extract time data from column 4
% Remove invalid rows from table (corresponding to NaN’s in Time_Data
rows2delete = isnan(Time_Data);
tBC(rows2delete,:) = [];
Time_Data = tBC{:, ‘Var4’}; % extract time data from column 4
% Fit a polynomial p of 1st degree to the first points of each staircase (top curve)
xx = (1:numel(Time_Data))’;
dTime_Data = diff(Time_Data);
ind = 1+find(dTime_Data>max(dTime_Data)/100);
ind = ind(2:end); % in some cases the first point is too much off trend and we prefer not to use it.
p = polyfit(xx(ind),Time_Data(ind),1);
% Evaluate the fitted polynomial p and plot:
Time_Data_new = polyval(p,xx);
% % debug plots (to double check)
% figure(j)
% plot(xx,Time_Data,xx,Time_Data_new);
ECG_Data = tBC{:, ‘Var6’}; % extract ECG data from column 6
PPG_Data = tBC{:, ‘Var8’}; % extract PPG data from column 8
SYS_Data = tBC{:, ‘Var10’}; % extract reference systolic pressure data from column 10
DIA_Data = tBC{:, ‘Var12’}; % extract reference diastolic pressure data from column 12
% Filter ECG and PPG data
ECG_Data_smoothed = movmean(ECG_Data, windowSize);
PPG_Data_smoothed = movmean(PPG_Data, windowSize);
% Normalize ECG and PPG data around 0
ECG_Data_normalized = ECG_Data_smoothed – mean(ECG_Data_smoothed);
PPG_Data_normalized = PPG_Data_smoothed – mean(PPG_Data_smoothed);
% Fnd peaks for ECG and PPG data above thresholds
[ecgPeaks, ecgPeakIdx] = findpeaks(ECG_Data_normalized, ‘MinPeakHeight’, ecgThreshold);
[ppgPeaks, ppgPeakIdx] = findpeaks(PPG_Data_normalized, ‘MinPeakHeight’, ppgThreshold);
Time_Formatted = datestr(Time_Data_new, ‘HH:MM:SS:fff’); % Format time data with milliseconds
t = datetime(Time_Formatted,’InputFormat’,’HH:mm:ss:SSS’);
t.Format = ‘HH:mm:ss.SSS’;
Date_Number = datenum(t);
t_plot = datetime(Date_Number, ‘ConvertFrom’, ‘datenum’);
t_plot.Format = ‘HH:mm:ss.SSS’;
%Plotting ECG and PPG Data on the same graph
figure;
plot(t_plot,ECG_Data_normalized, ‘b’, t_plot(ecgPeakIdx), ecgPeaks, ‘ro’, …
t_plot, PPG_Data_normalized, ‘r’, t_plot(ppgPeakIdx), ppgPeaks, ‘go’);
xlabel(‘time’);
ylabel(‘Normalized Data’);
title([‘ECG and PPG Data vs Time – Workbook ‘, num2str(i), ‘sheet’, sheets{j}]);
legend(‘ECG’, ‘ecgPeaks’, ‘PPG’, ‘PPG Peaks’);
% Store the figure handle for later reference if needed
Plotted_Data_ECG_PPG{i,j} = gcf;
Time_Data_Cell = num2cell(Time_Data);
ECG_Data_Cell = num2cell(ECG_Data);
PPG_Data_Cell = num2cell(PPG_Data);
SYS_Data_Cell = num2cell(SYS_Data);
DIA_Data_Cell = num2cell(DIA_Data);
% Place the formatted time data and numerical data in the first row
All_Data{i,j} = [cellstr(Time_Formatted), ECG_Data_Cell, PPG_Data_Cell, SYS_Data_Cell, DIA_Data_Cell];
end
end ptt, blood pressure MATLAB Answers — New Questions