# Class D and triangle wave linearity

#### Wendy

Joined Mar 24, 2008
23,421
There was a discussion not too long ago about the possible distortion from a RC triangle wave compared to a linear triangle wave. I'm attempting to see if there is any using my usual graphic approach.

If anyone remembers this thread, such as Ron H, point me to it please.

The RC waveform was done to scale using this thread, and was done to scale. It is as precision as I can make it. It appears there is very little difference between the two, though I would be the first to admit that the resolution is too low.

To me it appears it would be very usable.
.

#### Attachments

• 18.3 KB Views: 401
Last edited:

#### bertus

Joined Apr 5, 2008
22,277
Hello Bill,

You might take a look at the attached.

Bertus

#### Attachments

• 1.1 MB Views: 174

#### Ron H

Joined Apr 14, 2005
7,063
Here is the thread. I never posted the results of my distortion sim, and it's on my computer in in idaho, while I'm presently in Georgia, visiting my grandkids for Christmas.
I'm currently working on duplicating the sim. The distortion gets worse as the time constant increases as a proportion of the period.

#### thatoneguy

Joined Feb 19, 2009
6,359
I agree they are extremely close.

I will also admit being curious as to how a Class D amp would sound with the RC "Sharktooth" vs pure triangle.

Sometimes our ears disregard minor changes (mp3 compression), yet can pick up the right kind of distortion at low levels (tubes vs transistors, allegedly)

I'm no good at MATLAB, maybe somebody that is can take a 10 second chunk of a song (string quartet, no pre-distorted stuff), then process it to Class D via both Triangle and RC triangle waves with everything else as equal as possible. Once that is done, put both outputs through a low pass filter and come up with a distortion percent. Can this be done in MATLAB?

#### crutschow

Joined Mar 14, 2008
34,433
The non-linearity in the sawtooth would introduce some harmonic distortion into the output filtered waveform which is a no-no, of course, to any audiophile. You'd have to do an A-B listening test to determine how much triangle non-linearity you can have before it becomes noticeable or objectionable.

Since it's relatively easy to generate a very linear sawtooth using an op amp integrator and a couple of comparators, I see no good reason to use an RC exponential for this purpose.

#### Wendy

Joined Mar 24, 2008
23,421
One thing, the 555 exponential triangle wave (as shown) is taking the sweet spot out of the curve. While far from perfect, it is also the best triangle wave you can make using this technique.

Something that may be worth trying, is to have a side by side comparison of a sine wave generated by both techniques to see if the distortion is visible.

#### Wendy

Joined Mar 24, 2008
23,421
Here is the thread. I never posted the results of my distortion sim, and it's on my computer in in idaho, while I'm presently in Georgia, visiting my grandkids for Christmas.
I'm currently working on duplicating the sim. The distortion gets worse as the time constant increases as a proportion of the period.
No hurry, but I am interested in seeing the results.

#### thatoneguy

Joined Feb 19, 2009
6,359
One thing, the 555 exponential triangle wave (as shown) is taking the sweet spot out of the curve. While far from perfect, it is also the best triangle wave you can make using this technique.

Something that may be worth trying, is to have a side by side comparison of a sine wave generated by both techniques to see if the distortion is visible.
If nothing else, make a guitar pedal that mixes the sharktooth waveform somehow, somebody will like the sound.

#### Ron H

Joined Apr 14, 2005
7,063
One thing, the 555 exponential triangle wave (as shown) is taking the sweet spot out of the curve. While far from perfect, it is also the best triangle wave you can make using this technique.

Something that may be worth trying, is to have a side by side comparison of a sine wave generated by both techniques to see if the distortion is visible.
It ain't real purty, but here's a way of getting a triangle with a 555, a couple of trannies, and a bunch of diodes.

I'll post some results on the distortion using an exponential ramp soon, probably sometime on Friday.

#### Attachments

• 19.9 KB Views: 129

#### Wendy

Joined Mar 24, 2008
23,421
I've seen it done with simple current mirror (two transistors, one resistor). It is a ramp, but a linear ramp works as well as a linear triangle.

I'm going to draw up a crude Class D just for kicks.

#### Ron H

Joined Apr 14, 2005
7,063
I ran the sim with a 1kHz signal at almost 100% modulation, and a 100kHz PWM carrier, so that it could handle the audio band, and so I could filter out the carrier and still see the distortion-related harmonics, which are the odd harmonics of 1kHz. The filter is a 10 pole Butterworth, with Fc=15kHz.
I ran both a 100kHz linear triangle and a 100kHz exponential triangle, scaled to cover the range between 1/3 and 2/3 Vcc, where Vcc is 6V (actually, I used ±3V, so the triangles swing between -1V and +1V, but the results are the same).
Note that the 3rd harmonic distortion with the exponential triangle is about 40dB down from the peak.

Here is the subckt for the behaviorial comparator, Compb:
Rich (BB code):
.subckt compb 1 2 3 4 5
*
.param Ron=1k Roff=1Meg Vt=0 Vh=0
S1 N001 3 1 2 pullup
S2 N001 4 2 1 pulldn
C1 N001 0 1f
R1 5 0 30
G1 0 5 N001 0 {1/30}
.model pullup SW (ron={Ron} roff={Roff} vt={Vt} vh={Vh})
.model pulldn SW (ron={Ron} roff={Roff} vt={Vt} vh={Vh})
.ends compb

#### Attachments

• 19.2 KB Views: 63
• 9.4 KB Views: 55
• 9.1 KB Views: 46
• 9.1 KB Views: 51
• 8.7 KB Views: 51
• 3.3 KB Views: 26

#### crutschow

Joined Mar 14, 2008
34,433
I ran the sim with a 1kHz signal at almost 100% modulation, and a 100kHz PWM carrier, so that it could handle the audio band, and so I could filter out the carrier and still see the distortion-related harmonics, which are the odd harmonics of 1kHz. The filter is a 10 pole Butterworth, with Fc=15kHz.
I ran both a 100kHz linear triangle and a 100kHz exponential triangle, scaled to cover the range between 1/3 and 2/3 Vcc, where Vcc is 6V (actually, I used ±3V, so the triangles swing between -1V and +1V, but the results are the same).
Note that the 3rd harmonic distortion with the exponential triangle is about 40dB down from the peak.

.............
Interesting result. Harmonic distortion products 40dB down would be 1% distortion -- audible but perhaps tolerable for casual listening.

#### Wendy

Joined Mar 24, 2008
23,421
I know, shoot through is going to be a problem, especially with the Schmidt Triggers. I may build it to see how much of a problem it is.

#### Attachments

• 4.2 KB Views: 273

#### tom66

Joined May 9, 2009
2,595
Just make sure when testing these designs to have a rock solid Vcc. Any changes in Vcc will be directly reflected onto the output.

Also it's unnecessary to have a push pull design unless your Vcc is too low to provide a decent output. You could use a capacitor to couple the signal. The filter inductor might be optional, as the speaker itself acts as part of the filter, although not in all cases.

#### Wendy

Joined Mar 24, 2008
23,421
The thing is, it is a pure LC filter that should block the carrier, which I'm thinking should be quite high (100Khz or so).

I really do think shoot through is going to be a killer though. I have a back up plan or two to deal with it.

I'll go for max Vcc on the chips, that will define the maximum power out. I probably need to buy a more powerful speaker.

For those whom it isn't obvious, the pot is to balance the sides, and zero the voltage across the speaker when it is quiet.

#### tom66

Joined May 9, 2009
2,595
I really do think shoot through is going to be a killer though. I have a back up plan or two to deal with it.
Prototype? Put a bigger heatsink on the devices . Doing it properly? You can buy gate driver ICs like LTC4442 which have integrated shoot-through protection. You could use a high voltage at the middle node to inhibit the lower gate drive (use a Schmitt AND gate for the bottom) and vice versa for the top. Use a 22 ohm gate resistor to limit ringing.

I'll go for max Vcc on the chips, that will define the maximum power out. I probably need to buy a more powerful speaker.
It's not just max Vcc but making sure the Vcc doesn't ripple or drop under heavy load. If it does, it will add distortion, unless you have feedback to compensate but it still won't be very good. I highly recommend high performance electrolytics (at least 1500u for 30W output @ 12V with 1m of power cabling) right near the battery/power input and you should decouple your MOSFETs with a 2.2u poly and 100n ceramic tied near the drain of the top FET to a good ground with the shortest possible leads. Note high performance != RadioShack specials. Low-impedance electrolytics only, preferably good manufacturers and not CapXon etc.

#### Wendy

Joined Mar 24, 2008
23,421
You miss the point of projects like this, no specialized parts, minimum parts count. Keep It Simple Stupid (KISS). Done correctly you will not need heatsinks, the whole point of of Class D is PWM. The transistors are on/off, and not running in analog. Shoot though would be what generates heat, if the transistors lasted long enough.

Ideally it should be easy to follow and understand, so new users can pick up on it.

Last edited:

#### THE_RB

Joined Feb 11, 2008
5,438
Bill, why not use one of the standalone class-D amp chips that are already out there? There are a heck of a lot of them now and they are simple enough to use.

#### Wendy

Joined Mar 24, 2008
23,421
Again, this is not really the point. This not meant to be a practical circuit per se, but a teaching circuit. If it works it could wind up as a learning project.