jremington:
tmd3 (reply #22) has it right. I haven't tried out the Open Music Labs code, but 8 bit sampling certainly does allow you to span the nominal audio range. As pointed out several times already, in all cases you really need an anti-aliasing filter preceding the input, so that frequencies greater than (ADC sampling frequency)/2 are greatly diminished in the input.
I will do that!
tmd3:
aidvllasaliu:
However despite using analogRead(), by adding "ADCSRA = 0xc5;" to the code, I still get the same amount of noise reductions while still having around 20kHz freq range.
What's going on here?
What's going on is this: by executing "ADCSRA = 0xc5,", you change the ADC settings, and change the way it works. The ADC prescaler is set to 5, selecting a system clock divider of 32, an ADC clock of 500 kHz, and a sample time of 13.5 ADC clock cycles, 27 microseconds. That corresponds to a maximum sample rate of about 37 kHz, and a Nyquist frequency of about 18.5 kHz. Because the ADC conversions are triggered by the program, rather than hardware, you'll lose some time in loop overhead and function calls, so the actual sample rate and Nyquist frequency, will be something less. You measured 15.5 kHz - something less than 18.5 kHz, as expected. That suggests that you're losing about 5 microseconds per conversion in software, or about 80 system clock cycles. That's probably not unreasonable.
Your posted code didn't manipulate ADCSRA, so it uses the default prescaler of 7, didviding the system clock by 128, for an ADC clock of 125 kHz, and a maximum sample rate of about 9.3 kHz. It aliases at something like 4 kHz. As expected.
If you want to know how the ADC control registers affect the way the ADC works,
tmd3:
You can read about setting up the ADC in the ATMega328 datasheet, Chapter 24.
I did read a little bit, hence I added "ADCSRA = 0xc5", but I guess I'll have to go a little bit more in depth in this area!
krass76:
try using a battery instead of your pc's 5V to power the arduino (I used a 7.2V racing pack). That did it for me.
What or who are you referring to? Please re-formulate
Now I have another weird problem.
I am trying to show the FFT on an Adafruit SSD1306 OLED display.
The FFT:ing is working OK in a separate sketch, the OLED:ing is working OK in a separate sketch, but when I combine the two
the OLED:ing does not work.
However when I comment out the FFT code in void setup(), the OLED:ing works perfectly fine.
Does anyone have any idea on what's going on here?
Logically thinking, the OLED:ing part does not have anything to do with the FFT:ing at all purely computation-wise, or pin-wise.
All I'm doing is plotting out the resulting FFT values to the OLED, but the OLED isn't even working once the FFT part of the sketch is running.
Out of RAM?
The sketch size is well below the chip limit.