Seven versions of a cadence algorithm: what improved and what didn’t

Cadence Coach helps you train the cadence you choose, not one “right for everyone”: you set a target and the app guides you by voice, so you don’t have to look at the screen. To do that it needs to know your cadence, that is, the number of pedal revolutions per minute (rpm), and it works that out from the phone’s motion sensors. While building the app I wrote seven versions of the cadence-detection algorithm, and for this article I compared them on the same rides against a reference sensor on the crank. In steady riding the error fell from 0.60 rpm for the first version to 0.32 for the last, almost by half. At 90 rpm that is about 0.4%. The path was not a straight line, though: in an intermediate algorithm the error rose to 1.24, and the hardest moment, spin-up (the first seconds after the pedals start turning again), remains the weak spot.

· Alexey Egorenko

Why track cadence

The same power can be produced in different ways: pushing harder on the pedals less often, or lighter and more often. In the first case more of the load falls on the leg muscles, in the second on the heart and breathing. Which is better depends on the person, their fitness and their goal, so there is no single “right” cadence for everyone: a review of the research on cadence selection (Ansley and Cangley, European Journal of Sport Science, 2009) comes to a similar conclusion, listing many factors from muscle fibre type to perceived effort.

I train a high cadence: for me it is a way to strengthen the cardiovascular system and burn fat. That is my goal, not advice for everyone. High cadence is also where I find it hardest to keep an even tempo, and that is where I need the cues.

Steady cadence is useful for a different reason: it is easier to hold consciously. When the tempo drifts, it often slides to wherever feels familiar rather than where you wanted to train, and every spin-up after a stop costs energy. Voice cues bring the tempo back into the chosen range without taking your eyes off the road.

But a cue only works if the app detects cadence correctly. If it is off by many revolutions, “a bit faster” will sound when you are already on target. That is why, for me, the accuracy of cadence detection is the foundation of the app, not a detail.

In short

  • Steady riding. The latest version has an error of 0.32 rpm, and 99.7% of seconds are within 2 rpm of the reference.
  • Progress was not a straight line. Algorithm B turned out worse than the first version, A, and only smoothing brought it back. The best results in steady riding and in transitions belong to A1 and C1.
  • Coasting. When the pedals are still, the B family still showed a number in 93% of seconds; for the C family it is 6%.
  • Spin-up remains the weak spot. Algorithm C1 has an error of 4.88 rpm, a number is shown in 77% of seconds, and 13.8% of the values shown are off by more than 10 rpm. That is the price of the principle “better to say nothing than to show a false number”. Part of this error comes from the sensor’s own lag (see “Spin-up”).
  • Data from one person and one phone. To understand how the algorithm behaves for others, I need data from other cyclists.

How I measured

From a metronome to a crank sensor

To talk about error you need a reference. I used to compare the algorithm with a metronome: it set the tempo and I tried to follow it.

I only tried. I wanted to collect as much data as possible, so I built a data-collection mode that changed the target cadence by 10 revolutions every minute, from 60 to 120 and back. Part of the time went on spin-up and settling in, and the data came out dirty. Practice showed that at low and medium cadence I need more time to settle, and at high cadence I lack stability. I will have to work on that with the help of the app itself.

When a cadence sensor appeared on the crank, it turned out that the metronome had been a poor ruler. I pedal more evenly than I thought: in steady riding the cadence changes from one revolution to the next by 0.27 rpm on average, and only 0.4% of neighbouring revolutions differ by more than 2 rpm. So most of the spread in the old numbers was not coming from me.

The reference today is an Android phone and a cadence sensor on the crank. The sensor reports the time of every revolution. For each algorithm I look at which number it showed in each second and compare it with the reference. Error here means the absolute difference in revolutions per minute (rpm), averaged over seconds.

How much data I have

In total I have 60 recordings. The core is 35 ride recordings with a combined length of 12 hours 15 minutes: metronome, training program and free riding. The rest are test recordings. Some are short recordings of specific modes: riding standing on the pedals, rolling down a bumpy hill and others. Others are app tests: stability over long runs (including four overnight tests), cues working together with music, and the phone not shutting down the sensors.

Besides the rides themselves, a lot of time went into a web tool that made analysing and labelling recordings much easier.

Four modes and version names

This article uses eight rides with a cadence sensor as the reference: 3 hours 29 minutes of recording, 8,422 scored seconds. I divide the seconds into four modes. In my rides about 61% of pedalling time is steady, about 22% transitions and about 16% spin-up.

  • Steady (3,488 s): the reference cadence changes by no more than 4 rpm within ±5 seconds.
  • Spin-up (918 s): the first 10 seconds after a coast or a gap in the data.
  • Transitions (1,262 s): the rest of the riding, where cadence is changing.
  • Coast (2,754 s): the pedals are not turning.

The versions are named with letters. A, B and C are three different approaches. The digit means a close variant or the same approach with smoothing: B1 and B2 are B with increasingly strong smoothing, C1 is C with smoothing. Algorithm C1 already runs in the app, including in the closed test, and is being considered as a release candidate.

  • A
  • A1
  • B
  • B1
  • B2
  • C
  • C1

Steady riding: an error under a third of a revolution per minute

Calm riding without accelerations: in my rides it takes up the most time, and progress is easiest to see here. The latest version, C1, is off by 0.32 rpm on average. B had 1.24. Within 2 rpm of the reference, C1 had 99.7% of seconds and B had 82.8%.

But on this measure the first versions also look fine: the very first algorithm, A, has an error of 0.60 rpm, and 98.6% of its seconds are within 2 rpm of the reference, almost as many as C1. Version B turned out worse than A (1.24), and only smoothing brought B2 back to 0.53. The best results came from A1 (0.35) and C1 (0.32). So steady riding alone is not enough for a comparison, and next I look at the other modes.

Rides differ noticeably. The error of C1 by ride runs from 0.27 to 0.59, that of B from 0.89 to 2.29, that of A from 0.46 to 0.64. One ride alone would not show this. The overall figure is also skewed: one 81-minute ride accounts for 60% of all steady seconds.

Spin-up: the hardest moment

Spin-up is the first seconds after a coast, when cadence climbs quickly. C1 has an error of 4.88 rpm, and a number is shown in only 77% of seconds: the app needs to accumulate data before making an estimate. Of the values shown, 13.8% are off by more than 10 rpm. B almost always has a number (98%), but its error is 18.9 rpm, and 39% of its values are off by more than 10 rpm.

I set the spin-up window in advance: 10 seconds from the moment the pedals start turning again. In those seconds cadence goes from zero to working cadence: after 10 seconds it is usually around 81 rpm for me. My rides contained 256 spin-ups.

An algorithm shows its first number quickly: C1 after 1.4 seconds, A1 after 0.8. But the first number is not necessarily the right one. C1 gets within 2 rpm of the reference after 4.5 seconds (median), A1 after 3.7.

You cannot read the spin-up error without the share of answers, and here the price needs explaining.

Why B almost always answers

Algorithm B takes the last measured revolution and shows it almost without checking. At the start of spin-up cadence climbs quickly, and such a number often lags far behind the real one. That is why it has 98% answers, and 39% of them are off by more than 10 rpm. Here a high share of answers is not a merit but a lack of doubt.

Why C1 answers less often

This algorithm is built on the principle I started with: the app must not show false numbers. While there is too little data or too little confidence, it stays silent. So in 23% of spin-up seconds, about two seconds out of ten on average, there is no answer from it. It shows its first number on average after 1.4 seconds.

The price, and why it is worth paying

Counting over all spin-up seconds, the picture is this. B gives a number within 2 rpm in 28% of seconds and far off in 38%. C1 gives an accurate number in 49% of seconds and far off in 11%. So the silence costs roughly two seconds of quiet per spin-up, and in return C1 is accurate almost twice as often and far off 3.5 times less often. For an app with voice cues this matters: a cue is built on a number. Any false number means a false cue (“faster” when you are already fast), while silence means there is simply no cue.

You can raise the share of answers, but you will pay for it with false numbers. That is how the auxiliary variants on the chart behave: those that answered least often had the smallest errors, while B, which answers almost always, has the largest. A1 answers more often than C1 (89% against 77%) and is accurate slightly more often (52% against 49%), but is also far off slightly more often (13% against 11%). The choice between them is a choice between “speak more often” and “be wrong less often”, and I chose C1.

What the sensor shows in the first seconds

First, a caveat about the reference. In the first one to three seconds after a coast the crank sensor lags: the first interval between revolutions after a stop is long, so the sensor shows a low value. In the first second after a coast it showed 59 rpm on average (median over 469 cases, range 20 to 103). I inferred the cause from the pattern in the data. Checking it separately would take near-laboratory conditions, so I did not.

This explains part of the large errors. For C1 there are 97 seconds of spin-up with an error above 10 rpm: that is the 13.8% of values shown. In 65 of them (9.2% of values shown) the sensor caught up with the app’s value within 4 seconds: the app was closer to the final value and the sensor lagged. The other 32 seconds (4.5%) are not explained this way; they are ordinary estimation errors. The same lag accounts for six seconds in which the C1 value looked doubled (0.9%): in all six the sensor converged with the estimate after 1–3 seconds. This alone does not prove that the app is more accurate than the sensor: convergence after 1–3 seconds is an indirect sign, and I have no independent reference. But given how the sensor works and the amount of data collected so far, the explanation looks plausible.

If the first 3 seconds of every spin-up are left out, the numbers change a lot. The error of C1 falls from 4.88 to 1.89 rpm, the share of values off by more than 10 rpm from 13.8% to 3.6%, and the share of seconds with a value rises from 77% to 94%. For A the error goes from 5.26 to 3.56, for B from 18.93 to 7.54. I am not replacing the main row with this one: I chose the 3-second threshold after seeing the results, and leaving those seconds out removes not only the sensor’s lag but also the estimator’s own warm-up, when it still needs a full revolution. So the first three seconds after a coast are a poor basis for comparison: the sensor lags, and the estimate needs a revolution.

Only two conclusions about the order of the versions hold at every threshold. C1 is the best when 0, 2, 3 or 4 seconds are left out, and the B family (B, B1, B2) is the worst. The other versions differ within the spread: for example, A and C swap places depending on the threshold.

Coasting: the B family showed a cadence while the pedals were still

When the pedals are still, the right answer is “no cadence”. The versions of the B family showed a number in 93% of coasting seconds anyway, because of a large smoothing window. For the C family it is 6.2%. This is the biggest change between versions in terms of ratio.

My coasts are short. There were 233 of them, the median coast is 6 seconds, and 9 out of 10 are shorter than 25 seconds, though there are some very long stops. That is because I try not to lose speed: then I don’t have to spend a lot of effort on spin-up.

In the C family a number stays on in 6% of coasting seconds. Smoothing is there to improve data quality at spin-up, but it lags slightly, so on a coast one more voice cue sometimes manages to sound. This only happens in the target zone, when the cue sounds without delay. In the app you can set the delay and the repeat frequency for each cue.

Want to hear how this works on the road? The app is in closed testing on Google Play. Join the test

Transitions: the error fell by a factor of two and a half

Transitions are riding where cadence is changing: accelerating, slowing down, changing tempo. Here the error fell from 2.65 for B to 1.00 for C1. About 88–89% of seconds for A1 and C1 are within 2 rpm of the reference, against 64% for B. The spread between rides is large, especially for B: from 1.82 to 6.09.

Transitions are short: there were 277, with a median length of 4 seconds. Altogether they take about 22% of pedalling time.

The whole path: the error rose and fell

By date, the versions went like this: A (0.60), then B (1.24), then B1 and B2 with smoothing, A1 (0.35), C (0.62) and C1 (0.32). So the error first rose, then fell, then rose again with a new approach and only became the best after smoothing. By error, C1 leads or shares first place in all four modes, but in spin-up it answers less often than A1.

The “has answer” (spin-up) and “number shown” (coast) columns show the difference between the approaches. B answers almost always (98% of spin-up seconds) because it shows a number without doubt. It pays for that not only with errors in spin-up but also in coasting: a number is shown in 93% of seconds when the pedals are still. C1 stays silent where it is unsure (an answer in 77% of spin-up seconds, a number shown in 6% of coasting seconds) and in return makes fewer errors. The price of this choice is described in detail in the “Spin-up” section.

The versions are built differently: some take the last revolution, others average several. So this compares approaches, not only time.

Work on the algorithm continues, but progress has slowed noticeably. Perhaps I am close to the limit of what can be extracted from a phone’s sensors, but only data from other cyclists can show that.

What this means for a rider

In plain terms, if you ride with the phone in a pocket:

  • When you hold an even tempo, you can trust the number. In my rides the app was off by about a third of a revolution per minute, so a target of 90 is not read as 87 or 93. Almost every second (99.7%) was within 2 rpm of the sensor on the crank.
  • The first seconds after a start are the weak spot. After a coast the app needs a few seconds to be sure. A number appears after about 1.4 seconds, and it is usually within 2 rpm after about 4.5 seconds. In about two seconds out of ten in that window there is no number at all.
  • Silence is deliberate. When the app is unsure, it prefers no cue to a wrong one: “faster” when you are already fast is worse than no cue.
  • On a coast there should be no cadence. In the current version a number still lingers in about 6% of coasting seconds, so one extra cue is occasionally possible.
  • This is one person and one phone. Your phone, pocket and style of riding may give different numbers, and that is exactly the data I am asking for below.

What these numbers do not show

  • One person and one phone. In early experiments there were two phones from different manufacturers, but all eight rides with the sensor were recorded on one. Other people and phones may give a different result.
  • Only eight rides, 3 hours 29 minutes. The phone was in a pocket.
  • Cadence was mostly between 75 and 105 rpm.
  • The reference is tied to the time the sensor signal was received, which gives an uncertainty of about ±1 revolution. The reasons: the sensor sends data over Bluetooth, reception has delay and jitter (for 73% of packets within ±0.7 seconds, for 5% more than 3.9 seconds), and sometimes several revolutions arrive in one packet. On average that happens with 1% of packets, but at a high cadence of 110–120 rpm with about 13%. The standard Bluetooth Cycling Speed and Cadence Service reports a running revolution count and the time of the last revolution, not each revolution as it happens. I did not separately measure the sensor’s own delay. All the numbers are estimates.
  • In the first seconds of spin-up it is especially hard to compare the app with the reference: the sensor on the crank cannot resolve anything faster than one or two revolutions.
  • In coasting, the shares of “number shown” are slightly overstated: in the calculation a number counts as valid for up to 2.5 seconds after the last answer.
  • I set the boundaries of the modes myself before running the calculations. Different boundaries would give different shares.
  • These are my own measurements, not a certified accuracy.

Try Cadence Coach and help with data

Cadence Coach is an Android app that helps you hold a chosen cadence. You set a target cadence or a range and hear voice cues while riding, without looking at the screen. You can set the delay and the repeat frequency of each cue. You can also have a metronome play alongside at your target tempo. Cadence is detected from the phone’s motion sensors, so no extra hardware is needed. The app works without internet and without ads, and rides are stored only on your phone.

The app is currently in closed testing on Google Play. To join you need an Android phone and the Google account you use in Google Play. Joining takes two short steps, described on the next page.

Join the test

I need your data. Everything above was checked on one person and one phone. To understand how the algorithm behaves for others, I need other cyclists, other phones and other riding, especially above 105 rpm, where I have almost no data. If you want to help, you can send me a recording of your ride. It is voluntary and off by default, and recording rides and cues work without it. The app sends nothing by itself: you export the ride you choose into a single ZIP file and send it to me through the Android “Share” menu, for example in a messenger or by email.

The archive contains accelerometer and gyroscope readings, ride settings and technical data: the phone model and the app and Android versions. It contains no name, email, location, contacts or microphone audio. The archive comes with a random participant ID: it is created when you first consent and is not linked to your account, phone number or device. This does not make the data anonymous, but with this ID you can ask me to show or delete your data. The archive is kept for three months, and I will delete it sooner if you ask. Details are in the research participation notice. Questions and feedback: [email protected].