Programmatically reducing jitter from a light sensor on a video monitor

I built a project that uses an ISL29125 RGB sensor connected to an Uno with a SparkFun MIDI shield to convert color and light to musical notes. It works fine in most aspects except when the light source is not continuous. With LEDs dimmed by PWM, fluorescent lights, or analog NTSC video screens, I get a variation in the reading from the pulse of the source. That jitter can carry over time as the sensor reading timing goes in and out of phase of the pulse rate of the light source. The timing ability of Arduino is not consistent enough to just hardcode the refresh rate of the video (60hz).

Can any folks here recommend a method of programmatically filtering out the scanline jitter and only yielding variations of brightness and color of the actual image on the screen?

Hardware setup:

Raw sensor readings, averaging red green and blue. Coarse jitter.

Smoothed average reading. Combines last 10 values and yields and average of that stack.

Attached is my basic INO to test smoothing options.

My end goal is to measure the changes in brightness of a video image on the screen, producing notes when it changes significantly. The video itself would produce a wide variety of values over time. Differentiating those value changes from inherent signal jitter is my challenge.

Suggestions?

rgb_normalize.ino (1.01 KB)

The jitter is caused by interference between the sampling rate and the signal (called "aliasing"). Google "sampling theorem" for detailed information.

To avoid that, you need to sample at least twice as fast as any possible variation in the input signal. You could try upping the sensor sample rate, and the I2C frequency from 100 kHz to 400 kHz, if the sensor supports it.

Edit: The 16 bit ADC conversion rate is about 10 Hz, but you apparently have only two options, 12 bits or 16 bits. The data sheet claims that the sensor "filters out" 50/60 Hz noise, but that requires you to set the integration time to match a submultiple of the source flicker frequency exactly. See the data sheet Noise Rejection section for the details.

For more control over the conversion rate, you may need to choose a different sensor.