Importing Files and Playing “Scales”

Project 5: Waveform Generator

Importing Files and Playing “Scales”

Project 5: Waveform Generator


In this experiment, we will use the Analog Discovery's™ ability to import “custom” waveforms from a file. Custom waveforms do not fall into any particular category of common waveforms (e.g., sinusoids, square waves, and triangular waves all fall into broad categories—their names provide intrinsic information as to the basic shape of the waveform).

The Analog Discovery allows us to import waveforms from either .txt (text) or .csv (comma separated variable) files. These files can be created by other applications such as Microsoft Excel®, Microsoft Notepad®, or MathWorks MATLAB®. It is also common to record data in .csv or .txt format—thus, one can record a waveform using (for example) an oscilloscope and then use the AWG to re-generate the recorded signal. This allows ready testing of circuits under expected operating conditions.

In this project, we will import a waveform into the AWG which was created in Microsoft Notepad. The imported file will have a number of discrete “levels”—when we modulate the frequency of a sinusoid with this signal, we will get a signal which consists of a number of different frequencies. When we play this signal through our speaker, we will get a set of discrete tones which will sound somewhat like playing scales.

Before you begin, you should:
  • Be able to use the Analog Discovery waveform generator to apply Sinusoids and Swept Signals to a circuit.
  • State what file formats can be imported to the Analog Discovery waveform generator.
  • State how the period of a swept signal changes with time.
After you're done, you should:
  • Use the Analog Discovery waveform generator to import and play files.


Qty Description Typical Image Schematic Symbol Breadboard Image
1 Buzzer/Speaker
The Buzzer/Speaker in the analog parts kit has two terminals. If a time-varying voltage is applied between the terminals a film in the speaker vibrates, converting the voltage waveform to a pressure waveform with a similar "shape." Note: The speaker in your parts kit may have different markings than the one pictured.



If you have completed the Sinusoids and Swept Signals project and your circuit is still intact, feel free to skip to Step 2 of this exercise.

Step 1: Understanding the Circuit

A. Circuit Schematic

  1. Connect one terminal of the speaker to the W1 terminal of your Analog Discovery.

  2. Connect the other terminal of the speaker to a ground terminal on your Analog Discovery.

B. Create Circuit

  1. Insert the terminals of the speaker into your breadboard so that they are in different rows.

  2. Connect W1 (the yellow wire) to one terminal of the speaker.

  3. Connect ground (, the black wire) to the other speaker terminal.

Step 2: Set up Instruments

A. Open WaveGen Instrument

  1. Open WaveForms™ to view the main window.

  2. Click on the WaveGen icon to open the waveform generator.

B. Create a “Stair Step” Waveform Using Notepad

  1. Open up the Microsoft Notepad program on your computer. Type, on successive lines, the values: 1, 2, 3, 4, 5, 6. Save the result as steps.txt. The result should look as shown in the figure below.

Screenshot of Microsoft Notepad 2009 running on Microsoft Windows 7.

C. Import the File from Part B as the Baseband Signal

  • Note: At some point during the above steps, you may get a pop-up error message to the effect that “Output amplitude exceeds device limits”. You can ignore this message; it will get fixed when we disable Amplitude Modulation in a later step.

Step 3: Experiment

A. Create and Apply the Frequency Modulated Signal

The images above are screenshots of Digilent WaveForms running on Microsoft Windows 7.
  1. Click on Run AWG1 or Run All to provide power to your circuit. You should hear a series of “tones” of successively increasing frequency. If the sound is difficult to hear, use a set of headphones plugged into the audio jack on the back of the Analog Discovery to listen to the sound.

Interpreting the Data

The steps.txt file does not contain information relative to the sampling rate of the data it contains (that is, the AWG does not know how far apart in time to put the data points—it only knows that there are six data points). The AWG assumes that the data points are evenly spaced throughout the buffer. Thus, the data created by the AWG consists of six different levels, each corresponding to one of the levels defined in the .txt file, and each occupying one-sixth of the total time period.

Test Your Knowledge!

  1. The above sequence of tones doesn't really constitute musical “scales”. The frequencies of our tones are equally spaced; in scales, the frequency doubles between successive notes. Try playing a set of real scales by creating a text file whose successive values double (e.g. the values 1, 2, 4, 8, ...) and using this file to modulate a sinusoid.

  2. Put a pause between each of the tones in our project. You can do this by adding a “zero” between each of the values in our above text file (e.g. create a text file with the values 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6 on separate lines and using that file to modulate our sinusoidal carrier wave).
    • Does the result sound like you would expect? Why? (Hint: modulating a sinusoid with “zero” gives a signal with zero frequency—it's a constant. Speakers need a time-varying input to create an audible sound.)

  • Other product and company names mentioned herein are trademarks or trade names of their respective companies. © 2014 Digilent Inc. All rights reserved.
  • Circuit and breadboard images were created using Fritzing.