Lowering Capacitive Sensor Fluctuation in RGB Led Proximity

This is a fairly specific Instructable on how to embed a capacitive sensor in close proximity of other wires, here an RGB led. As part of a project I'm working on, I want to control an RGB led through a capacitive sensor. However, there's a problem: Blue and Green draw more power than Red, and the induction (I think) created by these electric flows influences the capacitive sensor. The solution presented below can be applied to anything else as well by simply swapping "color spectrum" for "possible states of the device", such as decibels on a speaker.

While I'm reading values from 0-2000 for "hand closeby" values, the readings fluctuate between 0 and 1000 depending on the color nearby LEDs are emitting (the power they're drawing). On the graph above, the horizontal axis represents all the colors of the color spectrum, while the vertical axis represents the values the capacitive sensor reads while nothing is nearby. The blue line represents these "steady state" readings. The highest spike is Cyan, where both Green and Blue are activated. Obviously, this at first seemingly random fluctuation makes any kind of control through nearby gestures impossible.

The orange line in the graph is the standard deviation, which comes in around 0.5%, indicating the fluctuations are definitely caused by the color spectrum and not thus are not all that random.

One solution would be to disable the led for a few milliseconds, measure, and re-enable it; but that diminishes the light output, so there must be a better solution. Instead, we'll set up an array of values to substract from the readings, depending on the color currently being emitted. This will effectively stabilize the readings output without affecting the led output.

Step 1: Collect Data by Cycling Through the Color Spectrum

For this instructable I'm using the Arduino code supplied in this instructable:

Now let your project cycle through all the colors a couple times. I ended mine after 100 iterations. Copy everything into an excel file, place the readings next to eachother by color and average them. Then map these values into a graph and voila! You have yourself all the erratic capacitive sensor values caused by the current differences along the color spectrum. You could do this by hand, but this bit of excel macro significantly eases the process (assuming you pasted 100x360 color values in column A and pasted measured values in column B) :

Step 2: Correcting Your Readings in Arduino Code

Now that we have the exact values of the error, we can simply substract them from our Capacitive sensor readings and the result will be very close to a nice, straight line around zero. As you can see in the first graph, the standard deviation of my 100 readings is ~0.5%, so the line will mostly fluctuate between -50 and +50.

Then while you're cycling through the color spectrum, in the following code, "k" is the time value cycling from 0 to 360 indicating what color is currently being projected by the LED. So simply substract them:

I'm constraining the values overall to zero because negative values are useless fluctuation to my project and generally just difficult to work with. You might slap on an extra -100 to account for the standard deviation.

I should note that for both the K_values readings and the CurrentReadings, I'm smoothing the past ten results into one by averaging them, because this gives a better stability level imo. This isn't really necessary, but I find it helpful. The code for that can be found here: https://www.arduino.cc/en/Tutorial/Smoothing

Also, if your project is short on memory, these arrays take up a lot of space. You can sacrifice some detail to win space by dividing everything over 5 (mapping them to values below 256) and using an 8bit array instead of a 16bit array; after which you remultiply the values in your code. Don't think this would impact performance.