# Tones produced by Fourier Synthesis

With the Arduino MEGA (either 2560 or 1280), you are able to control as much as sixteen potentiometers. In case you don't have a 2560 or don't want to use one or you don't have enough potentiometers, the code is still running on an UNO or NANO but you only have either 8 or 6 analog inputs. Accordingly, please reduce the CHANNELS constant. Using this, you can set the volume of sixteen harmonics of a base frequency. In this project we set the sample rate to 44 kHz (similar to the CD sample rate). As nobody will hear the 22 kHz we do not need a low pass filter.
And we decided the base frequency will be produced by 256 samples. That makes the ISR very easy. So, the base frequency will be 172 Hz, that is the musical note f(3). The potentiometer #16 enables a frequency of 2750 Hz.

 ```ISR(TIMER2_COMPA_vect) {  static byte w;  OCR1A = samples[w++]; } ```

Each time a potentiometer changes its value the 256 samples are recalculated and stored in an array which is read by the ISR.

 ```  for (int t = 0; t < 256; t++) raw[t] = neu0 * pgm_read_float(&sintab[t][0]);  for (byte k = 1; k < CHANNELS; k++) if (neu[k])      for (int t = 0; t < 256; t++)        raw[t] = raw[t] + neu[k] * pgm_read_float(&sintab[t][k]); ```

The sine values have been calculated before, using an Excel spread sheet and stored in a CSV file which can be read by Arduino (see The sine table at the very end).

That is how you get the sound.

The hardware part is not very sophisticated but simply a lot of work to be carried out thoroughly. Just use a prototype board designed for the ATmega2560. Mind you: there are different types of prototype boards; some of them do not provide the space you need for the potentiometers. If you take the right ones there will be sufficient space to mount all the components.

Pin 11 and GND go to the earphone jack.

Probably, you also want to see the spectrum corresponding to the values of the potentiometers and the time funktion of the sound produced. As this only changes when a value of a potentiometer changes these data can be plotted as a static picture.

As you can see the Serial plotter shows the frequency spectrum on the left and the time function on the right.

 ⇐The base frequency ⇐ one octave above ⇐ two octaves above ⇐ three octaves above ⇐ four octaves above ⇐ a square wave ⇐ a sawtooth wave

For diagnostic purpose we added pulses at pin-10 (44 kHz) and pin-13 (base frequency).

The source

contact: nji(at)gmx.de