ADC Noise Software Solution.

9 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


*/

x0 = in_ADC0;

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

d0=y0;


x1 = in_ADC1;

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

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

Please Log in to join the conversation.

9 years 10 months ago #203 by shanemikel
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.

Please Log in to join the conversation.

9 years 10 months ago - 9 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 :guitarfende :pedalmxr: :ampmarshall during this week,
Cheers! ;)

Please Log in to join the conversation.

9 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

Please Log in to join the conversation.

9 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.

Please Log in to join the conversation.

9 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

Please Log in to join the conversation.

9 years 10 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.

Please Log in to join the conversation.

9 years 9 months ago - 9 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:

// Licensed under a Creative Commons Attribution 3.0 Unported License.
// Based on rcarduino.blogspot.com previous work.
// www.electrosmash.com/pedalshield


int in_ADC0, in_ADC1; //variables for 2 ADCs values (ADC0, ADC1)
int POT0, POT1, POT2, out_DAC0, out_DAC1; //variables for 3 pots (ADC8, ADC9, ADC10)
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()
{
//ADC Configuration
ADC->ADC_MR |= 0x80; // DAC in free running mode.
ADC->ADC_CR=2; // Starts ADC conversion.
ADC->ADC_CHER=0x1CC0; // Enable ADC channels 0 and 1.

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

void loop()
{
//Read the ADCs
while((ADC->ADC_ISR & 0x1CC0)!=0x1CC0);// wait for ADC 0, 1, 8, 9, 10 conversion complete.
in_ADC0=ADC->ADC_CDR[7]; // read data from ADC0
in_ADC1=ADC->ADC_CDR[6]; // read data from ADC1
POT0=ADC->ADC_CDR[10]; // read data from ADC8
POT1=ADC->ADC_CDR[11]; // read data from ADC9
POT2=ADC->ADC_CDR[12]; // read data from ADC10

//USE IT HERE

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

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


//Add volume feature with POT2
out_DAC0=map(in_ADC0,0,4095,1,POT2);
out_DAC1=map(in_ADC1,0,4095,1,POT2);


//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

Please Log in to join the conversation.

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

Please Log in to join the conversation.

8 years 1 week ago - 8 years 1 week ago #652 by Ray
Replied by Ray on topic ADC NOISE SOFTWARE SOLUTION!
We did not make much progress here... maykef published some code but we tried them without much success.
In theory it should be simple, just summing some samples before releasing them should filter the high freq noise.

Please Log in to join the conversation.

Time to create page: 0.104 seconds