Pages: [1]   Go Down
Author Topic: Arduino Audio Filter  (Read 3135 times)
0 Members and 1 Guest are viewing this topic.
Planet Earth
Offline Offline
Karma: 0
Posts: 36
I hope I didn't brain my damage...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi everybody,

Well I've been trying to build an audio filter on arduino, which takes in input from a mp3 song (thru a 3.5mm jack on d arduino), then filter out the different frequency ranges like the bass (<400hz), vocals (400hz - 5khz) and treble (>5khz).

The input audio signal after giving a DC offset is fed to the ADC of the arduino.

At first, I thought maybe go with three filters, low pass, high pass and band pass. But then i thought of using arduino itself to process the signal directly using FFT or some algorithm.

The problem is I'm not able to program it. Please help me in getting the FFT to identify and differentiate these frequencies.

btw, i posted something similar to this earlier, sorry for that.

Wales, UK
Offline Offline
Karma: 0
Posts: 37
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I too could do with a littl ehel on this subject.

Ive Coded the aruino to accept audio input and output it using one of the PWM pins at a very high rate by changing the regester values.

My next step is to manipulate this data. I want to be able to filter this input to only output iether a bandwidth set digitally in the code, or just 1 single frequency.

Ive been reading into fft, but have yet to find something native to the arduino.

Ive been thinkin about designing my own code that would measure the incoming signal and compare it to previous samples to determin the peek and trough of the wave, I could than calculate the time between these waves to determin the frequency. However this seems too slow, and by the time ive done this alagarithm would I be to late to decide wether the signal should be filtered or not.

Here is the code I am runing on the arduino atm.
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))      //AnalogRead Settings
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))      //AnalogRead Settings

// vars altered by interrupt
volatile boolean f_sample;
volatile byte badc1;
volatile byte ibb;

void setup()

  // set adc prescaler  to 64 for 19kHz sampling frequency
  cbi(ADCSRA, ADPS2);
  sbi(ADCSRA, ADPS1);
  sbi(ADCSRA, ADPS0);

  sbi(ADMUX,ADLAR);  // 8-Bit ADC in ADCH Register
  sbi(ADMUX,REFS0);  // VCC Reference
  cbi(ADMUX,MUX0);   // Set Input Multiplexer to Channel 0

  // Timer2 PWM Mode set to fast PWM
  cbi (TCCR2A, COM2A0);
  sbi (TCCR2A, COM2A1);
  sbi (TCCR2A, WGM20);
  sbi (TCCR2A, WGM21);

  cbi (TCCR2B, WGM22);

  // Timer2 Clock Prescaler to : 1
  sbi (TCCR2B, CS20);
  cbi (TCCR2B, CS21);
  cbi (TCCR2B, CS22);

  // Timer2 PWM Port Enable
  sbi(DDRB,3);                    // set digital pin 11 to output

  cbi (TIMSK0,TOIE0);              // disable Timer0 !!! delay is off now
  sbi (TIMSK2,TOIE2);              // enable Timer2 Interrupt

void loop()
  while (!f_sample) {         // while f_sample = 0, waiting for input

  OCR2A=badc1;                // output audio to PWM port (pin 11)


ISR(TIMER2_OVF_vect) {

  PORTB = PORTB  | 1 ;

      badc1=ADCH;                    // get ADC channel 0

ibb++;                          // short delay before start conversion

sbi(ADCSRA,ADSC);               // start next conversion

Thanks, Phil.
« Last Edit: September 11, 2010, 05:30:48 am by philwalker » Logged

Offline Offline
Edison Member
Karma: 0
Posts: 1103
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Pages: [1]   Go Up
Jump to: