{"id":686,"date":"2013-12-15T14:13:24","date_gmt":"2013-12-15T21:13:24","guid":{"rendered":"https:\/\/inkofpark.wordpress.com\/?p=686"},"modified":"2024-09-01T20:07:12","modified_gmt":"2024-09-02T02:07:12","slug":"candle-flame-flicker","status":"publish","type":"post","link":"https:\/\/www.inkofpark.com\/?p=686","title":{"rendered":"Candle Flame Flicker"},"content":{"rendered":"<p>For a project I wanted to make an LED flicker like a candle. I searched for the signal statistics of candle flicker, and I found no data. One <a href=\"http:\/\/people.ece.cornell.edu\/land\/courses\/eceprojectsland\/STUDENTPROJ\/2001to2002\/pc59\/\/index.htm\" target=\"_blank\" rel=\"noopener\">student web site<\/a> suggests that candle flame flicker is a 1\/<em>f<\/em>-type random signal with roll-off of 20 dB per decade increase in frequency. Similar processes are typical for turbulence, so this student\u2019s plan seemed reasonable. However, the student did not discuss whether the signal is Gaussian or not, and did not describe the low-frequency characteristics of the signal. 1\/<em>f<\/em> noises may have a spectrum that follows the 1\/f curve to very low frequencies, but because they would require infinite power at <em>f<\/em>=0 they always have some lower frequency change. I had no data.<\/p>\n<p>Candles aren\u2019t hard to get, and I already had a silicon photodiode for an absorptive smoke density measurement system I\u2019m working on. I also had an analog-to-digital converter (ADC) in an ADS1015 on a breakout board from Adafruit. I made the very simple circuit shown below and attached it to a Raspberry Pi to sample the data. There are a lot more details, but those are later.<\/p>\n<p><a href=\"http:\/\/www.inkofpark.com\/wp-content\/uploads\/2013\/12\/circuit.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image:none;border-bottom:0;border-left:0;margin:5px;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;\" title=\"circuit\" border=\"0\" alt=\"circuit\" src=\"http:\/\/www.inkofpark.com\/wp-content\/uploads\/2013\/12\/circuit_thumb.png\" width=\"147\" height=\"226\" \/><\/a><\/p>\n<p>The voltage measured by the ADC is directly proportional to the current through the resistor. The current through the reverse-biased diode is directly proportional to the incident optical power. Very simple. I recorded a minute of data at a low 250 Hz sample rate, and subjected the data to analysis. The setup was a nominally dark room with the sensor a few inches from the flame. I flapped my hand at the candle to get it to flicker while recording.<\/p>\n<p><a href=\"http:\/\/www.inkofpark.com\/wp-content\/uploads\/2013\/12\/20131211-04.jpg\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image:none;border-bottom:0;border-left:0;margin:5px;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;\" title=\"20131211-04\" border=\"0\" alt=\"20131211-04\" src=\"http:\/\/www.inkofpark.com\/wp-content\/uploads\/2013\/12\/20131211-04_thumb.jpg\" width=\"644\" height=\"461\" \/><\/a><\/p>\n<p><a href=\"http:\/\/www.inkofpark.com\/wp-content\/uploads\/2013\/12\/20131211-06.jpg\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image:none;border-bottom:0;border-left:0;margin:5px;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;\" title=\"20131211-06\" border=\"0\" alt=\"20131211-06\" src=\"http:\/\/www.inkofpark.com\/wp-content\/uploads\/2013\/12\/20131211-06_thumb.jpg\" width=\"644\" height=\"461\" \/><\/a><\/p>\n<p><a href=\"http:\/\/www.inkofpark.com\/wp-content\/uploads\/2013\/12\/20131211-12.jpg\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image:none;border-bottom:0;border-left:0;margin:5px;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;\" title=\"20131211-12\" border=\"0\" alt=\"20131211-12\" src=\"http:\/\/www.inkofpark.com\/wp-content\/uploads\/2013\/12\/20131211-12_thumb.jpg\" width=\"625\" height=\"484\" \/><\/a><\/p>\n<p>The first graph below is a histogram of sample values.<\/p>\n<p><a href=\"http:\/\/www.inkofpark.com\/wp-content\/uploads\/2013\/12\/dfile_hist.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image:none;border-bottom:0;border-left:0;margin:5px;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;\" title=\"dfile_hist\" border=\"0\" alt=\"dfile_hist\" src=\"http:\/\/www.inkofpark.com\/wp-content\/uploads\/2013\/12\/dfile_hist_thumb.png\" width=\"644\" height=\"398\" \/><\/a><\/p>\n<p>The histogram is about normally distributed, but the right-hand tail is not Gaussian; it is too fat. In other words the candle is occasionally much brighter than normal. The time series (below) shows the same properties. There are clearly visible large excursions.<\/p>\n<p><a href=\"http:\/\/www.inkofpark.com\/wp-content\/uploads\/2013\/12\/dfile_time.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image:none;border-bottom:0;border-left:0;margin:5px;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;\" title=\"dfile_time\" border=\"0\" alt=\"dfile_time\" src=\"http:\/\/www.inkofpark.com\/wp-content\/uploads\/2013\/12\/dfile_time_thumb.png\" width=\"644\" height=\"398\" \/><\/a><\/p>\n<p>For human eyes the candle\u2019s flicker will be well represented if the frequency spectrum of the flicker and the distribution of the flicker approximately match a natural source. The spectrum below can be thought of as an average brightness (the peak at the left), a flat spectral region out to about 4 Hz, and then a 1\/<em>f<\/em>-style roll off at 44 dB per decade.<\/p>\n<p><a href=\"http:\/\/www.inkofpark.com\/wp-content\/uploads\/2013\/12\/dfile_psd.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image:none;border-bottom:0;border-left:0;margin:5px;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;\" title=\"dfile_psd\" border=\"0\" alt=\"dfile_psd\" src=\"http:\/\/www.inkofpark.com\/wp-content\/uploads\/2013\/12\/dfile_psd_thumb.png\" width=\"644\" height=\"398\" \/><\/a><\/p>\n<p>Numerically, we have the recipe for a flickering candle:<\/p>\n<ul>\n<li>Samples should be normally distributed with a standard deviation equal to 0.25 of the mean.<\/li>\n<li>The power spectral density of the signal should roll off at about 40 dB per decade with a 3 dB cutoff frequency around six cycles per second.<\/li>\n<\/ul>\n<p>To make this work on the Arduino using the pulse-width modulated outputs, we can further constrain the problem:<\/p>\n<ul>\n<li>The maximum value cannot exceed 255 counts\u2014or make the limit that the mean plus two standard deviations is 255.<\/li>\n<li>From this, we can derive that 2s+m = 255, use the fact that 0.25m=s to find that the mean m=170 and the standard deviation is about 42.<\/li>\n<li>A sample rate of between 30 and 120 Hz should be more than adequate to satisfy the Nyquist criterion for human vision (see <a href=\"http:\/\/en.wikipedia.org\/wiki\/Flicker_fusion_threshold\" target=\"_blank\" rel=\"noopener\">Wikipedia<\/a>).<\/li>\n<li>Values may not go below zero or above 255<\/li>\n<li>A second-order infinite impulse response (IIR) filter has a roll-off of 40 dB per decade<\/li>\n<\/ul>\n<p>If we can find a numerically efficient way to generate a time-series of Gaussian random variables inside the Arduino, filter them with a 2nd-order fixed-point IIR, scale them (if needed) then we should be able to make a flickering candle.<\/p>\n<p>Unfortunately, I have failed repeatedly to get a stable fixed point IIR filter. The cookbook solution specification above should be easy to implement, but I have not found it so. A better solution will have to wait for another post.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For a project I wanted to make an LED flicker like a candle. I searched for the signal statistics of candle flicker, and I found no data. One student web site suggests that candle flame flicker is a 1\/f-type random signal with roll-off of 20 dB per decade increase in frequency. Similar processes are typical [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,8],"tags":[17,25,44],"class_list":["post-686","post","type-post","status-publish","format-standard","hentry","category-making","category-nature","tag-arduino","tag-electronics","tag-raspberrypi"],"_links":{"self":[{"href":"https:\/\/www.inkofpark.com\/index.php?rest_route=\/wp\/v2\/posts\/686","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inkofpark.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inkofpark.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inkofpark.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inkofpark.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=686"}],"version-history":[{"count":1,"href":"https:\/\/www.inkofpark.com\/index.php?rest_route=\/wp\/v2\/posts\/686\/revisions"}],"predecessor-version":[{"id":1267,"href":"https:\/\/www.inkofpark.com\/index.php?rest_route=\/wp\/v2\/posts\/686\/revisions\/1267"}],"wp:attachment":[{"href":"https:\/\/www.inkofpark.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=686"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inkofpark.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=686"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inkofpark.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=686"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}