Electronic – How to sample audio at Nyquist frequency with MSP430F5438

adcaudiodacsampling

I want to:

  1. Input an analog audio track

  2. Using the microcontroller ADC, convert it to a digital output

  3. Then have the microcontollers/boards timer sample the data at selected intervals

  4. Resample the "Sampled audio track" at twice the highest frequency content

  5. Convert it back to analog as a perfect reconstruction of the initial audio track

Using Fourier Analysis I will determine the highest frequency at which I will sample the track at.

It sounds easy enough and straight forward, but what I need is to program this in C and utilize my MSP430 chip/experimenters board to sample the track.
I'm going to be using Texas Instruments CCS and Octave for my programming and debugging. I am using the MSP430F5438 Experimenter Board.

Is C the right language for this? Can I get any examples of how to sample the track at Nyquist frequency using C? What code in C will tell the board to utilize the ADC component? And any recommended information that is similar or that will help me on this project.

Best Answer

You can do your entire project in a desktop PC. In fact, if I had to do it, I would start with the desktop:

  1. a .wav file is already sampled at a high frequency, often 44100 or 48000 Hz.
  2. determining the highest frequency can be done with an FFT. For prototyping, I would link FFTW.
  3. downsampling to an arbitrary frequency is a bit hard, because downsampling involves low-pass filtering. You need to set up a filter for each frequency. Look at libsamplerate and see how it sets up a SINC function to convolve against.
  4. Converting back to the original sample rate will involve another low-pass filter. See again libsamplerate.

I believe I would implement this in several passes, for ease of debugging:

  1. Get everything working in Matlab or Octave first. Octave has libraries to do all the filtering and Fourier analysis.
  2. Get everything working in C on PC, linking FFTW and libsamplerate for the downsampling / upsampling.
  3. Rewrite the C code with explicit-width variable types (e.g., int16_t instead of "short") and replace FFTW and libsamplerate with own code so that it compiles standalone.
  4. In C for the MSP430 or whatever DSP you've got, write interrupt routines to sample data on the ADC and output it on the DAC. Test that this works, just going from input to output.
  5. Take the working code from step 3 and compile it for the MSP430 or whatever. Then wedge it in to the working code from step 4 to operate on the sampled data between ADC and DAC.

This may seem like a lot of steps, but it is much more likely to make a working result than heroically coding everything up in one huge MSP430 application, then trying to debug it on the dev board.