ADCH samplerate

hi there,

based on this instructable: http://www.instructables.com/id/Arduino-Audio-Input/

i want to create an audio effect for guitar.

can i lower the sample rate of the ADCH dynamically? ideally i would like to lower it from the 38.5khz down to 1000hz continuously. i cannot do this with the prescaler. but can i somehow change the interrupt routine? i'm a bit lost. just checking if this is at all possible...

I can't answer your question... I haven't looked at the code so I don't know how the sample rate is set... But in general, lower sample rates are "easier". There is less data to process and it frees-up the processor to do more stuff.

ideally i would like to lower it from the 39.somethingkhz down to 1000hz continuously.

Are you sure about that? Are you familiar with [u]Nyquist[/u]. ...Basically, you have to sample the top-half of the "wave" at least once per cycle and the bottom once per cycle, so with a 1khz sample rate, the maximum audio frequency would be 500Hz. That doesn't cover the range of your guitar, even before considering harmonics... It's not even good enough for voice![/b] (The traditional telephone sample rate it 8kHz.)

And, you have to low-pass filter before sampling, or you'll get [u]Aliasing[/u] (false "non-musical" frequencies).

thanks for your answer. and yes i'm very sure about it :slight_smile: basically i want to implement a sample rate reducer, with aliasing etc... i know nyquist quite well, he is my musical friend :slight_smile:

OK it is your project but what are you hoping to achieve, what do you think it will sound like other than a mess.
If you want a mess that is fine, but it will not sound musical. I say this as one who goes to live gigs of noise, clicks and the odd beep for fun.

44kSPS is a reasonable sample rate for an audio processor. 1kSPS is most definitely not going to work except
on a bass synth output band limited to about 300Hz with a really good brick-wall filter, which is just
crazy.

Do the decimation in software for low-pass filtering, a FIR low-pass followed by decimation can be
optimized to only apply the FIR once per output sample, not once per input sample.

However you then need to oversample and low-pass filter again to reconstruct the output samples.

It may well be simpler to work at 44kSPS/38.5kSPS throughout.

The circuit given in that instructible is wrong BTW. No surprise of course.

yes, i know how it sounds. i have a performance degree in jazz music and i am a professional musician. i like the sound and it can be very musical, believe me. you can for example use the samplerate reducer like a filter. so if you adjust the sample rate with an adsr on an attack you can get very nice results... of course it will not stay at 1000hz all the time, unless you want that kind of ring modulated aliasing sound. it is also unbelievably cool for bass sounds. so ok, not just for guitar but also for bass guitar and even synths...

i already built such a device with dedicated hardware (adc and dac chips), but i want to create a programmable version that i can control via midi.

so, back to the original question, is it possible to adjust the sample rate dynamically in the interrupt?

but i want that sound! it has to be sample rate reduced. i don't want a clean nice signal.
i would not use the schematics on the intstructable site. have not even looked at it. i am able to do my own preamp and filtering at input stage, bias etc. i have built many pedals.

i just have never worked with arduino and this ADCH mode for the analog input.

so, back to my question. can you adjust the sample rate dynamically?

MarkT:
44kSPS is a reasonable sample rate for an audio processor. 1kSPS is most definitely not going to work except
on a bass synth output band limited to about 300Hz with a really good brick-wall filter, which is just
crazy.

Do the decimation in software for low-pass filtering, a FIR low-pass followed by decimation can be
optimized to only apply the FIR once per output sample, not once per input sample.

However you then need to oversample and low-pass filter again to reconstruct the output samples.

It may well be simpler to work at 44kSPS/38.5kSPS throughout.

The circuit given in that instructible is wrong BTW. No surprise of course.

ok, that is a start. but would that not mean that i can only get half the sample rate or a third etc? processing every n-th input sample only? i already tried this approach (just outputting every n-th sample) and it works, but control range is obviously very limited. or can you elaborate a little more? how would you decimate the sample rate smoothly? as i said lowpass filtering is not what i am after, since the signal should alias on lower sample rates... i also tried some software versions that use sample and hold to achieve kind of sample rate reduced sound, but it sounds not the same.

is it possible to adjust the sample rate dynamically in the interrupt?

Yes just set the interrupt to go less often on a timer and read the A/D in the ISR.

ok, thanks so i have to replace the ADC_vect with a timer..

ok, will read up on how to set a timer at runtime to a desired frequency.

lokki:
but i want that sound! it has to be sample rate reduced. i don't want a clean nice signal.
i would not use the schematics on the intstructable site. have not even looked at it. i am able to do my own preamp and filtering at input stage, bias etc. i have built many pedals.

i just have never worked with arduino and this ADCH mode for the analog input.

so, back to my question. can you adjust the sample rate dynamically?

ok, that is a start. but would that not mean that i can only get half the sample rate or a third etc? processing every n-th input sample only? i already tried this approach (just outputting every n-th sample) and it works, but control range is obviously very limited. or can you elaborate a little more? how would you decimate the sample rate smoothly? as i said lowpass filtering is not what i am after, since the signal should alias on lower sample rates... i also tried some software versions that use sample and hold to achieve kind of sample rate reduced sound, but it sounds not the same.

Decimation is the name of the technique, its not a secret.

Perhaps you should say what you are trying to do, "control range" doesn't make any sense to
me in the context of signal processing.

BTW the human auditory system is a pretty good spectrum analyzer, you cannot get away with
half-baked approaches as spurious signals are very easily detected by the ear even at very low
levels and are often very objectionable. This means paying attention to preventing aliasing and
keeping quantization noise and sampling time jitter under control - certainly for music signals.

[ sorry didn't see the comment at the top of your last reply - so you just want to generate quantization noise by sampling at a low rate, or you want aliasing and quantization? ]

i want both. i will lowpass the signal if needed in analog before it enters the adc. but i definitely want the ability to alias.

with control range i mean the ability to control the sampling frequency from 38.5khz down to 1000hz smoothly, by midi (14bit if necessary).

MarkT:
BTW the human auditory system is a pretty good spectrum analyzer, you cannot get away with
half-baked approaches as spurious signals are very easily detected by the ear even at very low
levels and are often very objectionable. This means paying attention to preventing aliasing and
keeping quantization noise and sampling time jitter under control - certainly for music signals.

[ sorry didn't see the comment at the top of your last reply - so you just want to generate quantization noise by sampling at a low rate, or you want aliasing and quantization? ]

i hear you :slight_smile: you don't want to count the times i had to deal with this stuff in some studio because of some cheap interfaces or similar.

Hmm, the sampling rate could be controlled from a timer firing an interrupt, and you change the timer
period programmatically to adjust the rate. There will be jitter in the interrupt timing due to the fact
different instructions take different numbers of cycles and the interrupts only happen between
instructions. But more importantly the ADC samples are constrained to be synchronous to the
analog clock on the ATmel processors, which is a divided down from the system clock (by default
its 125kHz).

I think thats really going to hamper the resolution of sampling rates, even if the analog clock is
run a lot faster.

An external SPI ADC chip might be better, and it could be 12bit or better too.