Physical activity is essential to both physical and mental health, something brought home to many people following sedentary pandemic lockdowns. Even without the lockdowns, many parts of the world have been facing an obesity epidemic, which has created a need to help people manage their weight. For such people there are a wealth of fitness and diet apps that rely on smartphone and smartwatch sensors to monitor activity levels and track the calories they have burned. The problem is that smartphones and smartwatches do a terrible job at calorie counting.
A 2017 study looked at seven such typical devices, and found their counts were off between 27 and 93 percent, depending on the device. We decided to see if a better calorie counter could be made, at least for some forms of activity. The answer is yes—and it's one you can build yourself with parts any maker can easily obtain.
The road to the calorie counter began in our lab (the Human Performance Laboratory in the Stanford University School of Engineering), where we study things like the metabolic cost of walking. We broke out every possible sensor we had in the lab and attached them to participants. This included sensors that monitor muscle activity, inertial measurement units (IMUs) to monitor movement on different parts of the body, and instrumented insoles in shoes to monitor forces produced by walking and running. We used respirometry, a lab-based method of measuring energy expenditure by monitoring the oxygen intake and carbon dioxide expelled with each breath, so as to get a ground-truth measure of the calories burned as participants moved. With all of this data we looked at building a fundamental relationship between the movement of the body (and thus the activity of the muscles burning calories) and the actual energy expended by the whole body.
We found that by looking at the motion of the thigh and the shank (lower leg) we could estimate caloric expenditure during aerobic activities with an accuracy of about 13 percent. (For the full details of our analysis, see our recent paper in Nature Communications.) What's more, we could do it using inexpensive IMUs.
Two small inertial measurement units [top right] are strapped to the user's thigh and shank. Using a I2C expansion board [top middle], the IMUs feed data into a Raspberry Pi [bottom middle] powered by a USB battery pack [left].James Provost
We used Adafruit Precision NXP 9-DOF breakout board IMUs. This board combines two sensor chips, a six-degrees-of-freedom accelerometer/magnetometer, and a three-degrees-of-freedom gyroscope. The counter uses two of them, one attached at midthigh, the other at midshank. In our tests, we sometimes used toupee adhesive to hold various IMUs in place, but a Velcro strap works great, too!
The IMUs are connected to a Raspberry Pi using the I2C protocol. Although the Pi is bigger and has a higher power draw than, say, a Teensy board, we chose it because it was easy to stream data wirelessly from the Pi and monitor it during testing and calibration.
About 20 to 40 percent of the steps we take each day occur in bouts of walking that are 20 seconds or less.
The Pi, running a stock version of the standard operating system, also allowed us to use established Python libraries to do onboard data processing. We used the NumPy scientific computing library for storing data in a convenient format, and the Scikit-learn machine-learning library for analyzing motion data from the IMUs.
We trained a linear regression model to perform gait detection to segment each step and make an estimate of the calories burned. (Our Python scripts are available for download from a public repository.) We pull in sensor data at a fixed rate of 100 hertz. We determine when a step occurs by detecting when the leg stops rotating in one direction and starts rotating in the other direction, occurring around the time the heel touches the ground. Then we pass the leg motion from that step into our model that estimates energy expenditure.
This kind of direct analysis provides a much better way of tracking instantaneous energy expenditure over other measures such as heart rate or respiratory rate. These latter indicators take up to a minute to reflect changes in activity, so if you got up from the couch and walked 10 steps they wouldn't detect that movement. About 20 to 40 percent of the steps we take each day occur in bouts of walking that are 20 seconds or less, which contributes significantly to the total energy expended every day.
The red line shows how quickly the wearable system responds to the user starting and stopping different aerobic activities (from left to right: walking, running, stair climbing, bicycling). The stop is indicated by the dotted line in the middle of each activity.James Provost
We are currently working to create a more compact version of our calorie counter. We're interested in tracking energy expenditure over longer periods of time to hopefully improve weight management and sports training. What happens if you wear this device for a week or two at a time? We are also thinking about how we can integrate tracking upper-body activity by, say, looking at the motion of a paired smartwatch.
We plan to validate the data using the gold standard technique of so-called doubly labeled water, which lets us track energy expenditures on this kind of timescale very accurately. A subject drinks water containing deuterium and oxygen-18. Tracking how these are eliminated from the body in urine gives us the rate of carbon dioxide production, which is directly related to energy expenditure. In the even longer term, we hope to replace the current IMU boards with technologies being developed for flexible electronics that can be pressed on like a sticker or even possibly for direct printing on the skin.