In order isolate the user from the 110 V ground line from the MCU power supply to guarantee user safety, the circuit in
Figure 3 is used. The linear optocoupler (IL 300) is fed back into a control amplifier which determines the output of the
LED in the IL 300. This controls the behavior of the photodiodes in the optocoupler to follow the input signal. By setting the
two resistors (R1 and R2) equal to each other, we obtain a unity gain so the output signal equals the input signal. Since the
purpose of this circuit is to isolate the input signal to the user, we must be sure to use the rails from the microcontroller
unit on one side of the optoisolator and a separate set of power rails for the other side.
The first stage of this circuit is the current source that takes in the isolated 50 kHz signal and generates a 10 uA
current source at 50 kHz frequency. The resistor from the negative terminal to ground (R3) is in parallel with the human
impedance which forms a divider. This allows us to choose R3 so that the we can always get the correct constant current
across the electrodes.
The second stage of this circuit is the voltage subtractor which gives us the voltage across the electrodes (represented
by the resistor labelled as human impedance). By making resistors R4=R5=R6=R7, the circuit behaves as a unity gain
differential amplifier so the output of this amplifier is simply the voltage difference of the two electrodes.
In order to generate the +4.5 V and -4.5 V rails, the circuit in Figure 5 was used. The 9 V battery is essentially
split into the two rails through the voltage divider (the two 100 kOhm resistors) with the output of the operational
amplifier acting as our virtual ground. The 1 uF capacitor removes noise in power rails. This way, these isolated rails
can be used for the IL 300 (linear optocoupler) and the human impedance circuit.
The isolating circuit is the same as the one used previously. We need to use the power rails of the microcontroller
unit to provide a stable signal for the ATMEGA1284. Resistors R9 and R10 are equal to each other to ensure unity gain
since we want the output to be the same as the input. We need a low pass filter was used to smooth out the signal so
the microcontroller can perform calculations on the data from the signal.
The software component for this project consisted of two parts - a realtime system for user input and bioelectrical voltage analysis,
and a MATLAB script to create a regression curve correlating body impedance and user body fat.
Fig.8 Realtime process threads
I/O System and TinyRealTime
The C code running on the microcontroller utilized the TinyRealTime kernel in order to run 3 tasks concurrently in real time. The three tasks included a body fat calculation task, an LCD printing task, and a serial communication task. Each task other than the user input loop had a specified release and deadline time, such that fat calculation ran ~25 times a second, and LCD communication ran ~5 times per second. These rates were chosen such that those tasks executed often enough to be observed easily by the user. The user input loop was not scheduled at certain times – rather, it executed when the user pressed enter in the UART terminal, which allowed for a faster and more intuitive user experience than scheduling the task. All shared variables in the program were protected using a single semaphore, SEM_SHARED, which allowed only one task to hold the semaphore at any given time. This prevented the variables from being overwritten while in use by a different task, which would hurt the correctness of the program execution. The idle task is initialized with a stack size of 80 bytes, which creates a stack for each task that is large enough that the tasks do not overwrite each other’s stacks. Additionally, the given trtSettings.h file was modified to work with the 16 MHz crystal of the ATMega1284P rather than a 20 MHz crystal.
The program took user input from a UART terminal using PuTTY, set to 9600 baud rate to match the transmission rate of the microcontroller. At the command line, the user was able to enter three parameters: weight, age, and gender. Weight was required to be in pounds, and gender used a binary encoding, 0 for female and 1 for male. With this system, the user could change parameters at any time during program execution, giving a significantly faster response time than a state machine based approach.
Body Fat Calculation
In order to collect body fat measurements, we required a 50 kHz signal to pass through the body. Using timer 0, we set the prescaler to divide by 8, the output compare register to 20, and enabled interrupt on overflow. These settings would cause timer 0 to run at 2 MHz, and trigger the overflow interrupt at every 20 ticks. By toggling pin B3 in the timer 0 overflow interrupt, pin B3 output a square wave with a frequency of 50 kHz. Additionally, this frequency would be easily customizable for potential multi-frequency analysis - by simply modifying the output compare register, one could easily generate dfferent frequencies of square waves.
The other important piece of software setup required turning on an ADC input, to retrieve the output voltage from the circuit. The ADC was set to be left adjusted, and compared to AVcc, which was hooked up to the 5 volt Vcc of the microcontroller. The output voltage from the circuit was connected to the ADC at pin A0, and was read every time the body fat calculation task was executed. Since the regression equations used to calculate body fat utilized the ADC conversion of voltage as one of their parameters, the value read from the ADC was simply used directly to calculate body fat. As a design note, the original software design sampled the ADC input, and kept track of when the input voltage repeated, in order to determine signal rise time. The signal rise time was used to calculate the imaginary, reactance component of the subject's body. When we determined that there was no discernable change in accuracy, we decided to eliminate this component from the calculation in order to preserve speed of execution. The low-passed output signal from the body provided the real, resistive component of the signal.
MATLAB Script and Data Processing
A major part of being able to determine body fat involved determining how the impedance information collected from the circuit related to the subject's body fat. To create the body fat equations, we used the volunteer body fat, voltage, age, and weight data. This data was passed to the MATLAB function mvregress, which outputs a vector of coefficients that weight the independent variables (age, weight, and voltage) in order to closely match the collected dependent variable (body fat). Data sets for male and female test subjects were run separately, in order to create distinct equations for each gender, and for simplicity, the ADC input value was used instead of raw voltage. The advantage of this approach is that the MATLAB script utilizes the built-in multivariate regression function to relate several independent variables to one dependent variable, and the script can be re-run to obtain a new regression equation as the data set is expanded. The regression equations obtained were:
Males: body_fat = 0.0923 * weight + 0.1605 * age - 0.0263 * voltage
Females: body_fat = 0.1871 * weight + 0.5800 * age - 0.0920 * voltage
The greatest concern of any bioelectrical system is for the safety of the user. In this system, the greatest safety risk posed to the user lay with passing electrical current through the body. Since we needed to pass current through as much of the body as possible, current passed through vital organs ike the heart, which required us to be very careful with how much current we were passing, Generally, from our research, we learned that current through the body for bioelectric impedance analysis is limited to the microamp range, and we decided to shoot for ~10 uA as the output from our current source to the subject. In practice, we achieved a consistent amplitude of approximately 12 uA for the signal passed into the user, which fit our safety requirements. Additionally, all users that tried the device reported no discomfort or strange sensation from the current being passed through the electrodes to their body.
The accuracy of the device was found to be reasonable within a certain range, but poor outside that range, due to the calibration data that we collected to create the regression equations. In order to make the body fat equations, data was collected from 12 subjects - 7 male, and 5 female. All subjects were within the ages of 20-22, with an average age of 21. Since there was little to no variation in age, the algorithm wuld only work well on people in that age range. Within males, there was little deviation in weight as well - 5 of the 7 male subjects weighed between 160 and 170 pounds. Females also had similarly restricted weight range. With a greater range of test subjects, accuracy can be greatly improved. Over all test subjects, the device's body fat prediction was higher than the caliper-measured body fat by .5 percentage points. This translates to an average percent error of 15%, which was higher than our goal of 10%. This increased error can be accounted for by test subjects who significantly differed in weight or body composition from the average test subject. The average percent error for male subjects was 20%, while average percent error for female subjects was approximately 8.4%, which can be accounted for by the presence of outliers in the data. Excluding outliers, average percent error for males was 9.2%. A larger test population that is more representative of the variation in human body composition would result in significantly greater accuracy.
Results vs. Expectations
The expectation at the start of the project was that the device would be safe, use a signal of ~10 μA and 50 kHz to determine body impedance, and predict body fat within a 10% error margin. The final circuit, while differing in certain respects from the original design, did achieve the safety and signal goals, while it conditionally achieving the accuracy goal. The device operated at a safe current and did not harm any of our test subjects. Our input signal to the user is approximately 12 μA, which is quite close to our goal of 10 μA, and is still safe to pass through a user’s body mass.
For our accuracy goal, we were able to achieve body fat prediction within a 10% error margin for subjects matching our test samples, but we had poor accuracy outside that fairly specific range of weights and body compositions. Given the small concentration of test subjects, we are pleased with the accuracy for the tested range, but there is significant room for improvement in accuracy for more body types.
This project provides many opportunities for future extensions. One extension would be to improve accuracy by implementing multi-frequency bioimpedance analysis. Each different frequency provides a different weighted sum of total body water and fat free mass, so by analyzing on multiple frequencies and comparing resistance and reactance measurements from each frequency, it is possible to obtain a more accurate result, as well as other metrics like hydration, muscle mass, and bone mass. This extension might be implemented by switching the software to a state-machine based approach, and modifying timer 0 to generate different wave frequencies.
Another possible extension would be to miniaturize the device and make it portable – this could allow for health conscious users to take it with them to the gym, for example. Modifying the device to work with conductive handles rather than electrodes would increase ease of use. In addition to the other changes, a logging system and linked application could be added to track body composition and hydration changes.
Intellectual Property Considerations
The hardware was all derived from several sources. The optocoupler circuits and the intuition behind them were based
from application circuit provide in the IL 300 data sheet. Our 10 uA current source is a modified non-inverting
amplifier which Bruce Land helped us with. Bruce also helped us develop the split supply for the 9 V battery.
Our software was mainly written by us with the exception of the Tiny Real Time (TRT) and trtUART libraries. TRT was
written by Dan Henriksson and Anton Cervin which were modified by Bruce Land to cater towards his ECE 4760 course.
trtUART was written by Joerg Wunsch.
Our project adheres to the IEEE Code of Ethics. We have both assisted each other in the development of this device in a
professional matter. Since our device uses collected data from volunteers In order to calibrate our device, we must
acknowledge that body fat percentage and obesity are sensitive matters. We must consider the stigma and discrimination
against obese people and we have agreed to keep the collected data anonymous and unreleased to the general public. We
have not bribed any of the participants as they are all volunteers. Each volunteer has agreed to be tested by our
device and was taught how to use the calipers in order to perform a three point skin-fold analysis. We treated all
volunteers without discrimination against race, religion, gender, disability, age, national origin, sexual orientation,
gender identity, or gender expression. We do not use user data in an unintended manner, and we do not profit from the use of their
data. All test subjects were given a verbal confirmation that their data would be not be used in any manner without their permission.
No individual was harmed or injured by our device as we made certain the safety
considerations with passing a current through a human. A 10 uA current source is well below the maximum current a human
can handle. We also agree that all the claims and estimates provided are honest and realistic and were given to improve
the understanding of technology.
Our project does not violate any legal considerations. All external libraries (trtUART and TRT) were properly licensed, and all materials used were purchased by us or taken from lab or as scrap with permission. All test subjects volunteered with no expectation or compensation, and we are not publishing any potential identifying data on this page, nor are we profiting from their participation in our project.
We would like to thank our instructor, Bruce Land, for his teaching and guidance throughout this project, and througout the ECE 4760 course. We would also like to acknowledge Dan Henriksson, Anton Cervin, and Joerg Wunsch, for their work on the software libraries we used in this project. Finally, we would like to thank our test subjects, who patiently underwent the testing process and agreed to let us use their sensitve data.
Finally, a public acknowledgement to the following testing volunteers who asked to be publicly acknowledged:
- Shiva Rajagopal
- Jake Streb
- Richard Quan