Contact an Expert

Create Music using Frequency Modulation

Each musical note has a different frequency associated with it. To play a specific piece of music, you play the different frequencies for a certain duration and in a certain sequence. By modulating a sine wave with an arbitrary waveform, music can be created. Varying the vertical values of an arbitrary waveform allows different frequencies to be produced. By varying the number of points (horizontal) of the waveform, you can control the duration of the notes.

To simulate the musical notes, we'll generate a tone (a carrier) on the Keysight 33220A, then use the "arb" function as an FM signal to modulate the frequency of that carrier. We'll create a lookup table to translate from musical note to frequency and finally, we'll put it all into an interactive Microsoft Excel spreadsheet to generate the notes.

Choose a musical selection that can be replicated using the function generator. We will use the theme from Bach's Minuet in G to demonstrate the process. It is a good fit for the 33220A because it takes less than 500 seconds (the 33220A's slowest modulation rate) to play the entire selection. The piece you choose should not exceed this length, and less than 100 seconds is ideal. If you wish to convert your own piece of music, this article assumes a basic knowledge of how to read the notes.

Procedure:

Step 1. Define the musical notes in engineering terms. First, we need to convert note values to frequency and duration pairs, so the function generator knows how to interpret them. The downloadable file at the end of this article includes a table that shows the unique frequency value of each note.

Spreadsheet for converting musical note values

Also at the end of this article, you will find the Bach's Minuet (bach.xls) spreadsheet (see Figure 1) and the template we created for you (template.xls). You don't have to use the template, but we've automated many of the tasks to save you time.

For your spreadsheet, enter the value and octave of each note in the melody and the corresponding frequency. If you are using our template, corresponding frequencies are automatically assigned using the VLOOKUP function in Microsoft Excel.

To calculate duration values, find the tempo of the music (usually given at the beginning of a musical selection) and translate each note's beat length into time. In the case of Bach's Minuet, the tempo is 110 beats per minute with the quarter note receiving one beat. To convert this to seconds, multiply the beat of each note by 0.545 seconds/beat (60 seconds/110 beats). Your seconds/beat number will be different if your tempo is something other than 110 beats per minute. Record each note's duration in your spreadsheet.

Total your number of beats and the seconds in your duration column. You'll need these totals later.

Step 2: Determine modulation parameters. Next, convert the frequency and duration values into the frequency modulation parameters required by the function generator. First, pick a center (carrier) frequency. Start by finding the maximum and minimum frequency values of the notes. For Bach's Minuet, the minimum frequency is 293.7 Hz (D5) and the maximum frequency is 987.8 Hz (B6).

The carrier frequency should be set to half the sum of the minimum and maximum frequencies of the selection in order to be in the middle of the frequency range:

Carrier Frequency

= (minimum frequency + maximum frequency)/2
= (293.7 Hz + 987.8 Hz)/2
= 640.75 Hz

Deviation is the difference between the carrier frequency and the frequency limits of the music:

Deviation

 = Maximum Frequency  carrier frequency
 = 987.8 Hz  640.75 Hz
 = 347.05 Hz

Modulation Frequency is the repetition rate of the music, or the inverse of the amount of time it takes to play through the selection once:

Modulation frequency

 = 1/duration of selection
 = 1/52.364 seconds
 = 19 mHz

We will use these values to modify the instrument settings to output the "music" correctly.

Step 3: Define the arbitrary waveform. To create the arbitrary waveform, convert the frequencies you defined in Step 1 to arbitrary waveform values, and convert the beat values to points.

To determine the number of points necessary to play each note for the required duration, divide the waveform length by the total number of beats in the song. For this exercise, we will assume your waveform length is 4096 points. (The instrument can store up to 65,536 points in memory, but we are only using 4K in this example to save time during calculation.) There are 96 beats in Bach's Minuet.

Points per beat

= 4096 points/96 beats
= 42.7 points/beat
= 42 points/beat (truncated to the nearest integer so as not to exceed waveform memory by rounding)

The waveform controls the duration of the notes

Multiply the result by the beat count of each note to determine the appropriate number of points, and record that information in your spreadsheet.

Varying the vertical values of the arbitrary waveform creates the different tones of the selection. The highest note of the music (maximum frequency) corresponds to a vertical arb value of +1, the minimum frequency to 1, with all the other points scaled linearly between. Use the formula below to convert note frequency to the arbitrary waveform level (arb value).

Arb Level

= (Note Frequency - carrier frequency)/deviation
= (587.3 Hz - 640.75 Hz)/ 347.05 Hz
= -0.15401

Record the values for each note in your spreadsheet.

Once you have determined the arb value and number of points needed to represent each note, you have enough information to create the arbitrary waveform.

As you saw in Figure 2, a DC (horizontal) line segment represents each note. The duration of the note determines the length of each segment (number of points), and the note’s frequency determines its vertical position (arb value).

Step 4. Format your waveform (create a waveform record). Before you can download all the arb values into the 33220A, you need to format them in a consecutive string so the function generator can understand them. Your spreadsheet currently shows the arb value for each note and the number of times it should be repeated. You need to create a record that actually lists each value the correct number of times.

You could format the waveform manually (copy the arb value and paste it in a spreadsheet the correct number of times for each note). However, if you are using our template, you can do it automatically with a Visual Basic script that will copy and paste the points for you. Just hit the "Create Waveform Record" button. Your data will be formatted and recorded in the "Arb file" page of your spreadsheet.

Step 5. Download your waveform to the Keysight 33220A. Now you are ready to download the arbitrary waveform to the 33220A. You can either write a simple program or use the provided spreadsheet which utilizes VISACOM. VISACOM Drivers

First, connect the 33220A to the computer using either LAN, USB, or GPIB. (If you have not done this before or need assistance, please see the USB/LAN/GPIB Interfaces Connectivity Guide, or the 33220A User's Guide.) Connectivity Guide

If you are using the spreadsheet, click the "Set instrument address" button and enter the address of your instrument. Then, click the "Send to instrument" button. The waveform record on the "Arb file" page will automatically be sent to your instrument.

If you are writing a program, use the commands DATA VOLATILE for floating-point arb values or DATA:DAC VOLATILE for binary integer arb values:

DATA VOLATILE, , , , , , . . .

or

DATA:DAC VOLATILE, {|, , , , . . . }

More information on programming the 33220A can be found in the 33220A User's Guide English Version

Step 6. Play your music. Connect a speaker to the output of the 33220A, and modify the frequency modulation parameters to the values you computed in Step 2. Adjust the amplitude to control the volume and enjoy your creation!

This will also work on the Keysight 33250A 80 MHz Function/Arbitrary Waveform Generator without any modifications.

Conclusion

You can construct an arbitrary waveform and use it as a modulating waveform to generate a musical passage on a function generator. By varying the vertical values of an arbitrary waveform you produce different frequencies, and by varying the number of horizontal points of the waveform you control the duration of the notes.

Documents & Downloads

Bach's Minuet Spreadsheet 

Application Note 2004-03-25

null XLS 409 KB
Lab Template 

Application Note 2004-03-25

null XLS 245 KB
Frequency values for musical notes 

Application Note 2004-03-25

null XLS 47 KB