← Nesim Apps

Reading a Pulse From a Phone Camera: Filter, Peaks and Refusing to Guess

By Nesim Razon, independent mobile developer · 2026-11-17

#Algorithms#Android#Health

Pulselings estimates a resting pulse from the colour of a fingertip lit by the phone flash. The signal is tiny and the failure modes are many, so most of the work is not in finding the beats but in deciding when not to trust them. This is a walk through the pipeline in the app, with the numbers from the code. It is an engineering note, not a medical claim: the app is not a medical device.

The raw signal

Each camera frame is reduced to the average red value of the picture. With the flash shining through a fingertip, this number rises and falls very slightly with every heartbeat, because blood volume changes how much light is absorbed. More blood means less red reaches the sensor, so the useful wave is upside down: the code inverts it at the end of the filter, which makes the beats peaks.

Frames do not arrive at an even rate, and on some phones the rate changes during a measurement. The first step is therefore to resample the irregular samples onto a fixed 30 Hz grid with linear interpolation. Everything after that can assume evenly spaced samples.

Filtering without shifting the beats

The wave of interest is about 0.8 to 3.5 Hz, which is 48 to 210 beats per minute. Below that sits slow drift: the finger pressing a little more, auto exposure settling, a hand sinking. A first version used a moving-average high-pass, and it let a slow wobble around 0.7 Hz through. On one phone that wobble looked like a pulse of 42 to 50 beats per minute.

The fix was a second-order Butterworth band-pass from 0.8 to 3.5 Hz, applied forward and then backward. Running it both ways cancels the phase shift, so the peaks stay at the true time of the beat. Because a filter needs a run-in, the signal is extended at both ends by three seconds with a point-symmetric mirror, which avoids a jump at the edges, and one second is trimmed from each end of the result.

Finding the beats

Peaks are local maxima above a threshold of a quarter of the signal's standard deviation. Two peaks closer than 0.33 seconds, which would mean more than 180 beats per minute, are not both real, so only the higher one is kept. Each peak time is refined with a parabola through three points.

Then the app looks for the steepest rise in the 0.3 seconds before each peak and uses that moment as the beat time. A broad peak is noisy to locate, while a steep upstroke is sharper. The gaps between these times are the inter-beat intervals.

Deciding what to keep

Intervals outside 0.33 to 1.5 seconds, that is 40 to 180 beats per minute, are dropped. So is any interval that differs from the median by more than 30 percent. The share of intervals that survive is the coverage. The other ingredient of quality is how even the peak heights are: a clean signal has peaks of similar size, a messy one does not. Quality is the product of the two, from 0 to 1.

The app needs at least eight good intervals before it reports anything. The pulse is 60 divided by the average good interval. It then cross-checks against the frequency spectrum: if the time-domain result and the dominant frequency agree within 8 percent, fine. If they disagree, the peak picking probably went wrong, and the app either trusts the spectrum, if it is concentrated enough, or returns no number at all.

The wrong-but-confident reading

The worst bug is not a failed measurement but a successful one that is wrong. In one early test a phone gave 61 beats per minute with full quality, while a watch said about 100. The likely cause was a single steady rhythm that is not a heartbeat, such as light flicker or the camera's exposure cycle, which looks very clean.

Two guards came out of that. First, the app tries the red and the green channel and discards any channel that saturates, with values at 250 or above. Second, it looks at the ratio of green to red. With a finger that covers the lens, the real measurements had a ratio of 0.13 to 0.35, but the fake pulse had 0.52, because light was leaking around the finger and the picture was not dominated by blood-filled tissue. Above 0.40 the result is no longer counted as confident.

Say 'not clear' instead of guessing

A reading counts as confident only if there is a pulse, the quality is at least 0.8 and the green-to-red ratio is under 0.40. Otherwise the screen says it is not clear yet and keeps measuring, for up to about 85 seconds. A good measurement can end early, but only after the quality has passed three checks in a row and at least 15 seconds of data have been collected.

This is a deliberate trade. Showing nothing is a worse experience than showing a number, but a wrong number that looks reliable is worse still. The app also lets the user tag each result, so that a pulse after exercise is not compared with one at rest.

What we left out: variability in milliseconds

The same code can compute a heart rate variability value from the intervals. We measured it on the same person several times and got anything from 27 to 136 milliseconds. A camera at 30 frames per second, with a hand that is never perfectly still, cannot give a stable millisecond figure. So the app does not show it. Instead it compares today's pulse with the user's own resting average, and only after five measurements tagged as resting within 14 days, and it says plainly that this is not a medical result.

Testing it

The filter and the peak logic are plain Kotlin with no Android classes, so they run in ordinary unit tests. Some tests use synthetic waves with a known rate and noise. Others replay real recordings: every measurement the app makes can be saved as a CSV file, and a set of them is checked into the project as regression data. When the filter changed, those recordings showed at once which measurements improved and which did not.

Frequently asked questions

Why is the camera signal upside down?

More blood in the fingertip absorbs more light, so less red reaches the sensor at the moment of a beat. The filter inverts the wave so that beats become peaks.

Why filter forward and backward?

A filter delays the signal. Running it in both directions cancels that delay, so peaks stay at the real time of the beat.

What makes a reading count as confident in Pulselings?

A pulse value, a quality of at least 0.8 and a green-to-red ratio below 0.40. Otherwise the app says it is not clear.

Why does the app not show heart rate variability?

Repeated measurements on one person ranged from 27 to 136 milliseconds, so a camera at 30 frames per second cannot give a stable figure.

More from the blog