- https://www.mathworks.com/help/matlab/ref/fopen.html
- https://www.mathworks.com/help/matlab/ref/fgetl.html
- https://www.mathworks.com/help/matlab/date-and-time-operations.html
How can I plot BPM over time using a UTC start time in an epoch.txt file?
1 view (last 30 days)
Show older comments
At the moment, I have BPM plotted against the duration of my ECG device's recording (~90 mins). What I'd like to do is to use a start time I have in UTC from an epoch.txt file outputted by the ECG device (e.g 07:55:14) to be able to plot BPM across the actual time during the session (e.g 07:55:14 - 09:25:14). I'd like to do this so I can identify the time in UTC of peaks in BPM and to average BPM during a period of the session I only readily know in UTC.
I realise I could work out the actual time of a peak by using the time elapsed on my current plots along with the start time in the epoch.txt files but I have lots of ECG data across many sessions which vary in duration with different start times so I'd like to save myself some grief!
I would also like to ultimately automate this process so any help or tips as to how to automate this into a script would be very appreciated too.
Thank you!
0 Comments
Answers (1)
VINAYAK LUHA
on 28 Nov 2023
Edited: VINAYAK LUHA
on 28 Nov 2023
Hi Molly,
I understand that, you have multiple 90 minutes BPM data and their initial UTC start time stored in a file named "epoch.txt". Your objective is to generate a plot depicting BPM against UTC time.
Here is code snippet to convert the time axis of your BPM plot to actual UTC time-
% Read the start time and date from the epoch.txt file
fileID = fopen('epoch.txt', 'r');
startDateTimeStr = fgetl(fileID);
fclose(fileID);
% Convert start time and date to MATLAB datetime format
startDateTime = datetime(startDateTimeStr, 'InputFormat', 'dd/MM/yyy HH:mm:ss');
% Duration of the ECG recording (e.g., 90 minutes)
duration = minutes(90);
% Calculate end time
endDateTime = startDateTime + duration;
% Create a time vector representing the actual UTC time during the session
timeVector = startDateTime:seconds(90*60/5399):endDateTime; % Adjust the time step to match the size of the data
% Plot BPM data against timeVector
plot(timeVector, bpmData);
xlabel('Time (UTC)');
ylabel('BPM');
title('ECG BPM across the session');
Further, you can automate this process for multiple sessions by encapsulating the code in a function and looping through the session files.
Additionally, you can refer to the following documentations for more details about the function used above -
Hope this resolves your query.
Regards,
Vinayak Luha
0 Comments
See Also
Categories
Find more on Test and Measurement in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!