Averaging data from seconds to three seconds because of different time variables

3 views (last 30 days)
I have measured data with two different devices.
One device (Garmin device)measured data every second for about 20 minutes, so I have data with a 1207x1 format.
The other device (Cosmed device) measured data every 3 seconds (so 1, 4, 7, 10, etc.) also for about 20 minutes, so this results in a 470x1 format.
I want to compare variables measured from these devices, but for a reliable analysis I have to have the same time dimension (either per 1 or 3 seconds).
The most simple option would be per 3 seconds, but in order to do that I have to ''average'' the data from the Garmin for every 3 seconds.
What is the simplest way to achieve this?
Thanks in advance!
  8 Comments
Stephen23
Stephen23 on 21 Aug 2023
"but do know that I already transferred the timestamps into seconds in my script."
Please provide the original, complete timestamps.

Sign in to comment.

Accepted Answer

Torsten
Torsten on 21 Aug 2023
I'd repeat the data for 3 seconds three times. This does not manipulate your data with interpolation or averaging.
  1 Comment
Ilse Frans
Ilse Frans on 30 Aug 2023
You mean that I wouldn't need the functions ''retime'' and/or ''synchronize'' then?
And (I'm sorry, I'm still new at using Matlab) how would I write the code to achieve that?

Sign in to comment.

More Answers (2)

Star Strider
Star Strider on 21 Aug 2023
Edited: Star Strider on 21 Aug 2023
I am not certain that it is possible, however if it is, some combination of retime and synchronize could work.
EDIT — (21 Aug 2023 at 12:41)
Please provide the complete ‘garmin_timestamp’ with all the fields. Only having the seconds values is not going to work.
The ‘cosmed’ times appear to have only the minutes and seconds. It would help to have the hours aa well, if that is possible. (We can assume for the time being that they are the same days.)
type('garmin_cosmed_marc.m')
clear all; close all; garmin_alldata = readtable('Pilot_Marc Garmin.csv'); cosmed_alldata = readtable('Cosmed_Marc 27 juni.csv'); % [Belangrijke informatie] % De huidige data is gemeten bij een proefpersoon met de volgende gegevens: gender = 0; % Waarbij 0 = M, 1 = V height = 1.85; % in meter weight = 103; % in kg age = 46; % in jaar, geboortedatum = 31/03/1977 % [Garmin variabelen] garmin_cadance = garmin_alldata{:,2}; % cadans in aantal stappen/minuut garmin_distance = garmin_alldata{:,3}; % afstand in meter garmin_speed = garmin_alldata{:,4}; % snelheid in meter/seconde garmin_HR = garmin_alldata{:,6}; % in bpm garmin_power = garmin_alldata{:,7}; % vermogen in Watt garmin_steplength_mm = garmin_alldata{:,11}; % staplengte in mm garmin_steplength = garmin_steplength_mm/1000; % staplengte in m garmin_timestamp = garmin_alldata{:,12}; % tijdsverloop in yyyy:mm:dd hh:mm:ss garmin_t = time2num(garmin_timestamp); garmin_oscillation_cm = garmin_alldata{:,14}; % verticale oscillatie in cm garmin_oscillation = garmin_oscillation_cm/100; % verticale oscillatie in m garmin_resprate = garmin_alldata{:,17}; garmin_resprate_real = garmin_resprate/1000; % respiration rate in brpm % [Cosmed variabelen] cosmed_t = cosmed_alldata{:,10}; % tijdsduur in seconden cosmed_t = cosmed_t(4:end); % [cosmed_t van mm:ss omzetten naar seconden en double value] % Initialize an array to store the converted values cosmed_seconds = zeros(size(cosmed_t)); % Iterate over each timestamp and convert it to seconds for i = 1:numel(cosmed_t) % Split the timestamp string into minutes and seconds time_parts = split(cosmed_t{i}, ':'); % Convert minutes and seconds to double values minutes = str2double(time_parts{1}); seconds = str2double(time_parts{2}); % Calculate the total time in seconds total_seconds = minutes * 60 + seconds; % Store the result in the array cosmed_seconds(i) = total_seconds; end cosmed_Rf = cosmed_alldata{:,11}; % ademhalingsfrequentie per minuut cosmed_VE = cosmed_alldata{:,13}; % ademminuutvolume in L/min cosmed_VO2 = cosmed_alldata{:,15}; % zuurstofopname in mL/min cosmed_VCO2 = cosmed_alldata{:,16}; % kooldioxide uitademing in mL/min cosmed_RQ = cosmed_alldata{:,17}; % respiratie quotiënt / RER cosmed_VO2kg = cosmed_alldata{:,22}; % zuurstofopname in mL/min per kg lichaamsgewicht cosmed_METs = cosmed_alldata{:,23}; % metabole quotiënt cosmed_HR = cosmed_alldata{:,24}; % hartslag in bpm cosmed_cadance = cosmed_alldata{:,77}; % cadans in stappen/min cosmed_HRR = cosmed_alldata{:,82}; % heart rate reserve in bpm cosmed_EEm = cosmed_alldata{:,45}; % energieverbruik in kcal/min cosmed_prot_day = cosmed_alldata{:,48}; % eiwitverbruik in kcal/dag cosmed_prot = cosmed_prot_day*0.00069; % eiwitverbruik in kcal/min cosmed_prot_percent = cosmed_alldata{:,51}; % percentage eiwitten cosmed_fat_day = cosmed_alldata{:,49}; % vetverbruk in kcal/dag cosmed_fat = cosmed_fat_day*0.00069; % vetverbruik in kcal/min cosmed_fat_percent = cosmed_alldata{:,52}; % percentage vetten cosmed_CHO_day = cosmed_alldata{:,50}; % CHO-verbruik in kcal/dag cosmed_CHO = cosmed_CHO_day*0.00069; % CHO-verbruik in kcal/min cosmed_CHO_percent = cosmed_alldata{:,53}; % percentage CHO % [EE_Garmin (in kcal/min) op basis van HR] garmin_HR_min = min(garmin_HR); garmin_HR_max = max(garmin_HR); garmin_HRR = ((garmin_HR-garmin_HR_min)./(garmin_HR_max-garmin_HR))*100; garmin_EE_HR = 1.044 + (0.025*garmin_HRR) + (1.0108*weight) + (0.001177*garmin_HRR*weight); %in kcal/min % [EE_Garmin (in kcal/min) op basis van GPS, Pandolf-Santee] carried_load = 0.9; % in kg terrain_factor = 1; % op loopband grade(:,1:240) = 0; grade(:,241:480) = 0; grade(:,481:721) = 25; grade(:,722:962) = 10; grade(:,963:1207) = 0; speed(:,1:240) = 1.39; speed(:,241:480) = 0.83; speed(:,481:721) = 0.83; speed(:,722:962) = 1.67; speed(:,963:1207) = 0.83; garmin_EE_GPS_W = (1.5.*weight) + (2.0.*(weight+carried_load)).*((carried_load/weight).^2) + (terrain_factor.*(weight/carried_load)).*(1.5.*speed.^2+0.35.*speed.*grade); garmin_EE_GPS_W = garmin_EE_GPS_W.'; garmin_EE_GPS = garmin_EE_GPS_W*0.01433075379765; % in kcal/min % [Verhouding naar VO2 en MET] garmin_VO2_GPS = garmin_EE_GPS*0.8; % GPS data, zuurstofverbruik in mL/min garmin_MET_GPS = garmin_EE_GPS*199; % GPS data, MET-waarden garmin_VO2_HR = garmin_EE_HR*0.8; % HR data, zuurstofverbruik in mL/min garmin_MET_HR = garmin_EE_HR*199; % HR data, MET-waarden % [Data ZIP] zip('garmin_cosmed.zip',{'garmin_alldata.mat','cosmed_alldata.mat'}) % [Data exporteren naar CSV] %for i = 1:3:length(garmin_t) % garmin_avg = mean(garmin_t(i:i+2)); % end %writematrix([garmin_EE_GPS garmin_VO2_GPS garmin_MET_GPS garmin_EE_HR garmin_VO2_HR garmin_MET_HR cosmed_EEm cosmed_VO2 cosmed_METs],'garmin_cosmed_marc.csv')
Uz = unzip('garmin_cosmed.zip');
LDG = load(Uz{1});
garmin_alldata = LDG.garmin_alldata
garmin_alldata = 2031×5 table
HR cadence distance grade t __ _______ __________ _____ __ 91 0 0 0 0 91 0 0 0 1 93 115 0 0 2 95 115 0 0 3 95 60 0 0 4 96 57 0.00050952 0 5 97 60 0.0013359 NaN 6 96 57 0.0021872 NaN 7 95 0 0.0021872 NaN 8 95 0 0.0021872 NaN 9 96 0 0.0021872 NaN 10 96 0 0.0021872 NaN 11 96 0 0.0021872 NaN 12 96 0 0.0021872 NaN 13 96 0 0.0021872 NaN 14 96 0 0.0021872 NaN 15
LDC = load(Uz{2});
cosmed_alldata = LDC.cosmed_alldata(4:end,10:end);
cosmed_alldata.t = datetime(cosmed_alldata.t,'InputFormat','mm:ss', 'Format','mm:ss')
cosmed_alldata = 793×57 table
t Rf VT VE IV VO2 VCO2 RQ 02exp CO2exp VE/VO2 VE/VCO2 VO2/kg METs FeO2 FeCO2 FetO2 FetCO2 FiO2 FiCO2 PeO2 PeCO2 PetO2 PetCO2 Fase Marker Amb T Analyz. Press. PB EEkc EEh EEm EEtot EEkg Pro Vet CHO Pro% Vet% CHO% npRQ Ti Te Ttot Ti/Ttot VD/VT e LogVE t Rel Fase tijd VO2/Kg%Pred BR O2 delay CO2 delay RH sample Stride Cadence VT/Vi PaCO2_e _____ _____ _____ ______ ____ ______ ______ ____ _____ ______ ______ _______ ______ ____ _____ _____ _____ ______ ____ _____ ____ _____ _____ ______ ________ __________ _____ ______________ __ ____ ___ ____ _____ ____ ___ ____ ___ ____ ____ ____ ____ ____ ____ ____ _______ _______ _____ _____ _________ ___________ ____ ________ _________ _________ ______________ _____ _______ 00:28 20 0.524 10.48 542 74.25 64.042 0.86 105.2 4.2 122.3 141.8 0.99 0.3 20.08 0.8 16.29 4.12 20.9 0.07 145 6 117 30 {'NONE'} {0×0 char} 22.8 51 36 745 768 518 21.6 0.36 0 6.9 0 243 275 0 46.9 1.18 1.82 3 0.39 0.69 1.02 0 {'00:00'} 3 93 1267 1022 74 0 0.44 32 00:31 23.44 0.681 15.961 585 520.63 421.38 0.81 116.8 22 27.5 34 6.94 2 17.15 3.23 16.02 4.16 20.9 0.07 124 23 116 30 {'NONE'} {0×0 char} 22.8 51 36 745 768 3591 149.6 2.49 0 47.9 0 2337 1255 0 65.1 1.07 1.49 2.56 0.42 0.18 1.203 3 {'00:03'} 19 89.4 1267 1022 74 0 0.64 32 00:34 16.9 0.729 12.321 662 377.55 304.8 0.81 126.7 22.1 29.5 36.5 5.03 1.4 17.38 3.03 15.81 4.29 20.9 0.07 125 22 114 31 {'NONE'} {0×0 char} 22.8 51 36 745 768 2603 108.5 1.81 0 34.7 0 1712 891 0 65.8 1.75 1.8 3.55 0.49 0.25 1.091 3 {'00:06'} 13 91.8 1267 1022 74 0 0.42 33 00:38 14.96 0.855 12.793 968 400 339.99 0.85 147.7 27.8 29.4 34.5 5.33 1.5 17.27 3.25 15.75 4.38 20.9 0.07 125 23 114 32 {'NONE'} {0×0 char} 22.8 51 36 745 768 2785 116 1.93 0 37.1 0 1426 1359 0 51.2 1.14 2.87 4.01 0.28 0.23 1.107 4 {'00:10'} 14 91.5 1267 1022 74 0 0.75 34 00:42 14.85 1.208 17.941 1122 521.37 447.3 0.86 211.7 36.9 32.4 37.8 6.95 2 17.52 3.05 16.02 4.3 20.9 0.07 126 22 116 31 {'NONE'} {0×0 char} 22.8 51 36 745 768 3637 151.5 2.53 0 48.5 0 1763 1873 0 48.5 1.43 2.61 4.04 0.35 0.28 1.254 4 {'00:14'} 19 88.1 1267 1022 74 0 0.84 33 00:46 18.18 0.969 17.618 700 499.74 428.64 0.86 170.6 28.9 32.7 38.1 6.66 1.9 17.61 2.98 16.04 4.27 20.9 0.07 127 22 116 31 {'NONE'} {0×0 char} 22.8 51 36 745 768 3486 145.2 2.42 1 46.5 0 1693 1793 0 48.6 1.26 2.04 3.3 0.38 0.28 1.246 4 {'00:18'} 18 88.3 1267 1022 74 0 0.77 33 00:49 19.8 0.764 15.129 515 449.28 371.6 0.83 133.5 23 30.6 37 5.99 1.7 17.47 3.01 15.75 4.36 20.9 0.07 126 22 114 31 {'NONE'} {0×0 char} 22.8 51 36 745 768 3112 129.7 2.16 1 41.5 0 1836 1276 0 59 1.15 1.88 3.03 0.38 0.27 1.18 3 {'00:21'} 16 90 1267 1022 74 0 0.66 34 00:52 19.17 0.676 12.958 702 408.78 336.7 0.82 116.7 21.5 28.4 34.5 5.45 1.6 17.26 3.18 15.47 4.55 20.9 0.07 124 23 112 33 {'NONE'} {0×0 char} 22.8 51 36 745 768 2829 117.9 1.96 1 37.7 0 1703 1126 0 60.2 1.34 1.79 3.13 0.43 0.24 1.113 3 {'00:24'} 15 91.4 1267 1022 74 0 0.5 35 00:54 23.53 0.828 19.482 712 692.13 564.49 0.82 139.2 29.3 25.8 31.6 9.23 2.6 16.81 3.54 15.29 4.64 20.9 0.07 121 26 110 33 {'NONE'} {0×0 char} 22.8 51 36 745 768 4781 199.2 3.32 1 63.7 0 3009 1772 0 62.9 0.93 1.62 2.55 0.36 0.2 1.29 2 {'00:26'} 25 87.1 1267 1022 74 137 0.89 36 00:57 24.69 0.477 11.778 460 399.09 314.86 0.79 81.2 15.6 25.2 31.9 5.32 1.5 17.02 3.27 15.26 4.56 20.9 0.07 123 24 110 33 {'NONE'} {0×0 char} 22.8 51 36 745 768 2740 114.2 1.9 1 36.5 0 1974 766 0 72 0.89 1.54 2.43 0.37 0.18 1.071 3 {'00:29'} 14 92.2 1267 1022 74 0 0.54 35 01:01 12.35 2.41 29.753 2141 1058.7 888.07 0.84 404.5 87.8 27.3 32.5 14.12 4 16.78 3.64 15.43 4.65 20.9 0.07 121 26 111 34 {'NONE'} {0×0 char} 22.8 51 36 745 768 7353 306.4 5.11 1 98 0 4045 3307 0 55 1.99 2.87 4.86 0.41 0.23 1.474 4 {'00:33'} 38 80.3 1267 1022 74 156 1.21 36 01:03 32.61 0.463 15.098 856 392.69 334.39 0.85 82.8 12.6 32.6 38.3 5.24 1.5 17.88 2.72 16.3 3.97 20.9 0.07 129 20 118 29 {'NONE'} {0×0 char} 22.8 51 36 745 768 2735 114 1.9 1 36.5 0 1386 1349 0 50.7 1.08 0.76 1.84 0.59 0.22 1.179 2 {'00:35'} 14 90 1267 1022 74 92 0.43 31 01:06 30.3 0.54 16.364 83 683.21 534.64 0.78 87.1 21.5 20.8 26.6 9.11 2.6 16.13 3.98 14.66 5.01 20.9 0.07 116 29 106 36 {'NONE'} {0×0 char} 22.8 51 36 745 768 4684 195.2 3.25 2 62.5 0 3476 1207 0 74.2 0.36 1.62 1.98 0.18 0.12 1.214 3 {'00:38'} 24 89.1 1267 1022 74 0 1.5 38 01:09 18.13 0.523 9.48 547 383.88 286.67 0.75 85.3 19.3 21.4 28.6 5.12 1.5 16.31 3.69 14.45 5.03 20.9 0.07 118 27 104 36 {'NONE'} {0×0 char} 22.8 51 36 745 768 2610 108.7 1.81 2 34.8 0 2256 354 0 86.4 1.46 1.85 3.31 0.44 0.17 0.977 3 {'00:41'} 14 93.7 1267 1022 74 0 0.36 38 01:11 22.3 0.809 18.045 905 709.94 539.05 0.76 132.9 29.5 23.2 30.6 9.47 2.7 16.43 3.65 14.98 4.76 20.9 0.07 118 26 108 34 {'NONE'} {0×0 char} 22.8 51 36 745 768 4841 201.7 3.36 2 64.5 0 3977 864 0 82.2 1.12 1.57 2.69 0.42 0.19 1.256 2 {'00:43'} 25 88 1267 1022 74 0 0.72 36 01:14 20.41 0.672 13.714 757 506.87 394.28 0.78 112.1 23.6 24.2 31.2 6.76 1.9 16.68 3.51 15.15 4.65 20.9 0.07 120 25 109 34 {'NONE'} {0×0 char} 22.8 52 36 745 768 3471 144.6 2.41 2 46.3 0 2631 840 0 75.8 0.92 2.02 2.94 0.31 0.19 1.137 3 {'00:46'} 18 90.9 1267 1022 74 0 0.73 36
.
  1 Comment
Ilse Frans
Ilse Frans on 30 Aug 2023
Edited: Ilse Frans on 30 Aug 2023
Unfortunately this is the only data I have received and it's not possible to change.
The Cosmed timestamp is given in mm:ss and the Garmin timestamp in yyyy:mm:dd hh:mm:ss.
But now that I have the Garmin data in seconds and Cosmed per 3, how will I be able to use the function retime and/or synchronize to work?

Sign in to comment.


MinJi KANG
MinJi KANG on 21 Aug 2023
Let the Garmin device's data as x
for i=1:3:length(x)
avg = mean(x(i:i+2))
end
If you do that, you can get avg(470x1 format) data.
Hope you can solve it.
  2 Comments
Ilse Frans
Ilse Frans on 21 Aug 2023
I understand this, but when I have a Garmin variable with a 1207x1 size, I get the following error:
for i = 1:3:length(garmin_t)
garmin_avg = mean(garmin_t(i:i+2));
end
>>
Index exceeds the number of array elements. Index must not exceed 1207.
Error in garmin_cosmed_marc (line 31)
garmin_avg = mean(garmin_t(i:i+2));

Sign in to comment.

Categories

Find more on Genomics and Next Generation Sequencing 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!