Author Topic: Square wave from sine, follow envelope?  (Read 6881 times)

0 Members and 1 Guest are viewing this topic.

Offline alexanderbrevigTopic starter

  • Frequent Contributor
  • **
  • Posts: 700
  • Country: no
  • Musician, developer and EE hobbyist
    • alexanderbrevig.com
Re: Square wave from sine, follow envelope?
« Reply #25 on: August 22, 2017, 11:23:08 pm »
As I've said I just tried diptrace and I like it a lot!

Here's my layout of this thing: (as small as possible because why not.,..)
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 13006
Re: Square wave from sine, follow envelope?
« Reply #26 on: August 23, 2017, 04:21:03 am »
Here's another approach to the problem:
I'm assuming its fed by a buffer amp with a very low output impedance.
Detect the peaks by the reversal of the current through a capacitor, and use that to trigger a sample & hold circuit to hold the output till the next peak.  On a waveform with alternating positive and negative peaks that will give you a squarewave that follows the envelope.  However on more complex waveforms it gets a bit messy.

The devil is however in the details - to cover the whole audio frequency range (say 50Hz to 20Khz) you need an analog switch with a very high ratio of off resistance to on resistance. 

Ltspice sim attached.  Change the .param freq to change the frequency as it alters the simulation length to match.   You'll need 74hct.lib and the 74HCT symbols, specifically the quad XOR 74HCT86, from the LTwiki files area.

A practical implementation would either run everything at 5V single supply using rail to rail CMOS OPAMPs and 74HC logic, or use 4000 series CMOS logic to avoid the need for a 5V logic supply.  If using logic with symmetrical thresholds, omit R4 and readjust the R3*C3 time constant (which controls the sampling gate time) to suit.  Also the peak detector comparator will need a trace of hysteresis added to reduce chatter due to noise.  Too much compromises its ability to follow small signals and skews the sampling point away from the peak.
« Last Edit: August 23, 2017, 04:26:21 am by Ian.M »
 

Offline dorin

  • Contributor
  • Posts: 39
  • Country: ro
Re: Square wave from sine, follow envelope?
« Reply #27 on: August 23, 2017, 09:52:16 am »
Not sure if it matters for your application, but what you are getting there with these circuits is a very distorted square wave. To get a clean square wave, the circuit would need to be much more complicated.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 13006
Re: Square wave from sine, follow envelope?
« Reply #28 on: August 23, 2017, 10:10:51 am »
I've had some further thoughts on the sampling at peak approach:
If one uses a two channel SPDT switch, e.g CD4053, and two hold caps, one can discard the quad XOR and drive the switch direct from the comparator.
It would alternately connect one cap to the input and the other to the output buffer amp, swapping them on every signal peak.  Because the cap connected to the input follows the signal for the whole interval between peaks, it avoids the problem of trying to charge the hold cap very quickly before the signal has dropped too far from the peak and will give much sharper edges.  That gets it down to a three chip solution: Comparator, CD4053, and a dual FET input OPAMP to buffer input and output.
 

Offline alexanderbrevigTopic starter

  • Frequent Contributor
  • **
  • Posts: 700
  • Country: no
  • Musician, developer and EE hobbyist
    • alexanderbrevig.com
Re: Square wave from sine, follow envelope?
« Reply #29 on: August 23, 2017, 10:35:16 am »
Not sure if it matters for your application, but what you are getting there with these circuits is a very distorted square wave. To get a clean square wave, the circuit would need to be much more complicated.
Does not matter at all for my application (a guitar effect). We like distortion ;)
 

Offline alexanderbrevigTopic starter

  • Frequent Contributor
  • **
  • Posts: 700
  • Country: no
  • Musician, developer and EE hobbyist
    • alexanderbrevig.com
Re: Square wave from sine, follow envelope?
« Reply #30 on: September 15, 2017, 05:52:15 pm »
Just wanted to say, I made it and it works!
Clips out some of the lowest playing, and acts as a gate in turn. Not sure yet if I like it or not.

I wonder if it is the first zener from ground or what? Hmm.
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19786
  • Country: gb
  • 0999
Re: Square wave from sine, follow envelope?
« Reply #31 on: September 16, 2017, 07:26:29 pm »
Just wanted to say, I made it and it works!
Clips out some of the lowest playing, and acts as a gate in turn. Not sure yet if I like it or not.

I wonder if it is the first zener from ground or what? Hmm.
I don't know. Which schematic did you build? None of the ones posted, have a zener diode.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf