BTW: as you can see in the video, the frequency response if VERY good. it recognizes frequencies up to 20 KHz
So I connected the Audio signal to A5 instead, and use A0 as noise reference.
QuoteBTW: as you can see in the video, the frequency response if VERY good. it recognizes frequencies up to 20 KHz No, it doesn't. What you are seeing is aliasing and this is very well understood. Any frequencies higher than 4.8 kHz present in the input get "folded" down into the range of 0-4.8 kHz.
Code: [Select]So I connected the Audio signal to A5 instead, and use A0 as noise reference.Frankly, I can imagine that working when A0 and A5 are sampled simultaneously, but that is not the case with arduino...
But I AM using an Arduino. An Arduino Uno to be exact, and it Does work, so I don't quite understand what it is that you are saying?
it Does work
But how come that when I sweep the tone generator to 20khz it shows up on the arduino's far right side?And anything beyond 20 khz starts to move to the left again?
But how come that when I sweep the tone generator to 20khz it shows up on the arduino's far right side? And anything beyond 20 khz starts to move to the left again?
I did not check the noise cancellation code, but in case there is a delay between A0 and A5 sampling, noise cancellation may not work properly.......That could be an illusion, unless you are an experienced dsp guy PS: As I wrote above, you need an anti-aliasing filter at the ADC input (low-pass), ie when using 20kHz sampling frequency the filter shall cut off everything above 10kHz.
QuoteBut how come that when I sweep the tone generator to 20khz it shows up on the arduino's far right side?And anything beyond 20 khz starts to move to the left again?You really need to read up on the theory and practice of sampling and FFT calculations. There is plenty of material on line. For example, look at the "sampling sinusoidal functions" and "folding" entries in this article: https://en.wikipedia.org/wiki/AliasingMany, many artifacts are introduced by the discrete nature of each procedure and until you understand those, refrain from drawing and publishing unwarranted conclusions. It will only make you look silly.
In past I used to use the Maxim's MAX740x low-pass filters, 8pin, 3.3-5V, 8th order, great for your anti- aliasing filter..http://www.maximintegrated.com/datasheet/index.mvp/id/1899PS: you must not use the external clock there, a single capacitor (see the datasheet) at CLK against Gnd will clock the filter at specific frequency (internal oscillator).
You're talking about using the Open Music Labs code. It works up to about 20 kHz because the sampling frequency is about 38.5 kHz. That code doesn't use analogRead() to get samples; it directly manipulates the ADC. ADCSRA is set to 0xE5: enable, start conversion, auto-trigger enable, and prescaler 5. On a 16 MHz Arduino, that sets the ADC clock to 500 kHz, and, with a conversion every 13 ADC clock cycles, the sample rate is about 38.5 kHz. The Nyquist frequency is about 19.2 kHz - close to 20 kHz. You can read about setting up the ADC in the ATMega328 datasheet, Chapter 24.You've noticed, I'm sure, that you don't get that kind of performance out of your "noise cancelling" code. That code uses analogRead() to get samples, and leaves the ADC clock at the default setting of 125 kHz, prescaler 7. The ADC isn't free-running, so samples take 13.5 ADC clock cycles, for a maximum sample rate of about 9.3 kHz, and a Nyquist frequency of about 4.6 kHz. There'll be some time lost between the end of one conversion and the start of another, so the rate will be a bit less than that. With sampling controlled by the program, rather than a hardware clock, there'll probably be jitter, but, with interrupts disabled, it may not amount to much.The results shown in the first post, with a bipolar sine signal directly coupled to the analog input, look about right. I'd expect the ADC to read zero for the entire negative half-cycle, and to track the input signal for the positive half-cycle, if it wasn't destroyed outright. Here's a link to a table of Fourier series, showing the coefficients for a half-wave rectified sine signal: http://people.clarkson.edu/~jsvoboda/Syllabi/EE221/Fourier/FourierSeriesTable.pdf. It has a DC component, a component at the fundamental, and decreasing components at even harmonics. That corresponds qualitatively with the initial results.
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?
You can read about setting up the ADC in the ATMega328 datasheet, Chapter 24.
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.
Quote from: aidvllasaliu on Mar 15, 2014, 12:44 pmHowever 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, Quote from: tmd3 on Mar 15, 2014, 01:38 amYou can read about setting up the ADC in the ATMega328 datasheet, Chapter 24.
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.