Sine Wave to Square Wave converter retaining original P-to-P

Thread Starter

jarek319

Joined Jan 24, 2010
18
I have an audio project that I'm working on. My guitar pickup outputs a sine wave anywhere from .05 to 1 V Peak to Peak, from 200Hz to 20Khz (haven't found the actual upper limit, using theoretical limits). I want to convert this to a square wave, retaining both the frequency and voltage of the original signal.

I've found zero crossing detectors that solve the frequency problem, however they output at only the voltage given to the comparator. There were a few 'self powered' sine to square converters, but they required a minimum of .75mV.

Does anyone have any ideas? Ideally it would be a chip powered by 3 AA batteries, or even self-powered with a voltage multiplier.
 

Wendy

Joined Mar 24, 2008
23,429
If you want to maintain the RMS value make a simple amplifier with a gain of 0.707 to feed the square wave through.
 

Potato Pudding

Joined Jun 11, 2010
688
First thought.

I thought you need to lag 90° or 180° out of phase to do it.

You need to start a period capture circuit to measure from the crossing to peak. Then you need to capture and hold the peak value, start decomposing the period capture while starting another period capture that ends when the signal recrosses zero. Keep holding the peak while you finish the first period capture and if the second period capture is finished you start to decompose it. If it was not complete then you start another period capture and keep doing so until one of the period captures finishes with the signal recrossing zero.

Meanwhile I think if the waveform complex bumps to a higher peak you need to capture that peak so the signal can escalate. I don't think the symmettry to declining peaks is asked for.

It is going to be 180° out of phase if you don't want to accept escalating peaks.

Second thought try detecting narrow averaged signal level and using an AGC to have that matched by the square waved (clipper circuit signal throughput) reamped output.
 

eblc1388

Joined Nov 28, 2008
1,542
If you want to maintain the RMS value make a simple amplifier with a gain of 0.707 to feed the square wave through.
How this gonna work for a square wave of constant amplitude? :confused:

To get a square wave, the sin input signal of varying amplitude has to go through a zero crossing comparator and this gives a constant amplitude square wave as output.
 

daviddeakin

Joined Aug 6, 2009
207
Use a peak-level detector to measure the amplitude (envelope) of the audio signal.
Convert the audio to a square wave of constant amplitude.
Feed the square wave to a voltage-controlled gain stage (e.g., LM13700) whose gain is controlled by the audio envelope.
 

Thread Starter

jarek319

Joined Jan 24, 2010
18
Thank you for the LM13700 tip! I'm going to look into that chip and put it down on my next digikey order. Since I'm going to be using a peak detector anyway, it would be easy to feed the peak into two different chips.
 

tom66

Joined May 9, 2009
2,595
I've been thinking on how to implement this, and I came up with this pretty basic idea. I'm not sure if it's been suggested before, or if this circuit already exists - I independently designed this.

The input op-amp acts as a peak detector to figure out peak amplitude. The capacitor can be adjusted; a bigger value means less output ripple, but also means that the output takes longer to change between levels. Note the input signal *must* be ac coupled.

The second and third op-amps from the left act respectively as buffers and as inverting buffers. The second op-amp can be omitted if it is known that there is not going to be much load on the output (i.e. it's going into an amplifier stage.)

The fourth op-amp acts as a zero crossing detector. A comparator can (and probably should) be substituted here for high speed operation. Slew rate limitations of this op-amp WILL get into the output.

This entire arrangement can be implemented using a quad op-amp and uses very few parts.

The transistor and resistor arrangement is a low cost way of amplifying the signal within a Vp-p bound. You can't draw much from this due to the 100k resistor. It works very similar to an open collector output. It is normally high at V+, but applying a signal greater than about 0.7V to the base (relative to the emitter) of the transistor causes it to "pull down" the V+ signal through the 100k resistor to V-. It works from a low to a high voltage with virtually no distortion. For higher output current, and op-amp follower or power amplifier should be used. Note the output is about 20mV less than the peak, I am not entirely sure what causes this.

So you can simulate it, I have provided the import text. Use Falstad's circuit simulator (falstad.com/circuit) to import. Go to File > Import, and paste the text below.

Rich (BB code):
$ 1 5.0E-6 35.60246606707791 50 5.0 50
a 208 192 304 192 1 15.0 -15.0 1000000.0
d 304 192 352 192 1 0.805904783
c 352 240 352 320 0 4.7E-5 4.9644452371188965
g 352 320 352 336 0
w 416 240 352 240 0
w 352 240 208 240 0
w 208 240 208 208 0
w 352 192 352 240 0
R 208 176 176 176 0 1 40.0 5.0 0.0 0.0 0.5
a 464 256 560 256 1 15.0 -15.0 1000000.0
w 464 304 464 272 0
r 416 240 416 336 0 47000.0
r 464 336 560 336 0 47000.0
w 560 336 560 384 0
w 464 368 464 336 0
w 464 368 416 368 0
w 416 368 416 336 0
w 560 256 560 304 0
w 560 304 464 304 0
w 464 240 416 240 0
w 560 256 608 256 0
w 560 384 608 384 0
g 464 400 464 416 0
O 608 224 656 224 1
O 608 416 656 416 1
a 464 384 560 384 0 15.0 -15.0 1000000.0
a 560 144 656 144 1 15.0 -15.0 1000000.0
g 560 160 544 160 0
w 208 128 208 176 0
t 720 304 752 304 0 1 -19.96473829888124 -10.035996765514113 100.0
w 608 256 608 224 0
w 656 144 672 144 0
w 672 144 672 304 0
r 672 304 720 304 0 10000.0
w 752 256 752 288 0
w 752 320 752 384 0
w 752 384 608 384 0
w 608 416 608 384 0
r 704 256 752 256 0 100000.0
w 704 256 608 256 0
w 752 256 800 256 0
w 560 128 208 128 0
o 8 64 0 291 9.353610478917778 9.765625E-55 0 -1
o 40 64 0 291 9.831615282070846 0.0 1 -1
An image is attached.

Note: this circuit works down to about 5mV to 10mV before the output transistor stops pulling the negative rail enough and the negative rail starts floating towards V+. Substituting the NPN for an NMOS transistor allows the circuit to work as low as 700µV.
 

Attachments

Last edited:

Thread Starter

jarek319

Joined Jan 24, 2010
18
Wow, that simulation is exactly what I've been trying to do! I'm going to put it together tonight with an LM339 and post back with results. Thank you for your effort!
 

tom66

Joined May 9, 2009
2,595
Wow, that simulation is exactly what I've been trying to do! I'm going to put it together tonight with an LM339 and post back with results. Thank you for your effort!
You can't use an LM339 (except for the zero crossing detection); you must use an op-amp.
 

tom66

Joined May 9, 2009
2,595
I came up with a better 'front end' for it. It involves many more components. It's so big you'll need to paste it in and use the Drag tool (Alt-Drag or under Other on the right click menu.) This version changes much quicker than the other version and has almost no ripple.

Rich (BB code):
$ 1 5.0E-6 6.724437240923179 50 5.0 50
a 160 368 256 368 0 15.0 -15.0 1000000.0
r 96 352 160 352 0 1000.0
d 160 320 256 320 1 0.805904783
d 256 368 304 368 1 0.805904783
r 160 288 304 288 0 1000.0
g 160 384 160 400 0
w 160 352 160 320 0
w 160 320 160 288 0
w 256 320 256 368 0
w 304 368 304 288 0
r 304 368 304 448 0 100000.0
g 304 448 304 464 0
R 48 320 16 320 0 1 40.0 15.0 0.0 0.0 0.5
w 96 352 96 416 0
a 416 384 512 384 1 15.0 -15.0 1000000.0
w 416 432 416 400 0
c 512 432 512 512 0 1.0000000000000001E-7 0.7771022728570868
g 512 512 512 528 0
d 512 384 512 432 1 0.805904783
w 416 432 512 432 0
g 416 512 416 528 0
w 416 448 416 432 0
w 416 480 416 512 0
a 128 176 224 176 0 15.0 -15.0 1000000.0
g 128 192 128 208 0
154 288 128 400 128 0 2 5.0
154 464 96 576 96 0 2 0.0
w 288 112 288 80 0
r 400 128 464 128 0 1000.0
g 464 176 464 192 0
c 464 128 464 176 0 3.3E-7 4.99999995815831
w 464 80 288 80 0
w 464 112 464 128 0
g 288 144 288 160 0
w 288 80 256 80 0
w 256 80 256 176 0
r 576 96 576 160 0 1000.0
r 256 176 256 240 0 100000.0
g 256 240 256 256 0
d 224 176 256 176 1 0.805904783
w 128 160 96 160 0
w 96 160 96 352 0
f 368 464 416 464 0 1.5
w 576 160 576 224 0
w 576 224 352 224 0
w 352 224 352 464 0
w 352 464 368 464 0
w 416 368 304 368 0
g 592 352 576 352 0
a 592 368 688 368 0 15.0 -15.0 1000000.0
d 688 368 752 368 1 0.805904783
g 752 416 752 432 0
r 752 368 752 416 0 1000.0
c 816 368 816 416 0 1.0E-8 14.300403998053547
g 816 416 816 432 0
r 752 368 816 368 0 1000.0
w 1200 336 1248 336 0
w 1104 384 1104 416 0
w 1104 352 1104 336 0
g 1104 416 1104 432 0
w 1104 336 1200 336 0
d 1200 288 1200 336 1 0.805904783
g 1200 416 1200 432 0
c 1200 336 1200 416 0 1.0000000000000002E-6 0.7771752295008041
w 1104 336 1104 304 0
a 1104 288 1200 288 1 15.0 -15.0 1000000.0
f 1056 368 1104 368 0 1.5
w 512 384 592 384 0
w 512 432 544 432 0
w 544 432 544 272 0
g 944 416 944 432 0
c 880 368 944 368 0 6.800000000000001E-7 6.247627442147326E-12
I 816 368 880 368 0 0.5
r 944 368 944 416 0 1000.0
g 1024 416 1024 432 0
d 944 368 1024 368 1 0.805904783
r 1024 368 1024 416 0 1000.0
w 1104 272 544 272 0
w 1056 368 1024 368 0
174 48 320 96 384 0 1000.0 0.9455000000000001 Volts p-p
g 48 384 48 400 0
o 13 64 0 291 5.0 9.765625E-5 0 -1
o 56 64 0 35 1.1692013098647223 9.765625E-55 1 -1
 

Thread Starter

jarek319

Joined Jan 24, 2010
18
I'm not sure where to place the scope so I can get a reading on this one. I tried placing it on the end of the circuit, but it doesn't seem to be oscillating...
 

tom66

Joined May 9, 2009
2,595
What op-amp are you using?

Make sure you have a proper ac-coupled input. The circuit will not normally oscillate, unless there is a problem. The output should be the same frequency as the input.
 

Thread Starter

jarek319

Joined Jan 24, 2010
18
I meant on the simulation, the second one you provided. I loaded it into the java applet, and I tried attaching the software scope to the little wire on the far right, but it doesn't show up as a wave.
 

tom66

Joined May 9, 2009
2,595
That one won't oscillate. It's only a small part of a yet to be completed circuit. It was a replacement for the original peak detection front end. I agree it's a monster, so that's why I recommend you use the original; only use this front end if you want the circuit to adjust very fast and if ripple is a problem.
 

Thread Starter

jarek319

Joined Jan 24, 2010
18
I'm using the first circuit currently, and it sounds really good. I'm playing with cap values now to get the best sound, but so far i can't beat the 47uF. It's supposed to be a larger dielectric cap right? I couldn't find a monolithic like in the circuit in that size lying around.
 

DonQ

Joined May 6, 2009
321
I can't see your second circuit, so excuse me if this repeats...

Here is a full-wave rectifier and averaging circuit that I've been using since... well, check the original publication date of the Ap-note. It wasn't long after that!

Figure 25. http://www.national.com/an/AN/AN-20.pdf (A good resource in general.)

It's a clever circuit. The second diode is not what provides the full-wave rectification. It only keeps the amplifier from saturating when the other diode is reverse biased. Many amplifiers behave poorly when saturated and this stops that. This simple mod could (should) also be applied to your first circuit.

Then use the same 'this voltage and its inverse as limits for a square wave circuit' like before...
 

tom66

Joined May 9, 2009
2,595
I'm using the first circuit currently, and it sounds really good. I'm playing with cap values now to get the best sound, but so far i can't beat the 47uF. It's supposed to be a larger dielectric cap right? I couldn't find a monolithic like in the circuit in that size lying around.
I don't know. I chose the value because I liked that value and it worked. There was no methodology behind it.
 
Top