Virtual Elevation: Preliminary Code and Results

74 views
Skip to first unread message

Andy Froncioni

unread,
Dec 13, 2009, 1:22:48 PM12/13/09
to golden-cheetah-users
Phew! Ok, I managed to hack something together in perl to compute Crr
and CdA using the Virtual Elevation Method, or my best attempt at it. I
used a lot of the data in Robert Chung's recent Wattage Forum
spreadsheet repost.

(It's important to acknowledge that this work is completely taken from
the stuff that's regularly shared on the Wattage Forum. Without that
forum, we would have a really tough time doing all this cool stuff.)

Here's how it works:

Features:
----------------------------------------------------------------------------------------------------------------------------
- computes Crr and CdA from power file and elevation profile
- stably tries to match the profiles using a global L2 norm
- full equations used for Newton's 2nd law (no small-angle approximations):
F - m g sin(theta) - Crr m g cos(theta) - CdA rho v^2 / 2 = m a
- regular iteration solver for slope to cope with nonlinear trig equation
- full Newton-Raphson using numerical derivatives for outer solver



To Do:
----------------------------------------------------------------------------------------------------------------------------
+ recheck numerics over and over to make sure they're right
+ implement Chung method for use when no elevation profile is available
+ provide unit tests to bolt-down the validation of the code
+ add calculation for rho, air density



Executable:
----------------------------------------------------------------------------------------------------------------------------
Perl program, ve.pl, attached.



Perl dependencies:
----------------------------------------------------------------------------------------------------------------------------
require Math::Trig;



Inputs:
----------------------------------------------------------------------------------------------------------------------------
A PowerTap CSV file, pt_data.csv, attached.
An associated elevation file, elevation.csv, attached.
Mass of rider + bike, m. ( Here, 89kg)
Time-sampling interval, dt. ( Here, 1.26s )
Density of air, rho ( Here 1.236kg/m^3)
Conversion factor from speed in file to m/s, v_factor (Here, 3.600 )
Starting elevation, elev_start. (Here, 7.59m)


Command line usage:
----------------------------------------------------------------------------------------------------------------------------
% ve.pl <power_tap_file> <elevation_file> <m> <rho> <dt> <v_factor>
<elev_start>



Example:
----------------------------------------------------------------------------------------------------------------------------
% ve.pl pt_data.csv elevation.csv 89 1.236 1.26 3.6 7.59
crr= -0.00896848, cda= 0.71414735 RESIDUALS: 0.051821
121720394637.221100
crr= -0.01887355, cda= 0.74727538 RESIDUALS: 0.043221
24240094726.978828
crr= -0.06140901, cda= 1.32495998 RESIDUALS: 0.724061
4847607668.734711
crr= 0.04881965, cda= -0.23143669 RESIDUALS: 1.950369
970123080.834633
crr= 0.01233395, cda= 0.28146843 RESIDUALS: 0.642751
195195026.279830
crr= 0.00621468, cda= 0.36746316 RESIDUALS: 0.107765
39145221.731429
crr= 0.00499893, cda= 0.38454789 RESIDUALS: 0.021410
7829464.327135
crr= 0.00475554, cda= 0.38796827 RESIDUALS: 0.004286
1565869.723166
crr= 0.00470688, cda= 0.38865210 RESIDUALS: 0.000857
313175.156131
crr= 0.00469715, cda= 0.38878888 RESIDUALS: 0.000171
62634.927414
crr= 0.00469520, cda= 0.38881621 RESIDUALS: 0.000034
12527.026148
crr= 0.00469481, cda= 0.38882167 RESIDUALS:
0.000007 2505.412917
crr= 0.00469473, cda= 0.38882276 RESIDUALS:
0.000001 501.082018
crr= 0.00469472, cda= 0.38882298 RESIDUALS:
0.000000 100.216611
crr= 0.00469472, cda= 0.38882303 RESIDUALS:
0.000000 20.043254
crr= 0.00469471, cda= 0.38882303 RESIDUALS:
0.000000 4.008642
crr= 0.00469471, cda= 0.38882304 RESIDUALS:
0.000000 0.801726
crr= 0.00469471, cda= 0.38882304 RESIDUALS:
0.000000 0.160310
crr= 0.00469471, cda= 0.38882304 RESIDUALS:
0.000000 0.032088
crr= 0.00469471, cda= 0.38882304 RESIDUALS:
0.000000 0.006452
crr= 0.00469471, cda= 0.38882304 RESIDUALS:
0.000000 0.001279
crr= 0.00469471, cda= 0.38882304 RESIDUALS:
0.000000 0.000221



Cheers!

Andy




pt_data.csv
elevation.csv
ve.pl

Andy Froncioni

unread,
Dec 13, 2009, 1:51:48 PM12/13/09
to golden-cheetah-users
More results... Attached are two plot files:

convergence.jpg: plot of several iterations of the virtual elevation
profile
convergence2.jpg: plot of iteration 10 vs actual elevation profile
(they're very very close!)

Enjoy,

Andy
convergence.jpg
convergence2.jpg

Mark Liversedge

unread,
Dec 13, 2009, 5:18:52 PM12/13/09
to golden-cheetah-users
NICE! I want!

Andy Froncioni

unread,
Dec 13, 2009, 5:28:29 PM12/13/09
to Mark Liversedge, golden-cheetah-users
Mark Liversedge wrote:
> NICE! I want

Well, we have to discuss a bit what options this new feature will
allow. For example:
1) Greg Steele has mentioned that maybe there should be an option to
hold Crr steady, and vary only CdA.
2) Andy Coggan has also pointed out that the real Chung Method doesn't
make use of an elevation profile. We need it look into the method, the
test protocol, and perhaps offer some kind of options for it. The
protocol is as much an integral part of this as an other code.
Instructions to the user are key to helping them get good results.
3) We might want to offer an elevation profile convergence plot to show
the user how the algorithm proceeds. Some of the more experienced VE
technicians might make use of this information to tweak the final
results. I'm not an expert user, so I don't know how this works.
4) Greg also mentioned that the algorithm could be improved if
accelerometer data is available. This is so cool -- it would greatly
improve the accuracy of the algorithm by incorporating a bit of redundancy.
5) The iAero would also allow another flavour of this feature, allowing
us to double-check with existing CdA and Crr coast-down results.

Any ideas out there?

Andy Coggan

unread,
Dec 14, 2009, 8:52:36 AM12/14/09
to golden-cheetah-users
On Dec 13, 4:28 pm, Andy Froncioni <a.fronci...@sympatico.ca> wrote:

> 2) Andy Coggan has also pointed out that the real Chung Method doesn't
> make use of an elevation profile.

Right - what you have coded up is "simply" an iterative solution to
the equation of motion, under the assumption that there is no wind. As
such, it doesn't require you to ride over the same spot more than
once, which is the key to Robert's VE method.

> 5) The iAero would also allow another flavour of this feature, allowing
> us to double-check with existing CdA and Crr coast-down results.

The iBike software actually already contains the approach you've
taken...and based on my experience with that, I think that putting
some careful thought into how to best iteratively solve the equation
*while explicitly recognizing issues of accuracy, error propogation,
etc.,* could be quite helpful.

Andy Coggan

Andy Froncioni

unread,
Dec 14, 2009, 9:32:23 AM12/14/09
to Andy Coggan, golden-cheetah-users
Andy,
> Right - what you have coded up is "simply" an iterative solution to
> the equation of motion, under the assumption that there is no wind. As
> such, it doesn't require you to ride over the same spot more than
> once, which is the key to Robert's VE method.
>
That reminds me... I'd like to try some high-order implicit
time-stepping schemes. In my experience, they are extremely stable and
much much more accurate. In fact, to be honest, I would never trust a
forward-difference scheme with anything that vital. I'm putting this on
the ToDo list for sure. It's a much bigger project because it involves
coding up a sparse matrix solver. But it's worth it...

I also want to experiment with autoconvolution of the virtual profile.
Let me explain: if you do N loops of a course, you would expect that
the autoconvolution of the virtual elevation vs. distance profile would
produce a maximum at x=D, the length of a single loop. By maximizing
this maximum, you can solve for (Crr, CdA).
> The iBike software actually already contains the approach you've
> taken...and based on my experience with that, I think that putting
> some careful thought into how to best iteratively solve the equation
> *while explicitly recognizing issues of accuracy, error propogation,
> etc.,* could be quite helpful.
>
As I mentioned, using an implicit time-stepping scheme eliminates a lot
of the tolerance-stacking associated with time-integration. By using a
global norm ( L2-error, autoconvolution, etc...) you remove a lot of the
worries of using "point-wise" error metrics.

Thanks for the info, Andy. It is very helpful to have someone around
who's that well-read.

Cheers,

Andy (no, not that one)


Andy Froncioni

unread,
Dec 16, 2009, 10:10:42 AM12/16/09
to golden-cheetah-users
I just made some slight changes to the VE perl script for virtual
elevation calculations.

You can see the update and download the code here:
http://andyfroncioni.com/2009/12/ve-update-improved-stability-and-convergence/
.

Just to be clear, the aim of this not to start a stand-alone piece of
code, but instead to provide all the numerical de-risking necessary to
turn this into a Golden Cheetah port. The code will be cross-posted to
the wattagetraining forum for their feedback.

Enjoy!

Andy

Dag

unread,
Dec 16, 2009, 12:41:00 PM12/16/09
to golden-cheetah-users
Can the equation be reversed to compute the Virtual Wattage? If this
matches the elevation so well that should be possible as well.

Andy Froncioni

unread,
Dec 16, 2009, 12:56:38 PM12/16/09
to Dag, golden-cheetah-users
Dag wrote:
> Can the equation be reversed to compute the Virtual Wattage? If this
> matches the elevation so well that should be possible as well
VE uses a real elevation profile and power data to compute 2 numbers,
Crr and CdA. It uses 2N (N large) samples of the data to solve for 2
unknowns in an over-constrained system of equations.

What you are proposing requires that with 2 inputs ( Crr, CdA ) and N
elevation samples we compute the power profile. It's more likely to
yield very precise results, but it is very similar to what iBike does.
I would say that the resulting power data would be as prone to numerical
errors as the original iBike-like calculation is.

See my Wattage Forum error analysis to see how bad this can be:
http://wattage.googlegroups.com/web/iBike_Error_Analysis.xls?gda=zGwK80oAAAA3b4NUdY_RIAVFYIq1Ir8_ocksebbTR34v9hAXDnxICbgtQqTtpXJyxiTdvuuHw4gK6Zok1W5MBtOwQ93PmTOx_e3Wg0GnqfdKOwDqUih1tA
.

But I suppose it might be able to work, in principle.

Cheers,

Andy

Andy Froncioni

unread,
Dec 16, 2009, 12:58:16 PM12/16/09
to Dag, golden-cheetah-users
Andy Froncioni wrote:
> Dag wrote:
>
>> Can the equation be reversed to compute the Virtual Wattage? If this
>> matches the elevation so well that should be possible as well
>>
> VE uses a real elevation profile and power data to compute 2 numbers,
> Crr and CdA. It uses 2N (N large) samples of the data to solve for 2
> unknowns in an over-constrained system of equations.
>
> What you are proposing requires that with 2 inputs ( Crr, CdA ) and N
> elevation samples we compute the power profile. It's more likely to
> yield very precise results,
What the heck am I saying?!! I mean to write IMprecise results, here.
My bad!
:-|

Andy Coggan

unread,
Dec 16, 2009, 3:31:16 PM12/16/09
to golden-cheetah-users
On Dec 16, 11:56 am, Andy Froncioni <a.fronci...@sympatico.ca> wrote:

> VE uses a real elevation profile

Virtuality is the new reality? ;-)

Andy Coggan

Jim Gilchrist

unread,
Dec 16, 2009, 3:37:57 PM12/16/09
to Andy Coggan, golden-cheetah-users
I cannot keep up with all of the emails on this list.

I have tried to unsubscribe from the updates but cannot, I keep getting delivery failures.

Can someone unsubscribe me, please.
> --
> _______________________________________________
> Golden-Cheetah-Users mailing list
> golden-che...@googlegroups.com
> http://groups.google.com/group/golden-cheetah-users?hl=en

Sean Rhea

unread,
Dec 16, 2009, 3:45:31 PM12/16/09
to Jim Gilchrist, Andy Coggan, golden-cheetah-users
Jim,

I've unsubscribed you.

Sean
--
"I refuse to accept the idea that the ‘isness’ of man’s present nature
makes him morally incapable of reaching up for the eternal ‘oughtness’
that forever confronts him." --MLK
Reply all
Reply to author
Forward
0 new messages