Devices & Components
Arduino Uno Rev3
MAXREFDES99# MAX7219 Display Driver Shield
SparkFun Electret Microphone Breakout
Project description
Code
Code snippet #2
text
1ISR(ADC_vect) { 2 uint16_t sample = ADC;samples[samplePos++] = sample - 400; 3 4 if(samplePos >= N) { 5 ADCSRA &= ~_BV(ADIE); // Buffer full, interrupt off 6 } 7}
Code snippet #3
text
1void goertzel(uint8_t *samples, float *spectrum) { 2 float v_0, v_1, v_2; 3 float re, im, amp; 4 5 for (uint8_t k = 0; k < IX_LEN; k++) { 6 float c = pgm_read_float(&(cos_t[k])); 7 float s = pgm_read_float(&(sin_t[k])); 8 9 float a = 2. * c; 10 v_0 = v_1 = v_2 = 0; 11 for (uint16_t i = 0; i < N; i++) { 12 v_0 = v_1; 13 v_1 = v_2; 14 v_2 = (float)(samples[i]) + a * v_1 - v_0; 15 } 16 re = c * v_2 - v_1; 17 im = s * v_2; 18 amp = sqrt(re * re + im * im); 19 spectrum[k] = amp; 20 } 21}
Code snippet #1
text
1void initADC() { 2 // Init ADC; f = ( 16MHz/prescaler ) / 13 cycles/conversion 3 ADMUX = 0; // Channel sel, right-adj, use AREF pin 4 ADCSRA = _BV(ADEN) | // ADC enable 5 _BV(ADSC) | // ADC start 6 _BV(ADATE) | // Auto trigger 7 _BV(ADIE) | // Interrupt enable 8 _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0); // 128:1 / 13 = 9615 Hz 9 ADCSRB = 0; // Free-run mode 10 DIDR0 = _BV(0); // Turn off digital input for ADC pin 11 TIMSK0 = 0; // Timer0 off 12}
Code snippet #2
text
1ISR(ADC_vect) { 2 uint16_t sample = ADC;samples[samplePos++] = sample 3 - 400; 4 5 if(samplePos >= N) { 6 ADCSRA &= ~_BV(ADIE); // Buffer full, 7 interrupt off 8 } 9}
Code snippet #3
text
1void goertzel(uint8_t *samples, float *spectrum) { 2 float v_0, v_1, 3 v_2; 4 float re, im, amp; 5 6 for (uint8_t k = 0; k < IX_LEN; k++) { 7 8 float c = pgm_read_float(&(cos_t[k])); 9 float s = pgm_read_float(&(sin_t[k])); 10 11 12 float a = 2. * c; 13 v_0 = v_1 = v_2 = 0; 14 for (uint16_t 15 i = 0; i < N; i++) { 16 v_0 = v_1; 17 v_1 = v_2; 18 v_2 = (float)(samples[i]) 19 + a * v_1 - v_0; 20 } 21 re = c * v_2 - v_1; 22 im = s * v_2; 23 amp 24 = sqrt(re * re + im * im); 25 spectrum[k] = amp; 26 } 27}
Downloadable files
schematics
schematics

schematics
schematics

Comments
Only logged in users can leave comments