Last active
September 29, 2017 21:50
-
-
Save aadm/89c91376bf9f4cabf9362d32050708e9 to your computer and use it in GitHub Desktop.
Little hack scripts to compare heartrate measurements from Polar and Garmin.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
import matplotlib.dates as mdates | |
import pandas as pd | |
import os | |
# (1) Garmin Connect: export gpx | |
# (2) convert gpx with heartrate_comparison_dataprep.sh <file.gpx> | |
# (3) Polar Flow: export csv | |
# reads data from garmin | |
f1=os.path.join(os.sep, os.getenv('HOME'), 'Downloads','garmin_activity_xxx.gpx.csv') | |
ga = pd.read_csv(f1, header=None, names=['time','hr'], parse_dates=[0]) | |
# reads data from polar | |
f2=os.path.join(os.sep, os.getenv('HOME'), 'Downloads','polar_username_xxx.csv') | |
po = pd.read_csv(f2,skiprows=2) | |
# timestamps from Polar csv are in relative time (starts at 00:00:00) so I add a delta time | |
# on the basis of the first time sample from the Garmin file | |
delta=ga.time[0]-po.Time[0] | |
po['Time_shift'] = po['Time'] + delta | |
f, ax = plt.subplots(figsize=(8,5)) | |
plt.plot(ga['time'], ga['hr'], '-b', lw=4, alpha=0.5, label='Garmin FR935') | |
plt.plot(po['Time_shift'], po['HR (bpm)'], '-r', lw=4, alpha=0.5, label='Polar M400') | |
plt.legend() | |
plt.grid(axis='y') | |
ax.xaxis.set_major_formatter(mdates.DateFormatter("%H:%M")) | |
_=plt.xticks(rotation=45) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
GPX=$1 | |
tempfoo=`basename $0` | |
TMPFILE1=`mktemp /tmp/${tempfoo}.XXXXXX` || exit 1 | |
TMPFILE2=`mktemp /tmp/${tempfoo}.XXXXXX` || exit 1 | |
echo "--> heartrate_comparison_dataprep.sh: input Garmin Connect gpx, output csv with time,hr" | |
echo "--> temporary files created (and deleted):" | |
echo " $TMPFILE1, $TMPFILE2" | |
echo "--> output: $GPX.csv" | |
awk -F "[><]" '/time/{print $3}' $GPX | sed '1d' > $TMPFILE1 | |
awk -F "[><]" '/ns3:hr/{print $3}' $GPX > $TMPFILE2 | |
paste -d , $TMPFILE1 $TMPFILE2 > $GPX.csv | |
rm -f $TMPFILE1 $TMPFILE2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Little hacks to compare heartrate measurements from Polar M400 (with HR chest strap) and my new Garmin FR935 (with optical heart rate monitor).
What to do:
heartrate_comparison_dataprep.sh <file.gpx>
This is what you should get.
I know, the accuracy of the optical HR measurement is really surprising!