Lab 2: Designing Optical Theremin Instrument

advertisement
THE PENNSYLVANIA STATE UNIVERSITY
Lab 2: Designing Optical Theremin Instrument
EE 300W Section 001
Nathaniel Houtz, Ji Eun Shin, Peter Wu
2/22/2013
1
ABSTRACT
A simple Theremin must be able to produce a highly user-customizable output signal from two
relatively plain input signals. Since multiple subsystems within the Theremin are required to provide the
needed signal modifications, thorough planning and designing are necessary for this system to function
correctly. Unlike a conventional Theremin that is hardware intensive, the photodiode Theremin built in
Lab 2 is software intensive. This leads to a simplified circuit design, but results in a more complicated
program design.
The physical circuit constructed on a bread board consists of two photodiodes connected to an
op amp configured to function as a current-to-voltage converter. This circuit produces two signals that
are then read by a NI myDAQ and modified using LabVIEW. In order for the Theremin to operate
correctly, the input signals, which vary with light intensity, had to be manipulated so that they could
serve as frequency and amplitude control signals for a sine wave simulator.
Ultimately, the user will be able to control many aspects of the output signal such as the
frequency range and the gain of the photodiodes. However, the more capabilities we incorporate into
the system the more complex it becomes. This is why it is imperative that this photodiode Theremin not
only be designed to work well, but also designed for easy operation.
INTRODUCTION
In this design project, the problem statement is to create an optical Theremin through a photo
detector circuit and LabVIEW programming. A Theremin is an electronic musical instrument that has its
volume and pitch controlled without any physical contact from the user. One will design circuitry to
measure the current that is produced by the photodiodes and use this in combination with LabVIEW
signal processing to produce a sinusoidal audio tone to be outputted by the NI myDAQ. By controlling
the amount of light entering the photodiodes, in the operational amplifier circuit, the user will be able
to control both the volume and pitch of the Theremin. The other high level design requirements include
allowing the user to configure the intensity range seen by each sensor and the range of audio tones
generated.
The design interface requirements with NI myDAQ and LabVIEW include the ability to generate a
sinusoidal audio signal from the myDAQ and the ability to adjust the amplitude and frequency ranges of
the audio signal through LabVIEW’s front panel window. Additional LabVIEW front panel requirements
define the adjustable user settings for the design. These project requirements include having an
adjustable maximum and minimum light intensity level for each detector, a front panel, user-adjustable
range of frequencies that the Theremin produces, the front panel displays for the normalized pitch
waveform as a function of time, and the normalized volume waveform as a function of time. Waveform
charts of the light intensities detected by each photodiode as a function of time must also be included.
For the second part of this lab, one has to create an auto-tune feature for the optical Theremin
that will tune a specific pitch to a tone in the equal-tempered scale. This auto-tune feature can be
turned on or off by the user on the LabVIEW front panel. In addition to the auto-tune capability, a bonus
2
feature incorporated into the system lets the user choose what key the Theremin is tuned to and what
octaves of notes it will play.
THEORY
In the design of the optical Theremin, a light to voltage circuit is utilized in obtaining the
amplitude and frequency signal voltages used to create the sinusoidal audio output. The conversion of
light energy to voltage is done using a photodiode, resistor, and FET operational amplifier configured as
a current-to-voltage converter. When light is incident upon a photodiode, a small leakage current is
generated. This leakage current is then transformed by the operational amplifier and the resulting
output is a voltage.
The photodiode current can be written as i = RL with i being the output current in
microamperes, L being the optical power in microwatts, and R being the responsivity property of the
semiconductor diode. The op amp takes this current and converts it to a voltage at its output with the
governing equation, Vout = -iRf where i is the input current and Rf is the feedback resistor. By combining
the two equations, one gets an output voltage in terms of the responsivity, optical power, and feedback
resistance, Vout = -RLRf. The output of each op amp is then connected to the analog channels of the
myDAQ for signal processing ("Tinker, Learn, and Do Engineering with NI MyDAQ - Lab 10: Optical
Theremin." ).
Figure 1 - Photodiode Circuit
The signal voltages going into the MyDAQ become inputs to the LabVIEW program. Both voltage
signals go through a normalizing and coercing block that outputs a value between 0 and 1 depending on
the intensity of the raw voltage signal. This normalized value is then multiplied with the respective
voltage and frequency ranges defined by the user. The sinusoid simulator then uses these two scaled
signals to define the amplitude and frequency of the sinusoidal audio signal generated. In addition to
scaling the frequency, one can also quantize the frequency or pitch to the nearest half tone or threshold
value if the auto-tune feature, another subsystem of the overall design, is enabled.
The amplitude and frequency of the sound produced by the optical Theremin can be controlled
by changing the intensity of light that reaches each photodiode. The amount of light that reaches the
3
photodiode in the amplitude photodiode circuit will determine the volume of the audio signal. The
amount of light that reaches the photodiode in the frequency photodiode circuit will determine the
pitch of the audio signal.
IMPLEMENTATION
The optical Theremin will consists of front-end detector circuitry and back-end signal processing
and generation with LabVIEW. To convert light energy to useful voltage signals, one uses photodiode
detectors to produce a current which then gets converted into a voltage through the utilization of an op
amp configured as a current-to-voltage converter.
The circuit will resemble the one shown in Figure 1. The resistor is a feedback resistor that ties
the output back to the inverting terminal. The non-inverting terminal of the op amp is grounded. The
photodiode is placed from the inverting terminal of the op amp to ground. When light hits an OP406
photodiode, a small leakage current is generated. A large gain is needed to amplify the small current
into a voltage signal around a single volt. A 1MΩ feedback resistor was chosen to achieve this
amplification. Two op amp current-to-voltage converters were used in the design since one output
voltage is used for the amplitude of the audio signal and the other is used for the frequency of the audio
signal.
The two voltage signals are acquired in LabVIEW through the myDAQ Assistant block which
communicates with the NI myDAQ. The voltages are then averaged, normalized, and scaled by the userdefined amplitude and frequency quantities. The frequency can be further manipulated if the user
chooses to have the signal auto-tuneed. This will basically round the ouput fruency up or down to the
closest frequency of a given scale. The adjusted signals are taken as inputs by the simulated signal
function in LabVIEW to generate a sine wave with an amplitude and frequency defined by the adjusted
signals. The sinusoidal signal is generated and written to the myDAQ through the use a second DAQ
assistant virtual instrument. In the LabVIEW front panel, one can set the upper and lower bounds for the
amplitude intensity and audio frequency range.
Block Diagram
Level 0:
Input:
-Light energy into
photodiodes (photodiode can
detect distinct light levels)
-user inputs light intensity
range and audio output
frequency range (adjusted by
user through front panel)
Sampler
&
Processor
&
Generator
Output:
User-controllable
audio signal
(output from the
MyDAQ 3.5 mm
TRS connector)
4
Level 1:
Sampler 1:
Samples the
amplitude
photodiode
amplifier circuit
Sampler 2:
Samples the
frequency
photodiode
amplifier circuit
Processor 1:
Processes the
signal obtained
from sampler 1
Processor 2:
Processes the
signal obtained
from sampler 2
Auto-tune:
Tunes the
frequency to the
nearest half-tone
of the selected
key
DAQ
Assistant:
Signal
Generator
Level 2:
Sampler 1:
Sampler 2:
Samples raw output signal voltage
from amplitude circuit
-
Samples raw output signal voltage
from frequency circuit
User can adjust voltage
amplitude of audio tone based
on light intensity
-
User can adjust frequency
of audio tone based on light
intensity
Processor 1:
Scales normalized value by
user-defined voltage amplitude
range
Normalizes and
coerces signal voltage
to a value between 0
and 1
-
User can configure
intensity range
Processor 2:
Normalizes and
coerces signal
voltage to a value
between 0 and 1
Scales the normalized signal
by the user-defined audio
frequency range
-
User can configure
frequency range
Offsets the signal for
the desired minimum
audio frequency
5
Auto-tune:
Takes normalized and scaled frequencies and
goes through an array comparator to output
frequencies to the nearest half tone
-
User turns feature on or off
Tune the pitch to a tone in the equaltempered scale
o User selects can select key
o 8 arrays of indexes are used
to build an array a given key’s
frequencies based on the 96 –
element array of chromatic
frequencies
Signal Generator
Takes normalized and scaled
amplitude and frequency
signals as parameters in
generating the audio output
signal
Initial Block Diagram and Justification
At the top level, the block diagram has inputs to the optical Theremin that include the light
energy going into the photodiodes, a user-defined light intensity range, and a user-defined audio output
frequency range. The output of the system is a user-controllable audio signal with its frequency and
amplitude determined by the user settings. The system samples the circuit voltage signals, processes the
voltage signals, and generates a configurable audio tone.
When delving deeper into the system, one sees subsystems that consist of two sampler blocks,
two processor blocks, an auto-tune block, and a generator block. The function of the sampler blocks is to
read the voltage signals from the circuit. The first sampler reads the voltage signal for the amplitude
circuit through the analog inputs of the NI MyDAQ and the second sampler reads the voltage signal for
the frequency circuit through the analog inputs of the NI MyDAQ. These voltage signals can be adjusted
by the user through manipulating the light intensities by moving one’s hand over the photodiodes.
The function of the processor blocks is to normalize and scale the two input voltage signals to a
user-defined amplitude and frequency range. The maximum and minimum light intensity level and range
of frequencies for the optical Theremin will be adjusted by the user in the LabVIEW front panel. The
normalized waveforms for the frequency and amplitude will also be displayed on the front panel along
with the light intensity level detected by each photodiode. The function of the auto-tune block is to tune
the normalized and scaled frequency signal to a tone in the equal-tempered scale. The auto-tune
feature can also be turned on or off on the LabVIEW front panel.
When enabled, the auto-tune block also contains a bonus feature that allows the user to select
the frequency that the Theremin auto-tunes to. This is achieved by first creating an array of indexes for
6
the desired key. This array is built based on an initial predefined array that contains the first octave of
notes in the key. The full index array for each scale will consist of seven octaves. The index array is then
used to build a frequency array using a for loop and array manipulation functions. This frequency array
will contain each frequency for the selected key within the first seven octaves. Finally, the user can also
select which octaves of the scale the output is auto-tuned to. This is accomplished simply by assigning
Boolean values to each octave and using Boolean and array operators to remove a given octave from
the final frequency array.
Block Diagram Analysis
In comparison with the block diagram at the beginning of the project, the revised block diagram
is almost identical to the initial block diagram except for the addition of an auto-tune subsystem. The
function of the auto-tune block is to tune the normalized and scaled frequency signal to a tone in the
equal-tempered scale. The auto-tune feature can also be turned on or off on the LabVIEW front panel.
The original project idea is the same. Our design has expanded from the initial design through the
addition of an auto-tuner.
Design Modifications Made During Testing
Over the past five weeks, our team has observed and verified the elements in our original circuit
and system design that function correctly, while also identifying which components need modification.
When comparing the initial design of the physical circuit with the final version, it is hard to notice any
changes at all. The only real variable within the circuit that we experimented with was the feedback
resistor value. Other than that, our initial circuit design has not been modified at all.
Most of our design modifications have been made during the program construction phase. This
was expected, however, since we are still learning how to use the multitude of features that LabVIEW
has to offer. The initial signal processioning portion of our program has remained unmodified except for
the addition of two multiplication functions that are used, in effect, to adjust the sensitivity of the
photodiodes. This allows the Theremin to be more functional in either dimly-lit or bright environments.
Another design modification that we made to the program was within the amplitude sub-VI.
Initially this VI was built to normalize the averaged signal from the amplitude diode, based on the userdefined maximum and minimum voltage values produced by the circuit. Then originally, the normalized
signal was wired back to the main VI. However, we later decided to wire in a multiplication function
similar to the two we had implemented to control the sensitivity of the two diodes. This new
multiplication function was added to serve the purpose of a master volume control.
The addition of the auto-tune feature brought about a few more design modifications. Initially
we had decided to use two VI’s in order to produce the auto-tuned output. The first VI would deal
strictly with array manipulation and the second VI would process the data. This seemed like the best
approach at first but through trial and error, we found that it was simply easier to design the autotuning feature using only one VI. By doing this, everything can be found in the same location and one
could easily reference the frequency array.
7
DAQ Assistant Setting Parameters and Observations
In our opinion, choosing the setting parameters for the DAQ Assistant reader and writer was the
most frustrating obstacle in this entire project, despite the acquisition modes for both the reader and
the writer already being selected for us in the Lab 2 handout. The DAQ Assistant writer was to be
configured to take a finite number of samples each time it reads the input signals. The DAQ Assistant
writer was to be set to sample continuously. The frustrating part was determining the sampling rates
and the buffer size or number of samples to read.
The DAQ Assistant reader turned out to be the simpler to configure out of the two. It uses the
finite sample data acquisition mode. Therefore the two parameters to adjust are the number of samples
read and the sampling rate. These settings must be chosen to maximize performance without sacrificing
system stability. The goal is to have the Theremin produce an audio signal that is smooth and not
choppy. This can be accomplished by setting the sampling rate to a high value and setting the number of
samples taken to a relatively low value. If the number of samples to read is too large it will take the DAQ
Assistant a longer time to read them all. The values we chose that seemed to work the best are 200
samples to read at a rate of 50 kHz. Additionally, we set the voltage input scale from zero to five volts.
The problem of choppy output also exists with the DAQ Assistant writer. However, since it
samples continuously the only parameter that affects how quickly it will produce a signal is the sampling
rate. The other parameter that you adjust when the DAQ assistant is in continuous sampling mode is
buffer size for the input signal. The value for these settings must be chosen carefully. If the sampling
rate runs too slow then the output signal will be choppy. However, if the DAQ Assistant writer runs at
too high of a sampling rate then sample regeneration might occur. Sample regeneration is caused when
the DAQ Assistant writes information out faster than it is receiving it. There is an option to enable
sample regeneration but this has a negative impact on the output signal quality. When the program
produces a warning that regeneration might occur, it suggest increasing the buffer size. We found that
increasing the buffer size by too much can use up a lot of your computer’s RAM and cause it to run very
slowly.
A compromise for speed and stability must once again be made. We found that a buffer size of
60,000 and a sampling rate of 40 kHz seemed to work well for us. We also set the voltage output range
from -2V to +2V, the voltage limits of the myDAQ’s audio output channel.
VALUE STATEMENT
The takeaway from this optical Theremin design project is learning how to tackle a given
problem statement by going through the concept design and selection processes as a team. The ability
of a team to successfully meet the project requirements depends on how well the individuals within the
team work together as a unit. An important lesson that we learned was discovering how to maximize
the performance of our team through leveraging the strengths of the individuals within the team. This
design project was an extremely useful exercise in learning about team dynamics.
8
CONCLUSION
Through a disciplined design and development process, we have created a simple circuit that
converts the leakage current of a photo diode to an output voltage. We then designed a LabVIEW
program that would read these voltage signals, manipulate them, and output an audio signal that could
be altered by the user controlling how much light the photodiodes are exposed to. Through careful
design and implementation, we have successfully proven that you can create an optical Theremin with a
detector circuit front end and signal processing in LabVIEW.
APPENDICES
GANTT CHART:
Task Name
1.0 Interface Circuitry
1.1 Design Circuitry
1.2 Construct & Test Circuits
2.0 LabVIEW
2.1 Obtaining signal
2.2 Amplitude VI
2.3 Frequency VI
2.4 Auto-tune VI
Week1 Week2 Week3 Week4 Week5
9
Screen Captures
Main VI for Part 1 of Lab2
Control Panel for Part 1 of Lab 2
10
Main VI for Part 2 of Lab2
Control Panel for Part 1 of Lab 2
11
Amplitude VI
Frequency VI
Auto-Tune VI
12
Financial Page
BILL OF MATERIALS
Cost of Parts (Quantity)
Jumper wires (15)
TL 074 Op Amp(2)
OP906 photodiodes (2)
1 M-ohm resistor (2)
NI MyDAQ
LabVIEW 2012 Student Version (free)
Breadboard (1)
Total Parts Est. ($)
$
0.20
2.04
1.10
0.04
175.00
0.00
20.00
$198.38
Cost of Labor
Est. Labor ($) Engineering rate: $35/hr
Fringe (4) 15% of Est. Labor
Overhead (4) 40% of (Labor + Fringe)
Total Labor Est. ($)
Contingency ($) 10% of (Adjusted Parts + Total Labor):
Grand Total
525.00
78.75
241.50
845.25
108.42
$1152.05
13
REFERENCES
"Tinker, Learn, and Do Engineering with NI MyDAQ - Lab 10: Optical Theremin." National Instruments Developer Zone. National Instruments, 20 Feb. 2012. Web. 22 Feb. 2013.
<http://www.ni.com/white-paper/13636/en>.
Download