I've just attached a patch with the code used to produce these screen-captures, the algorithm used is commented there, but a global description could be useful here for discussion, so here we go:
The basic idea is to start with a number of "segments" with the following information:
- initial altitude and velocity
- final altitude and velocity
- power, velocity and headwind at intermediate points (if headwind is not present, zero is assumed).
this segments are defined by points where altitud is non-zero (zero altitude is considered as no data), in the limit case in which all points have altitude non-zero each recording interval would be considered a "segment", but I have not tested this case since I not have such file to do the test.
With this information and assuming no breaking, no change in position nor in the surface, air density, mass, etc. we can compute an energy balance equation for each segment:
- Energy Loss = Energy Gain
where Energy loss is the sum of Aerodinamic and Rolling Resistance losses and Energy Gain is the sum of power supplied by the rider (minus transmission loss) times the duration of the interval plus Potential and Kinetic energy variation:
Aero-Loss + Rolling-Loss = sum(Eta * Power * Duration) + DeltaPE + DeltaKE
using the standard approximation of a global CdA and Crr and knowing air density (Rho), total mass (Mass), we have (using Distance = v*dt):
Aero-Loss = sum(0.5 * Rho * HeadWind**2 * Distance * CdA)
Rolling-Loss = sum(Mass * g * Distance * Crr)
where the sum() is over all the recording intervals in the segment (a first order approximation to the integral). The other terms are as expected:
DeltaPE = M * g * (initialAlt - finalAlt)
DeltaKE = 0.5 * M * (initalVel**2 - finalVel**2)
So, if we have N segments, we have N equations of the form:
X1 * CdA + X2 * Crr = Egain
where the unknowns are CdA and Crr, with two of them we could have an "exact" solution, but in general should be better to have more an look for the best-fit solution. In matrix form we have:
X * [ CdA ; Crr ] = Egain
pre-multiplying with X transpose (X'):
X' * X [ CdA ; Crr ] = X' * Egain
lets call A = X' * X and B = X' * Egain:
A * [ CdA ; Crr ] = B
and we have a 2x2 system which is solved to have the best fit CdA and Crr.
If the solution pass some consistency checks, Aerolab values are updated so the change is visible in the graph.
Caveat: the one-interval-per-segment with full altitude data has not been tested, perhaps this would need to be "smoothed" using more than one interval per segment, would be interesting to do some testing but I don't have the corresponding data.
Ale.