Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@aadm
Last active September 29, 2017 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aadm/89c91376bf9f4cabf9362d32050708e9 to your computer and use it in GitHub Desktop.
Save aadm/89c91376bf9f4cabf9362d32050708e9 to your computer and use it in GitHub Desktop.
Little hack scripts to compare heartrate measurements from Polar and Garmin.
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)
#!/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
@aadm
Copy link
Author

aadm commented Sep 29, 2017

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:

  • run with the two watches
  • export gpx from Garmin Connect
  • convert this gpx file with the bash script heartrate_comparison_dataprep.sh <file.gpx>
  • export csv from Polar Flow
  • modify the names and folder of your two input files in the python script
  • run the script

This is what you should get.

comparison_hr_polarm400-garminfr935

I know, the accuracy of the optical HR measurement is really surprising!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment