Thus, solving for inc we find inc=fsine/resolution. This means that for a given increment inc, fsine = inc*resolution.
If each we raise the increment by 1, we get a 1.46e-5Hz change in frequency as given by the resolution formula. This formula describes the increment needed to produce a given sine wave frequency fsine. With the increment frequency given by Fs, this gives 62.5KHz / 216 =1.46e-5Hz resolution.
We can produce 1 sine cycle per accumulator overflow, thus with an increment of 1 and a 32 bit accumulator we can produce 1 sine cycle every 216 increments. Basically we are trying to find out how much the frequency changes when we change the increment by 1, or equivalently the frequency of the wave when the increment is 1. This formula relates the sampling frequency to the best resolution we can get in frequency, with x being the number of bits in the accumulator. This means that we can sample the sine wave at a maximum rate of 62.5KHz. This formula relates the sampling frequency of the sine wave Fs to the clock speed on the mega32. The required increment for each frequency was calculated using the following formulas: As we will see in the following calculations, the resolution of the DDS is set by the number of bits in the accumulator, thus we used 32 bits instead of just the minimum of 8. Notice that only the top 8 bits are used to retrieve a value from the sine table. The increment is added to this table at each cycle of the PWM. Instead of using the internal DAC through OC0, we decided to create an external DAC for accuracy (see Hardware Design). Once again, the maximum frequency we could generate was about 3.9KHz with 16 samples per wave. Since the sine table has 256 entries, we only use the upper 8 bits as a lookup index into the sine table, which holds 8 bit chars.
To improve accuracy, we use a 32 bit accumulator and a 32 bit increment. We still use the fast PWM mode on the Mega32's timer 0, an accumulator table, a 256 entry sine table, and an increment for the accumulator based on the desired frequency. Background Math Direct Digital Synthesis (DDS)ĭirect Digital Synthesis is implemented similar to the method used in lab 2, with some modifications. During scanning, the notes detected by the image algorithm are played using an enhanced version of the Direct Digital Synthesis (DDS) scheme presented to us earlier in the year.
In addition to the image processing algorithm, we designed a user interface from the PC to the MCU via serial port (using Windows Hyperterminal) with which the user selects the clef and key signature of the music to be scanned. The key to the success of our project was the structure of the musical staff, where the five parallel staff lines gave us a basis for orientation and note recognition. This allowed us to significantly decrease the amount of computation required by the microcontroller by taking advantage of the nature of musical notation. In order to get around some of the problems of image processing, we chose the well-defined application of reading music. High-Level Design Back to Topĭue to the performance limitations of the microcontroller, sophisticated image processing on the microcontroller is very difficult and thus is not often attempted. The Music Wand was developed and built as a design project for ECE 4760 in the Cornell University School of Electrical and Computer Engineering. The concept of a music-reading wand appealed to us because it would allow a novice musician to easily learn sheet music without the help of a musical instrument. We chose this project in order to explore image processing and sound synthesis on the microcontroller in a creative and practical context. For each note detected, a synthesized piano note is played at the detected pitch. The device uses a linear image sensor mounted on the end of a handheld wand to scan printed sheet music and identify the note pitches. The Music Wand is a device that optically reads printed sheet music in real-time and synthesizes the notes which are read from the page.