Square to Triangle wave conversion

Started by mabell313, August 08, 2014, 04:28:26 PM

Previous topic - Next topic

mabell313

I have been mulling over the idea of a fuzz pedal that would create(convert) other waveforms besides a square wave, most notably triangle and sawtooth. Has anyone done an experiment such as this before? I was thinking maybe an integrator circuit using a single op amp to get the triangle conversion. I have seen a few circuits for sawtooth conversion but, not many(really none) in regards to the triangle waveform. Any thoughts/ideas would be much appreciated.

By the way, I am new here so hello to all!

anotherjim

Hi,
Well that's a tricky one.
An integrator is a fine idea, but you have the problem of getting it to track the note played -  it's time constant will be too short or too long most of the time. You should find a time that suits a reasonable range - but it'll only make a decent triangle over a very small range.

No, if it's a Sawtooth, the situation is a bit better.
If you square it up and then feed a simple RC highpass filter, it's reasonably saw like. This is all that was done in the old string synths to get the "string" saw waveform, although some also half wave rectified it. Nevertheless, the same simple filter covered all the pitches on some models.

Then, getting into guitar synth territory - a phase locked loop circuit.
The input feeds a zero crossing detector (just a comparator) to square it up and have the most chance of being the fundamental of the note.
A phase comparator (an exclusive OR gate) compares this squared input with the square wave output of a VCO. The result is "difference pulses" which are averaged by a capacitor into a DC control voltage - which control the VCO pitch. Hopefully, this VCO now tracks the notes of the guitar.
All the usual synth waveforms are now available.
Complex though?


mabell313

Yeah, I was looking for a semi-simple solution. I knew the integrator was too good to be true! Well then, I guess I will just stick with sawtooth then. Thanks a million!

PRR

The integrator will always turn a square to a triangle.

The "problem" is that the triangle gets smaller as the frequency gets higher.

Think. Someone has painted a square-wave down your street. You want to paint a triangle wave with the same wave length. You start at a corner and start painting on a slant..... but what slant-angle??

If you can see the next corner of the square-wave, you just aim your brush at it.

In audio we can't see the next wave. Since much fun audio is repetitive, we may be able to predict. But prediction circuits are non-trivial and usually do a wrong thing some times. A phase lock loop will capture the repetition rate (pitch) of a guitar tone, but it takes a few cycles to lock, and loves to lock overtones.

Go ahead and build an integrator. It's too simple to resist. Over a smaller range (like one octave) it may do quite well.
  • SUPPORTER

R.G.

In my relative youth I spent a lot of time thinking about this question.

As noted, the issue of the size of the triangle you get is very hard to control by any integration scheme. Or rather, it's definitely controlled, but not in a good way.

PLLs do offer a way out. As Paul notes, they do take a few cycles to lock, and tend to lock on harmonics, at least for simple ones. He missed a limited frequency range for the VCOs, and the fact that you have to pre-fake the capture range by putting the idle setting of the VCO in the middle of the expected frequency range. He left off the fact that any PLL technique needs to be gated somehow to not put out the idle frequency in the absence of an input, which there is a maddening amount of in music. There are others, but these are the biggies.

But the CD4046 and its near clones manage to do a really great job of quick lock, and if you use the "state machine" digital phase detector, it locks only on the fundamental, given only that you have cleaned the input waveform up into a real rectangular wave. The 4046 does a passable job of locking to single note guitar signals with the proper cleanup, for which I suggest you search on "roctave divider" and "PLL" 

I did a sawtooth waveform maker that used a 4046 to lock on an input signal and multiple it up by 32X, then used the several sub-octaves of the 32X up to drive a staircasing waveform generator that made a close approximation of a sawtooth from the PLL and multiplier outputs. The notes are here in a thread you can find by searching on "R.G." and "PLL", and probably "rocktave".

The same trick can be used to make a sine wave locked to the square wave, and probably a triangle. All of these tricks use resistor networks to selectively add/subtract the higher frequencies from the lowest-frequency square wave and make and approximation to the final wave.

The Rocktave divider signal conditioning does a good job of cleaning up guitar to a square wave that works with the iinput to a 4046.

Simple analog techniques are going to be limited to single note signals, not chords.
R.G.

In response to the questions in the forum - PCB Layout for Musical Effects is available from The Book Patch. Search "PCB Layout" and it ought to appear.

anotherjim

 Thomas Henry makes a synth VCO with the 4046 chip by ignoring the standard CV input and controlling it instead with a commonly used (in synths) compensated BJT current mirror - this greatly increases tuning range. Nearly all the standard waves are produced from the 4046.

R.G.

Yeah, I've read that. There is a lot of fancy stuff that can be added to the basic 4046 and its derivatives.

My bug was always getting to a sine wave, and that required either a triangle wave and a carefully balanced tri-to-sine converter or the multiply-and-resistor-net approach. The multiplication approach was easier to get right, for me at least.
R.G.

In response to the questions in the forum - PCB Layout for Musical Effects is available from The Book Patch. Search "PCB Layout" and it ought to appear.

anotherjim

Back to the original thought...
I wonder if an FtoV converter, driving a LED and an LDR in the integrator, might give enough tracking range for a sqr-tri converter.

As for the "saw" idea I made out -  it's true as far as it goes, but I would hope in practice, it won't sound like a Big Muff with the tone control all the way up to the treble side.
Anyway, I've remembered this...
http://wutierson.com/en/news/101-string-machine-project
I found these recordings interesting to look at in a wave editor - they all started as square waves from flip-flop frequency dividers - then simple filtering to some species of "saw". The recordings are taken from a stage in the instrument before the ensemble chorus works it's magic.

R.G.

Quote from: anotherjim on August 09, 2014, 02:19:13 PM
I wonder if an FtoV converter, driving a LED and an LDR in the integrator, might give enough tracking range for a sqr-tri converter.
The problem you get into very quickly is that LDRs have a "slew rate", the fastest they can change resistance with a change in illumination. Some LDRs are in the tens of milliseconds, some are in *seconds*. On top of that, the "slew rate" of conversion from frequency to voltage itself is slower than a cycle of signal, sometimes MUCH slower.

In fact, the phase comparator on a PLL is a kind of differential frequency to voltage converter, converting differences in frequencies to a voltage for the VCO. In fact, now that I think about it, a PLL could be set up as an F to V converter. It would probably beat many of the other schemes like pulse averaging and some others I have seen in terms of speed.

There is a lock-in constraint on any system I've ever seen on how fast it can latch onto a signal frequency step. That's quite outside the frequency slew range.

QuoteAs for the "saw" idea I made out -  it's true as far as it goes, but I would hope in practice, it won't sound like a Big Muff with the tone control all the way up to the treble side.
Yeah. The sound depends on the harmonic content.

Square waves have only a fundamental and odd harmonics. Rectangular waves, waves with different mark/space ratios and hence different average levels between the + and - peaks have some even harmonics. But real square waves have no evens. So you cannot filter them down to get even harmonics that are not there. Pipe organs use different pipes, stopped versus open, for making sounds that have all harmonics, and just odd harmonics (the stopped pipes).  Simple RC filtering of square waves can make things that look sawtooth-ish, but it's an approximation to the real saw, which contains all harmonics with a magnitude proportional to their harmonic number. Cheap organs filter squares, fancy ones use sawtooths or approximate saws with stairstep addition. Or used to before everthing was digitally sampled or created computationally. I highly recommend Richard Dorf's "Electronic Musical Instruments". Check amazon or abebooks.

QuoteI found these recordings interesting to look at in a wave editor - they all started as square waves from flip-flop frequency dividers - then simple filtering to some species of "saw". The recordings are taken from a stage in the instrument before the ensemble chorus works it's magic.
Do they use resistor networks of adding several octaves of the flipflop outputs in various ratios?
R.G.

In response to the questions in the forum - PCB Layout for Musical Effects is available from The Book Patch. Search "PCB Layout" and it ought to appear.

anotherjim

Nothing so fancy - a string machine is really naught but a divider organ with a fixed "strings" tab setting - a HPF. Some fitted individual HPF into the key gating so at least it's tailored to the pitch, other are global HPF. On some, the key gating produced half wave. Those were considered the best (such as the ARP/Solina). I think the sole object is to get a wave with a strong second harmonic. But, probably 90% of the success of the "string" sound for all of them was down to having an Attack/Decay envelope and the all important ensemble chorus.

I can't help wondering if for guitar (or bass), a swell effect + HPF + chorus could sound fairly close to the above.

R.G.

R.G.

In response to the questions in the forum - PCB Layout for Musical Effects is available from The Book Patch. Search "PCB Layout" and it ought to appear.

PRR

> square waves have no evens. So you cannot filter them down to get even harmonics

However "if" he can derive a triangle from the square, and put it through an Absolute Value conversion (precision rectifier or PaIa's clever trick), he gets a double-frequency triangle plus a DC offset proportional to level.

The incoming triangle has to be centered. The output stands on zero so DC offset may give some trouble. (Especially if we were to process the 2nd to get a 4th.)

If he don't go on to explore such tricks, I fear a simple Triangle will be just too darn boring. It isn't much brighter than a Sine. And nobody makes much music with pure (un-layered) sines.
  • SUPPORTER

slacker

#12
You can get a saw from a CD4046, see Thomas Henry's VCO mentioned above however this is at twice the input frequency, so you need to divide your square signal by 2 first, which is easy enough to do using flip flops or a counter like a CD4024. Once you have saw all your other waveforms can be generated from that either using the wave shapers from the same VCO or any number of other methods, most analogue synth VCOs have saw to tri to sine shapers.
The hard bit, as always, is extracting the fundamental of the note you want and generating a clean square in the first place.  

If you want something simple and dirty then you could try this http://www.deviever.com/fx/wp-content/uploads/2012/06/swsh.gif from Tim Escobedo, it will suffer from the same problems as using an integrator but it gets you some saw and triangle-ish action.