Square + triangle = sine (almost)

H

Harold Larsen

Jan 1, 1970
0
If a squarewave contains all odd harmonics of the fundamental
frequency, and a triangle all even, will I get ALL harmonics if I mix
the two waveforms?

It looks like a cross between a squarewave and sinewave.

I have not seen any tech references to the practical value of this.
Does it have any?

For example, to roughly approximate a sinewave without filtering.

Harold Larsen
 
R

Ron Tanner

Jan 1, 1970
0
"Harold Larsen"


** Sorry - that is WRONG .

A triangle wave contains only odd harmonics too.

http://en.wikipedia.org/wiki/Triangle_wave

A "sawtooth" wave contains all integer harmonics.

OK thanks for the pull-up, but how about using a triangle-square wave
mix, in place of a filter, to simulate a sinewave .

I have not seen that method applied or described anywhere, but it
makes a fair approximation, at least to my eye.

Harold Larsen
 
P

Phil Allison

Jan 1, 1970
0
"Ron Tanner"
"Phil Allison"
OK thanks for the pull-up, but how about using a triangle-square wave
mix, in place of a filter, to simulate a sinewave .

I have not seen that method applied or described anywhere, but it
makes a fair approximation, at least to my eye.

** Maybe you need better eyes.

Ever noticed how sine waves are flat topped and pass through zero at a 45
degree angle ?

Not much like your hut with pitched roof wave.......



...... Phil
 
D

D from BC

Jan 1, 1970
0
OK thanks for the pull-up, but how about using a triangle-square wave
mix, in place of a filter, to simulate a sinewave .

I have not seen that method applied or described anywhere, but it
makes a fair approximation, at least to my eye.

Harold Larsen


This reminds of the XR2206 chip that makes square, triangle and sine
using analog technology.
 
K

Kevin McMurtrie

Jan 1, 1970
0
If a squarewave contains all odd harmonics of the fundamental
frequency, and a triangle all even, will I get ALL harmonics if I mix
the two waveforms?

It looks like a cross between a squarewave and sinewave.

I have not seen any tech references to the practical value of this.
Does it have any?

For example, to roughly approximate a sinewave without filtering.

Harold Larsen

Heh, no that doesn't work.

The usual way to approximate a sine wave is to blunt the sharp tips off
a triangle wave with diodes. With enough tweaking it gets very close.
 
B

Ban

Jan 1, 1970
0
Bitrex said:
You can approximate a sine wave by putting a triangle wave through a
circuit that has a hyperbolic tangent shaped transfer function. The
following circuit (from "Musical Applications of Microprocessors " by
Hal Chamberlin)approximates that function by using the conduction
characteristics of two back to back diodes at low currents:


Triangle in 14V pk-pk

o-------o--------------------
.-. | .-.
| | - | |
1M | | ^ | | 150
'-' | '-'
| | |
| | |
| | |-+
| | |
-o--------o------>|-+ Sine out 1V pk-pk
| |
| | o---------o
.-. | .-.
1M | | | | |
| | V | | 150
'-' - '-'
| - |
---------|-----------
===
GND

(created by AACircuit v1.28.6 beta 04/19/05 www.tech-chat.de)


Though I haven't tried to do it the author claims that with precision
components and adjustment the circuit can be adjusted to under 1%
harmonic distortion. You could do a similar thing with a differential
amplifier or an OTA.

If this circuit is really published the way you drew it, it shows how little
a uP guy knows about analogue. The distortion may be even higher than of the
triangle wave at the input, and <1% you can get only with 6 turn points if
adjusted well.
A differential transistor stage OTOH is capable of sine-shaping with a
minimum of 1.3% THD, with an additional clipping of the tops you can reach
almost 0.4%.
Another possibility is to develop the sine function into a power series
sinx = x - x^3/3! + x^5/5! - ... using only the first 2 terms you get 0.6%
THD, but you need 2 analog multipliers for that. Slightly modifying the
coefficients even 0.25% can be reached. This is very useful if the sin is to
be differentiated later.

ciao Ban
 
M

Martin Brown

Jan 1, 1970
0
Harold said:
If a squarewave contains all odd harmonics of the fundamental
frequency, and a triangle all even, will I get ALL harmonics if I mix
the two waveforms?

It looks like a cross between a squarewave and sinewave.

Not in this world it doesn't. Both contain only the odd harmonics but in
varying amounts. You get from square to triangle by integrating it.
_ _ _
_| |_| |_| |_

A square wave is sum (-1)^(2n+1).sin((2n+1)wt)/(2n+1) n=0 .. inf

When you integrate a square wave you get a triangle wave - usually
available off the timing capacitor with a bit of buffering.

/\ /\ /\
\/ \/ \/

The expression for the square wave can be integrated to give:

A triangle wave is sum sin((2n+1)wt)/(2n+1)^2 n=0 .. inf

You could take the linear combination of triangle + square/3 to null out
the third harmonic but the waveform would look nothing like a sine wave
because of all the other uncancelled higher harmonics.

And the zero crossing would be perpendicular which is not right.
I have not seen any tech references to the practical value of this.
Does it have any?

None at all.
For example, to roughly approximate a sinewave without filtering.

A much better way ISTR originally poineered by HP is to take a triangle
wave and apply diode shaping to it. First order is to just clip the top
off and the next order chamfers the rough edges then a low pass filter.

Neater methods by varying gain with amplitude exist too. Although the
neatest of all is probably based on log shaping. Almost all of these
tricks have been displaced by direct digital synthesis now.

Natsemi has an app note that reviews sine generation methods that you
might find interesting:

http://www.nalanda.nitc.ac.in/industry/appnotes/Natsemi/AN-263.pdf

And venerable Intersil ICL8038 part that first embodied square, triangle
and a sinewave shaper on one chip is still online at

http://www.intersil.com/data/fn/fn2864.pdf

Regards,
Martin Brown
 
T

Tim Williams

Jan 1, 1970
0
Ban said:
Another possibility is to develop the sine function into a power series
sinx = x - x^3/3! + x^5/5! - ... using only the first 2 terms you get
0.6% THD, but you need 2 analog multipliers for that. Slightly modifying
the coefficients even 0.25% can be reached. This is very useful if the sin
is to be differentiated later.

I recall reading about an extension of fT multiplier and analog multiplier
(Gilbert cell) type circuits, where you basically join more B-E's and
collectors together in the right pattern and ratio of areas to create a sine
(or cosine) function approximation directly, by adding up subsequent terms
of the Taylor expansion. Cool.

Tim
 
B

Ban

Jan 1, 1970
0
Bitrex said:
Yep, the circuit is exactly the way it's drawn in the book - the FET
is listed as a 2N3819. When I built the circuit I think it gave me a
THD of like 10%, so I was wondering what black magic the author was
using to get it below 1%. Looking at it more carefully I can
understand why, it's an approximation to an approximation - the curve
of the hyperbolic tangent function (e^2x -1)/(e^2x + 1) which
approximates a sine is itself approximated by an ordinary diode law
exponential. I think the reason it was included is that it's cheap:
at the time the book was published (1980) OTAs probably cost the
equivalent of $10 each and if someone were assembling a "voice per
board" type synthesizer with a lot of voices the cost of an OTA and
assorted components to make a sine wave for each voice might become
prohibitive. In a synthesizer perhaps they figure the signal is just
going to be stuffed through a low pass VCF anyhow so the THD is not
such a big deal.
I like the idea of using a Taylor series to generate a sine transfer
function; what kind of multiplier would you use to raise the input to
the 3rd and 5th powers? Some kind of translinear network?

.-------\
.--| | \ .------\
o--o---+ | X | >----| | \ .---------.
Vin | '--| | / | X | >----|-0.543 |
| '-------/ .--| | / | |---o
| | '------/ .--|+1.543 |
| | | '---------'
| | |
'------------------o-------------'
(created by AACircuit v1.28.6 beta 04/19/05 www.tech-chat.de)

You need only the 3rd power for my above stated accuracy. With the shown
coefficients for the subtraction you get 0.25% THD.
 
B

Ban

Jan 1, 1970
0
Darwin said:
As pointed out by other participants, you can obtain a sine wave from
a triangle wave thanks to a nonlinear transform of the signal.
The National Semiconductor application note 263 is worth reading and
contains a paragraph dedicated to those techniques:

http://www.national.com/an/AN/AN-263.pdf

(see "Approximation Methods" paragraph beginning at page 8)

Hope it helps.

I downloaded the paper, but what they call *logarithmic* is IMHO *tanh* and
that opamp is not connected very smart either (FIG. 11).
 
L

legg

Jan 1, 1970
0
OK thanks for the pull-up, but how about using a triangle-square wave
mix, in place of a filter, to simulate a sinewave .

I have not seen that method applied or described anywhere, but it
makes a fair approximation, at least to my eye.

Harold Larsen
Maybe the news reader is confused, but 'Larsen' just posted as
'Tanner'.

RL
 
J

JosephKK

Jan 1, 1970
0
This reminds of the XR2206 chip that makes square, triangle and sine
using analog technology.

Sure enough, as does the ICL8038. Part of the question is how it is done.
 
T

Tim Williams

Jan 1, 1970
0
whit3rd said:
The output of the op amp then is fed to the Schmitt trigger (a '555
does this without the op amp, but its triangle waves are curvey
because of that).

You can use diode gates to divert a current source and sink into the cap,
driving the gate with the output pin (since pin 7 doesn't source current).
Then you also get freely adjustable frequency and duty cycle, like a proper
function generator. Add a buffer and you've got a hearty triangle output!

Tim
 
F

Frank-Stefan Müller

Jan 1, 1970
0
Phil said:
"Ron Tanner"
"Phil Allison"

** Maybe you need better eyes.

Ever noticed how sine waves are flat topped and pass through zero at a 45
degree angle ?
In Gemany, the angle is 56.789 degrees, because the mains voltage is
higher...

Frank
 
P

Phil Allison

Jan 1, 1970
0
"Frank-Stefan Müller"

In Gemany, the angle is 56.789 degrees, because the mains voltage is
higher...



** Das Fuhrer has spoken....




...... Phil
 
T

Tim Williams

Jan 1, 1970
0
MooseFET said:
If you use a quad comparator, you can do some interesting stuff. With
just 2 more comparators, you can make this:

------ ------
--- --- --- ---
------

I recollect something from Don Lancaster about Magic Sinewaves and how you
can get arbitrarily low harmonics from certain optimal patterns of on and
off, given sufficiently accurate timing, and I suppose some sort of
filtering. I never did figure out if it's supposed to be a tristate
waveform (as above) or PWM (on/off for varying rates) or multivalued
(minimal bit DAC?) or what.

http://www.tinaja.com/glib/stepsynt.pdf

Ugh. Why does Don. Always have to write. Fragmented sentences.

Looks like it's a PWM tristate thing (requiring an always-on H bridge), but
not really PWM as the edge timings are arbitrary through the cycle. Rather
than microcomputer friendly as claimed in the introduction, I expect such a
generator would be easier to synthesize in an FPGA, since microcontrollers
don't offer timers with lots and lots of counter compare units, and general
microcomputers have awful timing (at best, you'll get single cycle accuracy
in a single-cycle-instruction microcontroller with no possible interrupt
service).

Tim
 
D

Don Klipstein

Jan 1, 1970
0
Sure enough, as does the ICL8038. Part of the question is how it is done.

I have played around with the XR2206 before. It appears to me that the
square and triangle have a derivative/integral relationship to each other.
I seem to think that the triangle is generated current source switching
polarity periodically, such that the current waveform is a squarewave,
alternately charging and discharging a capacitor.

And it appears to me that the sine wave is derived by feeding the
triangle wave through a resistor in series with an inverse-paralleled
pair of diodes or something having similar effect. The sinewave is found
across the antiparallel pair of diodes (or similar circuitry). This
results in the tips of the triangle wave being "squashed" to obtain an
approximation of a sinewave. The peaks of the resulting sinewave are not
perfectly rounded, but show a trace of the pointy tips of the triangle
wave.

The XR2206 has provisions to adjust the symmetry and the degree of
squashing of the sine-to-triangle conversion. When my hearing is in a
good mood, I can adjust the symmetry to minimize even harmonics, and the
degree of squashing to get the 3rd and 5th harmonic low. (The 3rd and 5th
cannot be both reduced to zero simultaneously in my experience). Traces of
odd harmonics higher than the 5th will remain since the peaks of the
sinewave cannot be perfectly smoothed by the triangle-to-sine conversion
circuitry in the XR2206.

- Don Klipstein ([email protected])
 
D

Don Klipstein

Jan 1, 1970
0
In <7f952719-ece0-4a91-bd65-9e981f5c058f@v20g2000yqv.googlegroups.com>,
whit3rd wrote in part:

The linear solution of making an accurate triangle wave, then
distorting, might get from 5% distortion (which is what a triangle
wave is, compared to a sine)

A triangle wave has 12.1% distortion. The 3rd harmonic alone has
voltage of 11.1% of that of the fundamental.
down to 1% or less, is terribly limited, too. There's a theorem (the
Wiener-Hopf theorem) that says your fit functions work best if they have
the same autocorrelation as the thing they fit to... which means a smooth
diode response curve is not going to reduce a step-like square
wave to sinusoid in a small number of stages, EVER.

But, all these 'one percent' solutions don't kill the high harmonics
down to the level of a true sinewave oscillator.
My old HP 204C was worst-case 0.1% ( - 60 dB) on its
distortion right out of the box; compared to the triangle-wave
and breakpoint-diodes of an XR2206 at 2.5% before hand-tweaking.

- Don Klipstein ([email protected])
 
T

Tim Williams

Jan 1, 1970
0
whit3rd said:
The 'magic sinewaves' approach is a variant on the digital filter
theme, using calculated ON/OFF pulses to cancel two or three
of the harmonics... but that only buys you a small reprieve
from the problem, a low-pass filter to take out the higher
harmonics is assumed. Alas, that kills the adjustable-
frequency range, unless you make a (expensive) tracking filter.

Sure, but you could do it adaptively, using higher order magic sines for
lower frequencies. I don't know how much computation or memory that would
require. Sufficiently low frequencies could be driven by PWM instead
(basically DDS with PWM or d-s output). So instead of an expensive tracking
filter, you write a (potentially expensive) sinewave generator.

Practical considerations can change things of course... driving a motor,
it's not really going to matter much, as winding inductance will filter
harmonics, at some expense to efficiency; at low frequencies, the drive will
be rather coggy and the harmonics will be lossy, but the power output is
small, too (think VFD), so efficiency doesn't matter as much. On the other
hand, driving something like a voice coil shaker table, you *must* have
harmonics above a fixed frequency, or else they'll screw up your test
results.

Tim
 
Top