
Reverse Engineering a Real Candle - liyanage
https://cpldcpu.wordpress.com/2016/01/05/reverse-engineering-a-real-candle/
======
stygiansonic
The part about the harmonic oscillation frequency in the flame flicker is most
interesting:

" _The frequency of these oscillations seems to be around 5 Hz, drifting up,
and seems to be a fundamental parameter of the flame since it appears to be
relatively constant in all observations._ "

It appears that some (optical) flame detectors work by obtaining the frequency
of this flicker: [1]

" _This flame scanner also monitors the rate of combustion by analysing the
flicker frequency, or the fingerprint, of the flame... Since the flame is
always burning back to the fuel source, the flame is always in motion. This
motion allows the intensity of the flame to vary across a flame flicker
frequency spectrum._ "

From that link, it appears that the "flicker frequency" would be related to
the exact fuel source and possible fuel/air mixture ratio, as the "flame is
always burning back to the fuel source".

Some other information about flame frequency-flicker: [2]

" _Under normal gravity conditions, the flames have a well defined oscillation
frequency which is inversely proportional to the square root of the burner
diameter, D, and to a good approximation can be written as f » 1.5 /D½, with D
given in meters._"

So, it would indeed seem that the flicker frequency is related to the
particulars of the candle, its wick, etc.

Very interesting article!

1\. [http://www.coen.com/wp-
content/uploads/2010/05/HydrocarbonWo...](http://www.coen.com/wp-
content/uploads/2010/05/HydrocarbonWorld.pdf)

2\. [http://www.dantecdynamics.com/flow-characterization-of-
flick...](http://www.dantecdynamics.com/flow-characterization-of-flickering-
methane-air-laminar-diffusion-flames-using-piv)

~~~
megalodon
This reminds me of the quote "How much can the ripples tell us about the
object that fell in the water?"

~~~
semi-extrinsic
Or even the famous question "Can you hear the shape of a drum?", to which we
have a constructive proof (under some mathematical idealizations) that the
answer is " No".

[https://en.m.wikipedia.org/wiki/Hearing_the_shape_of_a_drum](https://en.m.wikipedia.org/wiki/Hearing_the_shape_of_a_drum)

~~~
Retric
That's been simplified enough to distort the question. Real listeners are not
limited to simple observation of frequencies they can move there ears around
to get a more 3d picture.

~~~
opless
*their

------
jedberg
This is awesome! Finally empirical evidence to back up what I've felt all
along -- that those fake LED candles don't look anything like a real candle
and are actually kind of distracting.

That animation at the end really sums it up nicely.

~~~
TranquilMarmot
I wonder if it would be possible to use this data to create an LED candle with
a super-sensitive microphone that would realistically flicker when
"disturbed", otherwise be a mostly consistent brightness.

Or are there better sensors than microphones to detect air disturbances?

~~~
detaro
hot wire aenometers can detect even tiny air movements

~~~
semi-extrinsic
But they're bloody expensive and quite fragile. The cheapest unknown-brand
ones I've seen on Chinese websites is ~ $100.

~~~
nomel
Oh come on. Some fine thermocouple wire wrapped around a literal hot wire
would be enough, no need to use industrial grade scientific equipment.

~~~
semi-extrinsic
That wouldn't give you anywhere near the resolution of an actual hot wire
anemometer. I'm fairly confident your instrument would be limited to measuring
"is the wind below or above 60 mph?", and would be unable to resolve changes
happening in less than ~ 10 seconds.

Real hot wires have a diameter of ~ 1/100 of a millimeter, that's the only way
to achieve any useful level of sensitivity.

------
jawarner
Great breakdown. The animation at the end is more convincing than any fake
candle I've seen. I'll make sure to use your model if I ever need to simulate
flame lighting in a game.

Nitpicking, but I think this is technically data modeling and not reverse
engineering.

------
dexwiz
I wonder how you could apply something like this to transition animations. The
simulated flicker ended up looking much better than the LED flicker.

Sometimes I see animations in UI. Some look completely natural, and some are
horribly jarring. I know there are all sorts of curves that tweening uses to
time its path. I wonder if reversed engineered curves would look better.

~~~
vvanders
It's almost always the case of using linear interpolation(which is what every
UX-naive developer reaches for) instead of proper ease-in + ease-out which
more appropriately models physical movement.

Even very subtle changes in the tangents of the curves can have drastic
effects and it's frustrating to see some platforms limit them to a few preset
curves.

~~~
SapphireSun
Sometimes you don't have bezier curves. I found a formulation of ease-in-out
that gives developers no excuses. ;)

[https://medium.com/analytic-animations/ease-in-out-the-
sigmo...](https://medium.com/analytic-animations/ease-in-out-the-sigmoid-
factory-c5116d8abce9)

~~~
vvanders
Good idea, but that exp() function makes my inner perf-nerd twitch a bit.

I'm personally a fan of pre-generating a fixed set of points that are linearly
interpolated and scaled. It has a few advantages:

- _Extremely_ cache friendly, can even be cheaper than computing a spline on a lot of platforms since it's essentially just a look up table.

-Your curve doesn't need to fit any specific formula(I.E. you can have a step function as part of it if you want).

-You can pull data from design applications to generate the curve allowing non-developers to have control over look-and-feel if you want to get that fancy.

~~~
SapphireSun
Don't forget, when you use these transitions, that computation is a very small
fraction of the animation as it's run once by the CPU. You can think of it as
setting a uniform on a shader.

The other reason I like using analytic functions is because: 1) You can easily
generate a linearly interpolated point set if you want, I've done it for CSS
in stylus (for spring animations that can't be represented by a single
bezier). 2) With the right formulation, it's very easy to tweak the shape as
it is in this case 3) You can analyze the functions easily

------
aidenn0
FWIW, the initial loss of brightness is almost certainly due to a reduction in
temperature a the fuel/air mixing piont. Blowing on a fire actually increases
the oxygen available.

------
iamleppert
Very interesting take on the subject. Of course, I think to simulate a real
candle, one would have to have some way of measuring air current. If I see a
fake candle flickering, and feel no air current, I'm going to be less likely
to think it's a real candle.

An LED candle the responds to its environment, could be "blown out" for
instance would make a great little hack project.

------
guitarbill
This is cool. Is the candle-flicker gif based on the algorithm, or the actual
output from the LED? Because I assume the LED will smooth out some features.
Vice versa, the LED probably needs to be driven with different data to produce
the equivalent brightness variation.

~~~
mrob
LEDs are extremely fast. The LED itself will add no perceptible smoothing. You
could easily add a capacitor for low-pass filtering, but that would add cost
so it's unlikely to be done.

~~~
pdkl95
I love how LEDs can flicker extremely quickly. Back in the early 90s when I
was working on HIPPI[1] network hardware, our crossbar switch had a 7-segment
LED display on each port that indicated the current destination. These LEDs
were actually updated synchronously. which worked surprisingly well as a debug
tool. You could send to multiple ports and see the port numbers blended on top
of each other in proportion to each ports data rate.

Years later, it seems blinkenlights[2] went out of fashion and everybody
started quantizing blink rates to 1s or 0.5s max. /sigh/ it's throwing out
useful information for no good reason.

[1] [https://en.wikipedia.org/wiki/HIPPI](https://en.wikipedia.org/wiki/HIPPI)

[2]
[http://www.catb.org/jargon/html/B/blinkenlights.html](http://www.catb.org/jargon/html/B/blinkenlights.html)

~~~
yuubi
I think quantized blink rates showed up around the time someone discovered
that rx/tx leds as usually implemented on dialup modems of the time leaked
data including passwords to anyone who could see the front panel.

------
TeMPOraL
The article[0] linked as an example of constrained random walk has a video
that's creepy and pretty unsettling. It's interesting how sprinkling some
randomness on things we're used to can make our brains go weird on us.

[0] -
[http://cnr.lwlss.net/ConstrainedRandomWalk/](http://cnr.lwlss.net/ConstrainedRandomWalk/)

------
OrdaGarb
I've had breadboards like his react to air flow. Those cheap ones especially
have such horrible connections that the slightest motion of flimsy part like a
resistor or LED wagging in the breeze will cause a significant change in
impedance where the leads meet the contacts.

Since this signal is dependent upon the series resistance, the output could
vary as a result.

------
miniatureape
Reminds me of:
[http://tomgerhardt.com/fireLight/](http://tomgerhardt.com/fireLight/)

------
knicholes
I can imagine feeding in the output of the photoresistor into char-rnn and
sample from that to "randomize" the light intensity.

------
baroa
I would buy an artificial candle that flickers when it detects air

