Fighting Flickering LED Bulbs with Python and OpenCV

Background

I have been experiencing headaches and fatigue since I moved into my new apartment. I suspect that they are caused by the preinstalled LED light bulbs.

Flickering

Although high-frequency flickers are imperceptible to the human eye, prolonged exposure to a flickering light source may cause headaches and fatigue.

Physics

There are multiple reasons for flickering LEDs, e.g. PWM dimming and poor AC/DC converters (e.g. LED drivers).

PWM dimming is a way to adjust brightness on LED backlit monitors and other dimmable LED bulbs. Basically, the LED is turned on and off very quickly such that it lights up 70% of the time in average, which translates to 70% brightness. It is no longer used in modern LED backlit monitors.

LEDs are powered by DC instead of AC. While some LEDs connect to an existing DC circuit, other LED bulbs, e.g. GU10, connect directly to the mains. They use built-in LED drivers instead of external drivers for AC-DC conversion. The use of a half or full rectifier may cause flickering. For a 50hz mains, a half rectifier produces a 50hz flicker while a full rectifier produces a 100hz flicker.

Detecting flickers

Usually, you can easily tell there’s a low frequency flicker by quickly waving your hand under the light source and looking for a strobing effect. It should work for any flicker up to 80hz.

More sophisticated methods are required for detecting higher frequency flickers. For example, an oscilloscope may be needed to visualize the waveform and determine the frequency.

Verifying my hypothesis

I realize my smartphone camera has slow-mo mode (240fps) and super slow-mo mode (960fps). What if I shoot a video in slow-mo, measure the brightness of each frame and plot them with respect to time? That should do it.

Code

With the help of OpenCV and matplotlib.pyplot, it is actually not hard to get what we want.

Remarks: 1. The padding value exists to compensate some weird frame rates at the beginning and the end of the exported slow-mo video. 2. It records how often the brightness value of a frame crosses the mean video brightness to estimate the frequency.

Code:

Results

The suspected LED bulb, 240fps: flickering-240

duration: 2.2125s
estimated frequency: 100.1130hz
percentage diff: 27.8891%

A good IKEA LED bulb, 240fps: flickering-240

A 960fps video should give a better resolution of the waveform.

The suspected LED bulb, 960fps: flickering-240

duration: 0.3500s
estimated frequency: 101.4286hz
percentage diff: 27.5657%

The estimated frequency is 100hz. Considering the UK mains is 50hz, it is likely that the LED bulb uses a full rectifier to convert AC to DC, resulting in a 100hz flicker.

Conclusion

After replacing the bad GU10 LED bulbs, there are no more daily headaches and fatigue. Without this experiment, you can’t tell for sure what’s wrong. I’m glad I can apply the usual “measure, fix, verify” methodology in reality to eliminate this disturbing problem.

Appendix

There’s actually a metric called Compact flicker degree (CFD). It is not popular. No consumer knows or cares about it, and certainly no LED producer likes it. But here’s an example of a good citizen. It’s time the public learned the related health hazards and the producers built quality products. Flickering LEDs should be eradicated.

Tags// ,