12
Laboratory 2 - Designing an Optical Theremin Team #2: Monstars Peter Lin, Matt Brewer, Kyle Emerson EE 300W Section 1

Optical Theremin Lab

Embed Size (px)

Citation preview

Page 1: Optical Theremin Lab

Laboratory 2 - Designing an Optical Theremin

Team #2: MonstarsPeter Lin, Matt Brewer, Kyle Emerson

EE 300W Section 1

Page 2: Optical Theremin Lab

Abstract

The task outlined in this lab was to create an optical theremin using both circuitry and LabVIEW programming components. Our design used photodiodes in order to detect the intensity of the light in the room. We then used the NI myDAQ in order to transfer the light intensity information from the circuit to LabVIEW. Within the LabVIEW program we were able to normalize the values of the input data. These values were used to generate a digital simulated sinusoidal signal. This signal was output using the myDAQ’s audio out jack, which allowed the simulated wave to be produced as an audio output. After completing the initial portion of the LabVIEW code we then added in code that would allow us to auto-tune the signal. The frequencies of the input signals were compared to the frequencies of a specific musical key and were coerced to fit within the key. This design is easy to implement, and is fairly simple to adjust.

Introduction

A Theremin is a purely melodic electronic musical instrument typically played by moving the hands in the electromagnetic fields surrounding two projecting antennae (http://www.merriam-webster.com/dictionary/theremin). The Theremin detects the distance of each hand from the antennae, which control the pitch and volume of the tone that is produced. An optical Theremin uses a similar concept, but instead of using the disruption of an electromagnetic field, it utilizes light intensity to control pitch and volume. This becomes possible by replacing the antennae with photodiodes. Our task was to create an optical Theremin with a detector circuit front end and signal processing in LabVIEW.

Rationale

A photodiode is a device that operates similarly to an LED. An LED takes a voltage or current and outputs it in the form of light, while a photodiode absorbs the light around it and then translates it to a voltage or current. The photodiode uses a PIN junction, which consists of a nearly intrinsic semiconductor region surrounded by heavily doped P and N regions. It is fairly simple to manipulate the amount of light that a photodiode absorbs, simply by obstructing the light source with your hand. This will make the operation of the optical Theremin akin to that of the normal Theremin.

The photodiode operates as a current source, which means that we need a way to convert those currents in to voltages before we input them into LabVIEW. A transimpedance amplifier is an op-amp configuration that will allow us to do this. We configured our op-amp to do so by tying the non-inverting terminal to ground. The

Page 3: Optical Theremin Lab

photodiode was placed so that the anode was tied to ground and the cathode was connected to the inverting terminal. A feedback resistor was placed between the output and inverting terminals of the op-amp completing the transimpedance amplifier and allowing us to convert the currents produced by the photodiode into voltages.

A myDAQ was used to read the input voltage values. LabVIEW was used to acquire these values from the myDAQ. LabVIEW also allowed the user to adjust the maximum and minimum light intensity levels and the range of frequencies. The LabVIEW front panel displayed the waveforms that show pitch as a function of time and volume as a function of time. It also displayed indicators that show the light intensities of the photodiodes.

Initial Block Diagram and Justification

At the most basic level (N=0) of the diagram only the inputs, the overall transformation, and the outputs are labeled. The system inputs are the amount of light being detected by the photodiodes, the range of the light intensity, and the range of the output frequency of the music produced: the latter two are user defined. The output of the system is a musical tone, which the user of the system is able to alter the pitch and volume of by altering the amount of light that each of the photodiodes detects. The second level (N=1) of the block diagram breaks down the transformation into three major components. The circuitry segment of the transformation provides the data to be input into the LabVIEW program. The LabVIEW code takes the information received from the myDAQ and manipulates it so that the desired output is obtained. The musical tones are then output using the myDAQ’s audio output jack.

Page 4: Optical Theremin Lab

The third level (N=2) of the block diagram breaks down each of the three main sections of the transformation further. The circuitry portion of the design is subdivided into a photodiode segment and an op-amp segment. The photodiodes are used to detect the amount of light that is around. The light is then converted to current and the op-amp, configured as a transimpedance amplifier, converts the current to voltage. The LabVIEW segment is broken into volume, pitch, and auto tune (own section) controls. The voltages provided by the circuitry portion of the design are normalized and placed in an array when entered into LabVIEW. The pitch and volume of the musical tone produced is proportional to the amount of light that each of the two photodiodes identify. The musical tone is output through the audio output jack on the myDAQ and is played through any speaker containing a 1/8” connection.

Implementation

The photodiodes used were the 365-1084-ND diodes. These photodiodes input current into an op-amp configured as a transimpedance amplifier. 2.2 mega ohm resistors were placed in the feedback loop of this amplifier, which converted the currents produced by the photodiodes into voltages. The voltages ranged from 0.04 v - 0.7 v when placed in normal ambient room lighting. This means that the currents produced by the photodiodes ranged from 18.2 nA - 318.2 nA. These voltages were then input into the myDAQ.

Circuit Board Layout

LabVIEW reads the values from the myDAQ for both photodiodes. The first value is used to set the frequency of the output tone while the second value is used to set the

Page 5: Optical Theremin Lab

volume of the output tone. The LabVIEW front panel allows the user to adjust both the light intensity levels and the range of output frequencies. It also displays the waveforms that control pitch as a function of time and volume as a function of time. The front panel displays numeric indicators of the light intensities of both photodiodes and allows the user to turn on or off the auto-tune feature. The auto-tune subVI allows the user to select a key for frequencies to be tuned to. Input frequencies will be adjusted to notes in the selected key before being output to the myDAQ.

Front Panel Display

LabVIEW Block Diagram Analysis

The autotune feature of the LabVIEW code allows the user to further place limitations on the audio signal that is produced. The user can select a particular key and have the output signal auto-tuned to certain frequencies that lie within key. The entire auto-tune subVI is encased within a case structure. If the case structure has an input that is false, then the input will be directly wired to the output (auto-tune is turned off in this case.) Otherwise, if the case structure has an input that is true, the auto-tune VI will run. The first structure in the auto-tune VI is a case structure that allows the user to select a key. Each key has a different array of seven values which correspond to that particular key. The

case structure selects a key based on an integer input, with each integer value mapping to a particular key (this map is shown with a comment.) Next, a for loop creates an array that repeats the frequency pattern of the key for the desired number of octaves.

Page 6: Optical Theremin Lab

This is done by multiplying each value in the input array by a power of two and appending it to the array. The completed array and input frequency are used as the inputs for the Threshold 1D Array Function. This gives the exact index value of the input frequency within the array (which is likely not an integer.) The resulting index value is rounded to the nearest integer. The output frequency is the value of the array that corresponds to the rounded index value.

Autotune Block Diagram

The amplitude control block diagram normalizes the measured input amplitude to be between 0 and 1 depending on the maximum and minimum amplitude ranges. The frequency control block diagram first normalizes the input frequency to the desired amplitude range, and then it normalizes this value to the desired frequency scale (dependent on desired maximum and minimum frequency ranges.) The max/min values for both amplitude and frequency are set by the user on the main front panel.

Optical Theremin without Auto-Tune

Page 7: Optical Theremin Lab

The autotune portion was written afterwards and added into the main block diagram as a subVI.

Optical Theremin with Auto-Tune

Frequency Control Amplitude Control

Description of Design Modifications

Throughout the design and testing phases of the project, our biggest challenge was determining the values for optimal sample rate and buffer size. The DAQ Assistant parameters needed to be adjusted to produce a smooth output signal, not a choppy, distorted signal. Both the DAQ Assistant Reader and DAQ Assistant Writer were configured to perform at optimal conditions. If the number of samples to read is too large, the DAQ will take longer to read all the samples since there is more information to process. This will cause a lag in the response time to the change in light intensity hitting the photodiode. Through some trial and error, we concluded that the DAQ Assistant would read 150 samples at 50kHz. For the DAQ Assistant Writer, we used continuous sample mode and adjusted the buffer size to produce a smooth sinusoidal output signal. If the sample rate is too low, then the output will appear choppy and distorted. However, if the sample rate is too high, then sample regeneration can occur.

Page 8: Optical Theremin Lab

Sample regeneration occurs when the DAQ Assistant writes information faster than it is receiving the information. The same signal is regenerated and this produced an error from the program. The buffer size needs to be chosen strategically because as it increases the slower the program runs and the more RAM is being used. In the final design, the number of samples written was 30,000 samples at a rate of 80 kHz.

Another modification we made was the resistor value of the feedback resistor used in the transimpedance amplifier. In order for the optical theremin to be used in a wide range of lighting settings, we needed the gain of the amplifier to be very large. After

adjusting light intensity, we tested several different resistor values including 510k ,

1.1M , and 2.2M . The After some trial and error with the resulting voltages (which

depends on the ambient light,) we decided on two 2.2 M resistors for the gain of the

two transimpedance amplifiers.

Conclusion

An optical theremin, a musical instrument that can be played without physical contact, was designed and implemented. The myDAQ acquires a voltage signal from the transimpedance amplifier circuit that depends on the light intensity incident on the photodiodes. LabVIEW processes this voltage signal and outputs a sinusoidal wave through the audio output jack on the myDAQ. The result is a system that outputs a sound wave that can be can be adjusted by volume or pitch based on the light intensity that hits two photodiodes.

Page 9: Optical Theremin Lab

Appendices:

Bill of Materials:365-1084-ND photodiode: $0.59 per unit (2)TL074 Op-Amp: $0.59 per unitNI myDAQ: $179.002.2 MOhm Resistor: $0.01 per unit (2)0.1 uF Capacitor: $0.02 per unit (2)LabVIEW software (student edition): $20.00Breadboard: $12.09Total: $212.92

Cost of Labor:Engineering labor rate: ~$60.00/hourTime spent working: ~15 hoursEstimated total cost of labor: ~$900

Major Scales Used: