8 years 10 months ago #199 by maykef
I finally found a simple way to remove noise from of Arduino ADC, using a recursive low-pass filter. See the code:

int y0, y1, x0, x1, d0 = 0, d1 = 0; // filter variables

/* Use these equations to calculate the filter coefficients:

decay= e^(-1/n)

n is the number of samples that produce an equivalent time to discharge a capacitor. I use 7.

b0=1-decay a1=decay

y = x*b0 + delay*a1

delay=y

*/

y0 = ((x0*15)/100) + ((d0*85)/100);

d0=y0;

y1 = ((x1*15)/100) + ((d1*85)/100);

d1=y1;
The following user(s) said Thank You: caleborion, shanemikel

8 years 10 months ago #203
Could you please elaborate a little here. For instance, I don't see where x comes from before you get to y=x*b0+delay*a1 . Also, you're using decay and delay (but where did delay come from?). I can't tell if that is code or pseudocode decay=e^(-1/n) is that e to the power of (-1/n) or binary arithmetic? If you could attatch a copy of a working sketch with this in it it would be easier for me to follow.

8 years 10 months ago - 8 years 10 months ago #204 by Ray
Replied by Ray on topic ADC NOISE SOFTWARE SOLUTION!
Thanks for your contribution ,I will try to code some examples and make some recordings during this week,
Cheers!

8 years 10 months ago #206 by maykef
Replied by maykef on topic ADC NOISE SOFTWARE SOLUTION!
X = CURRENT INPUT

Y = CURRENT OUTPUT

DECAY = PARAMETER TO CALCULATE COEFFICIENTS

DELAY = PREVIOUS INPUT

8 years 10 months ago #207 by maykef
Replied by maykef on topic ADC NOISE SOFTWARE SOLUTION!
Tip: This filter will make the signal a little more bass, so you have to test values for n, or add more gain on distortion effects.

8 years 10 months ago #208 by maykef
Replied by maykef on topic ADC NOISE SOFTWARE SOLUTION!
You will use these formulas to calculate the coefficients before you put them on the code

e = 2,71828183 It'S LIKE pi = 3,1415

8 years 9 months ago #211 by Ray
Replied by Ray on topic ADC NOISE SOFTWARE SOLUTION!

Rendering Error in layout Message/Item: array_keys(): Argument #1 (\$array) must be of type array, null given. Please enable debug mode for more information.

8 years 9 months ago - 8 years 9 months ago #219 by maykef
Replied by maykef on topic ADC NOISE SOFTWARE SOLUTION!
You must apply the filter immediately after storing the values of ADC, before any processing:

// Based on rcarduino.blogspot.com previous work.
// www.electrosmash.com/pedalshield

int LED = 3;
int FOOTSWITCH = 7;
int TOGGLE = 2;
int x_0=0, x_1=0, d_0=0, d_1=0; // NO NEED DOUBLE USE INT AND LONG
long f_0=0, f_1=0;

void setup()
{

//DAC Configuration
analogWrite(DAC0,0); // Enables DAC0
analogWrite(DAC1,0); // Enables DAC0
}

void loop()
{

//USE IT HERE

f_0 = ((x_0*13)/100) + ((d_0*87)/100);
d_0 = (int)f_0;

f_1 = ((x_1*13)/100) + ((d_1*87)/100);
d_1 = (int)f_1;

//Write the DACs
dacc_set_channel_selection(DACC_INTERFACE, 0); //select DAC channel 0
dacc_write_conversion_data(DACC_INTERFACE, y_0);//write on DAC
dacc_set_channel_selection(DACC_INTERFACE, 1); //select DAC channel 1
// dacc_write_conversion_data(DACC_INTERFACE, out_DAC1);//write on DAC
}
The following user(s) said Thank You: shanemikel

7 years 1 week ago #649 by BowDown
I am going to test this soon. What have other members found? Does this work?