Monday 1 April 2013

sinewave generator with the DAC of the ARM SAM3X




On my adventures in Digital signal processing and sound synthesis, i started to do some experiments...
First was to do a sinewave generator with the DAC of the Arduino DUE and the timer interrupt at 4096 samples per second. I know its not much for the ARM core of the SAM3X chip that clocks at 84Mhz, but was a exercise more than anything. This is quite scalable, anyway !
Direct digital synthesis is a common technique for generating waveforms digitally. The principles of the technique are simple and widely applicable. You can build a DDS oscillator in hardware or in software.
A DDS oscillator is sometimes also known as a Numerically-Controlled Oscillator (NCO).
Usually we use a Circular buffer or FIFO.




The NCO function contains a sine look-up tables (LUTs) that perform the following functions:

sin(n) = sin(2πn/N)
where:
n = Address input to the LUT
N = Number of samples in the LUT
sin(n) = Amplitude of sine wave at (2πn/N)



Incrementing n from 0 to N causes the LUT to output one complete cycle of amplitude values for the sine  function. The value 2πn/N represents a fractional phase angle between 0 and . The time (t) required to increment n from 0 to N is the period of the sine  waveforms produced by the NCO function.

The LUT address is incremented once each system clock cycle by an amount equal to the phase input. The phase angle data is accumulated and stored in the phase accumulator register. The output of the phase accumulator register is used to address the LUTs.
The frequency (f) of the system clock (fCLK) is fixed. Therefore, the frequency of the sine waves is:

f = 1/t = fCLK × phase/2π.

 
As a taster of the code to come (Used the proverbial timer interrupt example code, and the old techniques on Direct digital synthesis available at places like interface.khm.de) .Ill leave you some pictures
Mine is the picture below (1st), below is the output of a grain synth , code available at rcarduino.blogspot.co.uk.
*The sinewave generator code i shall share is not the one at this link above, but an " original " one !.
Also had to mention the wicked BASIC program i been using to help me in my math algorithms  called "Decimal BASIC", available at  http://hp.vector.co.jp/authors/VA008683/english/.
The sine wave graphic at the top is from it !!




No comments:

Post a Comment

Feel free to contact me with any suggestions, doubts or requests.

Bless