2
$\begingroup$

A bit of background information: I plan to start experimenting with digital signal processing on microcontrollers. The particular microcontroller I plan to use (TI Stellaris LM4F230H5QR, from the Stellaris Launchpad) has a 12 bit ADC integrated on it, while on the other hand, all DACs I that look like possible candidates for me to use are 8 bit.

Obviously, before getting the output, I'll have to reduce the bit depth somehow. I could just get an 8 bit ADC and avoid the issue altogether, but I'd like to keep as much of the signal processing line at 12 bits as I can.

Questions: First, am I right in my assumption that by keeping 12 bits for as long as I can, I'll get better results?
Second, is there a smarter way of turning those 12 bits into 8 bits than just shifting everything to the right four times?

$\endgroup$
  • $\begingroup$ What frequencies are the signal and what sampling frequency? Depending on what you're doing you can use shaped dither to improve the SNR by moving the noise up into frequencies above the signal $\endgroup$ – endolith Jul 7 '13 at 18:06
  • $\begingroup$ @endolith Well currently the main purpose would be to play around with DTMF, so highest frequency should be 1477 Hz. From what I've read, common sample frequency for it would be 8 kHz. I'm also considering using a multiple of 8 kHz, since microcontroller can do hardware averaging on the sampled data. $\endgroup$ – AndrejaKo Jul 7 '13 at 18:22
  • $\begingroup$ I would guess that DTMF doesn't care much about SNR, but yes, you can probably improve it with noise shaping, such as sampling at 16 kHz and using dither that's shaped to put all the noise above 4 kHz. $\endgroup$ – endolith Jul 8 '13 at 16:25
3
$\begingroup$

The first thing I would enjoin you to do is to measure the actual accuracy of your ADC. The 12-bit performance announced by the manufacturer can often be reached only in ideal conditions, such as:

  • Using an external precision voltage reference rather than the built-in one.
  • Using a distinct power supply for the analog section of the MCU.
  • Using all the necessary EMI isolation/filtering parts as specified in the app notes... that your target dev. board might not have because of cost cutting (it can be as simple as a ferrite between VCC and AVCC).
  • Using slow sample rates.
  • Preventing any I/O pin to switch during acquisition (eg, disabling a SPI or UART spitting data in the background, disabling interrupts causing a GPIO to be toggled, disabling PWM peripherals..), or even putting the entire chip in sleep mode during acquisition.

In non-ideal conditions, I have seen ADCs lose up to 3 bit of precision. All this to say that your assumption that doing the processing with 12-bit data all along is correct as long as you truly have a resolution of 12-bit on your input; but if it's actually 8 bits because you are far away form the "sweet spot" of the ADC, there's no point keeping and processing 4 bits of noise all the way - you can just do the reduction at the source.

Converting from 12 bits to 8 bits through rounding or shifting is going to cause quantization noise correlated with your input signal. Dithering algorithms can be used to solve this problem and spread the quantization error. You also have the option of shifting the quantization noise in a frequency band where it is less harmful, through noise shaping methods.

$\endgroup$
  • $\begingroup$ I'm well aware of how optimistic front page datasheet specifications can be. Still I'm interested in theoretical solution to the problem. Do you perhaps have any additional info on how to practically implement dithering or noise shaping in audio? Almost all of Wikipedia references are behind pay-walls which I at the moment can't scale. $\endgroup$ – AndrejaKo Jul 6 '13 at 11:01
  • $\begingroup$ Some ready to use code here: musicdsp.org/archive.php?classid=5#95 ; musicdsp.org/archive.php?classid=5#61 ; musicdsp.org/files/nsdither.txt $\endgroup$ – pichenettes Jul 6 '13 at 11:09
  • $\begingroup$ It's worth noting that even if you are going from n-bit in to n-bit out you need to dither if you are doing processing in between because any non-trivial processing will increase the resolution of your signal. $\endgroup$ – Bjorn Roche Jul 6 '13 at 18:19
3
$\begingroup$

Questions: First, am I right in my assumption that by keeping 12 bits for as long as I can, I'll get better results?

Yes, you are correct.

Second, is there a smarter way of turning those 12 bits into 8 bits than just shifting everything to the right four times?

Sometimes. Signed shifting to the right four times is the safest way to go, because you are guaranteed not to cause any numerical overflow problems. Let's say, though, that due to processing gains or starting signal level that you know that the absolute value of the final 12-bit signal will either never be greater than 1023 or that it will happen seldom enough that you are willing to take the distortion hit that will come by saturating the signal when it does happen. Then you can get rid of the most significant bit (saturating when you need to to avoid numerical overflows) and shifting over three bits. This introduces less quantization noise.

Please note, though, that it is better to use as much of your dynamic range as possible (i.e. use all 12 bits) through AGC's and setting up the processing gain to be as close to 1 as possible at every stage and then shift down by four bits at the end rather than using less dynamic range and shifting less at the end.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.