Audio Frequency to Voltage Converter
Total Page:16
File Type:pdf, Size:1020Kb
Audio Frequency to Voltage Converter Erick Rodriguez Hannah Savoldy May 14, 2020 Abstract This project focuses on producing an output that is proportional to an input audio frequency. To find the highest amplitude frequency in a signal, a series of bandpass fil- ters is used, one of which yields a pure sinusoid of the desired frequency. By compar- ing the rectified positive, no-offset voltage for each signal, the highest-amplitude sig- nal is isolated via comparator stages which compare and select the highest-amplitude wave of the previous stages. After obtaining the desired theoretically pure sinusoid, it is converted to a DC voltage proportional to its frequency using a differentiator, recti- fiers, and a voltage division circuit. This is then converted into a pulse width modu- lated (PWM) signal using a 555 timer and comparator. The final circuit has bandpass filters corresponding to the notes in one octave, successfully filtering the signal, select- ing the dominant frequency, and producing a PWM signal with a proportional duty cycle. 1 Introduction This circuit takes in an audio frequency with the range of one octave, outputting a PWM that could be used to drive motors at different speeds. A novelty application would be in playing different notes to make wheels spin or a lever to move faster as the note climbs. As motors are able to be implemented in a vast range of applications, so can this circuit. The project can be divided into two separate halves. The first half chooses the largest amplitude frequency in an audio signal. The second half takes in the sinusoidal signal of the first and converts it into a PWM signal. 1 2 Block Diagram Figure 1: Overview of System An audio signal registered via a microphone is split into multiple narrow frequency bands via bandpass filters tuned across one octave at the range of 261.63Hz - 523.25Hz. These bands undergo 4 stages of magnitude comparisons until the highest amplitude signal is selected. The signal is then split, with one of them differentiated and both rectified before being divided to produce a voltage proportional to the frequency. This voltage is then compared with a sawtooth wave generated by a 555 timer to create the PWM output. 2 3 Implementation 3.1 Voltage Selector (Hannah Savoldy) 3.1.1 Overview Figure 2: The entire voltage selector schematic with the input (microphone output) enter- ing on the left and the pure sinusoid exiting on the right. Calculating an output voltage that is proportional to an input frequency requires a signal with only one frequency. Therefore, before performing calculations on the input signal, a pure sinusoid must first be extracted. A microphone output will contain multiple frequen- cies in the form of noise and note harmonics. The frequency that will control the voltage output should be that of the largest amplitude component. 3 Figure 3: Side-by-side of an unfiltered microphone output containing noise and harmonics (left) and the filtered signal containing only the highest amplitude component (right) In music, this is typically the fundamental frequency of a note. To obtain this, a hardware approximation of a Fourier transform must be implemented. The input signal is split into frequency bands by a series of 13 bandpass filters, where the center frequency of each cor- responds to a note in an octave ranging from a C4 (261.63Hz) to a C5 (523.25Hz). Figure 4: The array of bandpass filters that the input signal goes through- each filter rep- resented with the note corresponding to its center frequency. The output of each filter is then rectified and, in pairs of two, passed into a comparator. If the output is high, one transistor will turn on and allow the higher of the two signals to pass through. If the output is low, it will turn on the other transistor after passing through a not gate, allowing the other signal to continue. 4 Figure 5: The building block of bandpass filter output comparisons The final output will be the highest amplitude filter output, once all signals have been compared. This is a theoretically pure sinusoid. An intuitive understanding of this process can be attained through a comparison with a bracket system typically used in sports. Figure 6: A bracket representation of the voltage comparisons Each “competition” between filter outputs results in a “winner.” Then winners are com- pared with winners until a final, highest amplitude sinusoid results. 3.1.2 Building the Filters Because the frequencies to be filtered are so close in magnitude, with the lowest difference being 15.55Hz, the choice of bandpass filter should have as narrow a roll-off as possible. The natural choice was a narrow-band Sallen-Key topology. 5 Figure 7: The bandpass filter used in this circuit Further choices could be made to make the band as narrow as possible. While maintaining a capacitor value of 220nF for both C1 and C2, increasing R1 and R2 and decreasing R3 decreases the bandwidth. However, making these changes worsens the transient of the filter output. Figure 8: The input (green) and output (blue) of a filter with a very low bandwidth and a long transient (Q = 11). After some optimizations, a Q value of about 17 was chosen, creating an acceptable balance between low bandwidth and short transient. 6 Figure 9: The final result of the tuned filter (Q = 17) with green input and pink output. (Note that this figure was captured after many more modifications to the circuit, so the slight distortion is not a result of changing the filter) 3.1.3 Choosing a Transistor The first thought was to use pnp and npn transistors to switch on the appropriate signal for negative and positive comparator output voltages, respectively. This would avoid the use of an extra component, a not gate, for every comparison block. However, several non- idealities exist with this approach. Because bipolar transistors are current-controlled, the voltage-based comparator output meant to switch on the base created issues. For exam- ple, without a resistor in series with each transistor, they yielded no output. Including a resistor made the transistors function as expected, but it created undesirable power losses that were difficult to make up, due to the unpredictability of the input. Trying to use MOSFETs instead was the next step. The issue with MOSFETs is that, al- though they are voltage-controlled which would result in more predictable behavior, they have an internal diode, so to pass an AC signal, they need an offset: positive for the n-type and negative for the p-type. This could be accomplished through a simple diode clamper circuit. Figure 10: The implemented diode clamper circuit. The capacitor and resistor values were chosen so that the time constant would be appropriate for the range of frequencies. The offset could be used to adjust for the 0.7V drop across the diode. The diode clamping step only needs to be performed once: at the output of every filter. 7 This offset is then removed before the final output through an in-series capacitor. In practice, different MOSFET models yield sometimes dramatically different results. For example, the output of the MOSFET initially appeared extremely distorted. Figure 11: The input (red) vs output (green) of the first MOSFET model tried, with notice- able distortion on the output This issue was resolved with another model: the Si7336ADP, probably due to a slew rate limitation. The final problem came from the use of both n-type and p-type MOSFETs, which must have different characteristics. Despite best attempts to match them, in a cir- cuit whose goal is to compare amplitudes, using different transistor models for different branches made little sense. In the end, the original design idea involving all the same model MOSFETs and not gates prevailed. 3.1.4 Final Debugging After the basic building block of the voltage comparison was complete, new challenges arose from putting them all together. Despite the buffer placed before the filters, the large load on the circuit, which involved capacitors in series with each other, required more buffer stages. This was implemented by placing unity-gain operational amplifiers between comparison stages. Unfortunately, this drastically increased the runtime of the simulation, so testing the entire, perfected system was infeasible. However, the somewhat functional schematic with no between-stage buffers, and the final one-stage building block design, are both testable, so the circuit as a whole can be confidently presumed to function. 8 Figure 12: A close shot of the final, perfected voltage comparison design with unity gain op amp buffers between stages 3.1.5 Testing Because the perfected overall design is too slow to effectively test, an analysis can be done on just one voltage comparison between two filters. The filters chosen for testing corre- spond to a C4 (261.63Hz) and a C#4 (277.18Hz) because these are the two closest center frequencies among all the filters. Figure 13: The setup for testing a single voltage comparison block The input to the circuit is a .wav sound file, in which a keyboard alternates between the two notes: a C4 and a C#4. 9 Figure 14: The input used to test the circuit- an audio wave representing a keyboard switching between the center frequencies of both filters A general idea of the circuit’s success can be gathered by examining the comparator output relative to each note change. A note change in the audio file is observed as a sudden increase in amplitude: in the clip shown in figure 14, there are three note changes. Figure 15: The output of the comparator (red) relative to the audio file (green), with changes in comparator output mirroring changes in audio frequency In figure 15, the comparator output switches approximately 50ms after the note changes, with the exception of the middle note change.