1. Please take 30 seconds to register your free account to remove most ads, post topics, make friends, earn reward points at our store, and more!  
    TalkBass.com has been uniting the low end since 1998.  Join us! :)

Class D Illustrated (lots of pics)

Discussion in 'Amps and Cabs [BG]' started by BbbyBld, Jun 12, 2014.

  1. BbbyBld


    Oct 13, 2005
    Meridian, MS
    I was inspired by the EQ discussion thread to run several basic class D simulations in SPICE to illustrate how it works.

    Let's say you were playing a low G and you ran your bass into a preamp...if you looked at the signal for a brief slice of time, it'd probably look a lot like this: audio.JPG
    First, the class D amp will sample the audio. Sampling is done by comparing the audio to a triangle or sawtooth wave that is much higher in frequency. In this case, the sampling frequency is 400KHz, which is close to the frequency range of AM radio broadcasts in the USA. 400KHz has almost become an industry standard...more on that later. Anyway, in the next pic I'm going to overlay this audio wave on top of the saw. In comparison, the saw will just look like a blue bar. Notice that I've dropped a marker at a point on the audio wave:
    audio on saw.JPG
    This picture was just for reference. Now, I'm going to zoom in...

    audio on saw zoomed.JPG

    Now that we are zoomed in, the audio looks like a straight line and you can see the sawtooth wave. Each sawtooth is equivalent to a sampling period. As I mentioned above, the audio is compared to the sawtooth. This is accomplished with an electronic device called...a comparator. This changes our audio wave into a stream of pulses. Now, I'm going to add in the pulses to show how they line up:
    resulting PWM.JPG
    Notice the pulse transitions occur where the audio wave intersects the sawtooth wave. Each pulse represents a sample. Just to make it less confusing (hopefully), here is what the pulses look like by themselves:

    just PWM.JPG
    So what happens when there is no input? In the next pic, I turned the volume knob all the way down so to speak and plotted zero input on top of the saw:

    no input compare with saw.JPG
    Now, I'm going to zoom in and plot the resulting pulses that come out of the comparator. Notice that our input of zero is intersecting the saw right in the middle, which makes the pulses have equal width at the top and bottom. Think about the top part of the pulses as ON, and the bottom part as OFF. Since the length of ON time is equal to the length of OFF time, we have essentially encoded zero.

    no signal PWM.JPG
    So what happens if I inject a + voltage instead of audio? Here you go:

    PWM at signal max.JPG
    Notice that the pulses are extremely narrow at the top because of where the input voltage intersects the saw. Now, I'm going to inject a - voltage...

    PWM at signal min.JPG
    Now the pulses are extremely wide at the top because of where in the input voltage intersects the saw.

    Hopefully it will be clear that unlike a DC voltage which is fixed, and audio waveform is changing constantly, so in the case of class D where we compare the audio with a sawtooth wave, the width of the pulses will be changing constantly. This is called pulse width modulation, or PWM for short.

    So now what? The pulses are amplified because we need enough voltage and current to drive a speaker. Usually the pulses are amplified with MOSFET devices because they are relatively easy to turn on and off quickly, which is important, because in this case, they would be turning on and off 400,000 times a second. Class D amp efficiency stems from the amplification of a signal that is essentially either on or off. Heating in older amplifier designs comes from transistors essentially operating as variable resistors. The transistors in class D amps are essentially operating as switches.

    After the PWM is amplified, it is connected to the speaker output through a passive low pass filter. This filter is very much like a low pass filter found in a speaker cabinet crossover. Here is what the output audio looks like:

    output audio.JPG

    The tech savy here will notice that this would be a pretty darn powerful amp. We have somewhere around +/-100 volts of signal swing and we started with +/- 5 volts. If you compare this pic with the first, you will notice that it's upside down...more on that later.

    I've hit the picture limit with this first post, and I will pick it back up later...
  2. Neat stuff, please continue!
  3. svtb15

    svtb15 Commercial User

    Mar 22, 2004
    Austin,TX - McKinney,TX - NY,NY, - Nashville,TN
    I play it all. Whatever works for the gig
    im in
  4. Awesome post.

    Not trying to tell you what to do, but it might make things more clear for people if the time scale was consistent across all (or at least most) graphs. This is coming from a EE, yada yada, who cares right?

    On another note, what are you using as your input netlist for spice? What simulator are you using?
    Bob Lee (QSC) likes this.
  5. JimmyM


    Apr 11, 2005
    Apopka, FL
    Endorsing: Ampeg Amps, EMG Pickups
    Great stuff, Bobby. I predict it will only take 15 or 20 more read-throughs to understand what you're saying ;) but despite that, I'm sure plenty of folks will understand it and be much appreciative.
    ialma, Mike A, JACink and 4 others like this.
  6. BbbyBld


    Oct 13, 2005
    Meridian, MS
    So, our output audio is a little fuzzy looking. I dropped a marker so we can zoom in and find out why:

    output audio zoomed.JPG
    The fuzziness is called "carrier bleed". It is caused by left over 400KHz PWM that didn't get filtered out all the way. At one time, companies like Peavey used lots of extra filtering to get rid of this as much as possible. It's not audible, but some people don't like it on principal. I mentioned earlier that 400KHz was sort of an industry standard for class D amplifiers. One reason for that is 400KHz is high enough to make the carrier bleed artifacts above the audio range, which means that the filter can be physically smaller, and also it's not so high as to over complicate the design. It's kind of a sweet spot for performance, reliability, and cost.

    So, I mentioned earlier that our output audio is upside down. This is because the amplifier must have feedback from output back to input in order to remain stable. I won't get into that too much, but we are talking about negative feedback, so the signal that is fed back must be out of phase. In order to compensate for that, the phase would be flipped earlier in the preamp so that input and output are in phase.

    Just for fun, I ran the output audio through an 8 ohm load and plotted the output power on top in green...is it what you expected?

    output power.JPG

    One trait that inherent to class D amps is that the input audio must be controlled so that the signal level can't pass above or below the sawtooth. Here's why:

    class d overmodulation.JPG
    ...The PWM stops, so the amp would pass pure DC to the speaker! Notice, the green audio peaks leaving the blue saw area, which halts the red PWM. Instead of switching, we are stuck to one rail or the other. This would usually result in catastrophic failure. Luckily, this is a simulation model that is missing several protection circuits. Preventing this operating condition has resulted in many patents. A good class D amp must clip artificially. Sometimes this sounds okay, and sometimes it sounds terrible. It all depends on the design.

    Anyway, hopefully this helps illustrate the class D principal for those who are interested. I happen to love working with these things, and I enjoy talking about them. There are many ways to skin the cat, but it basically all comes down to this.
    michael tomlin, rdtsc, will33 and 4 others like this.
  7. Interesting read. So why pick a sawtooth over a triangle or sine wave to sample against?
  8. BbbyBld


    Oct 13, 2005
    Meridian, MS
    I use LTspice. It's the best IMO. I won't reveal my netlist because I'm using a lot of tricks to optimize and cut down on simulation time. Now that SMPS and class D are the name of the game, so is simulation and the amount of time that it takes. Even if I put up my LTspice schematic, it wouldn't look like much because I'm using behavioral modeling.

    That's a good question. You wouldn't really want a sine wave because you want to reference against straight lines and you want sharp reset points. Technically, a triangle is the best for audio fidelity, and is more common these days due to self-oscillating class D designs taking over. I may put up some self oscillating sims later, but that's even more complicated. The example above is a traditional "hard-switching", or "direct PWM" way of doing things. In the classic sense, a sawtooth works best with the control pulses needed for artificial clipping and other protection schemes. Basically, it's easier to sync up to a saw than a triangle. Newer topologies have inherent protection against some of these issues.
    CatSquare and Pimmsley like this.
  9. BbbyBld


    Oct 13, 2005
    Meridian, MS
    These views are more typical of what you'd find in class D explanations because you can see more of what happens to the PWM. I ran the same model at 20KHz audio input, which is of course the very top end of human hearing range.

    traditional view.JPG
    Now, I took that PWM, ran it through the MOSFET amplification stage, and overlayed the filtered audio output to the speaker on top:

    traditional view output.JPG
    You will notice that the fidelity is reduced because there is less sampling sawtooth coverage due to the higher input audio frequency. Some may find it interesting that digital audio converters work in nearly the exact same way. This is an illustration of aliasing.

    Here is the input audio in green plotted with amplified output in blue @ 20KHz:

    traditional input to output.JPG
    Last edited: Jun 12, 2014
  10. Fantastic thread and posts ! Thanks.
  11. agedhorse

    agedhorse Supporting Member Commercial User

    Feb 12, 2006
    Davis, CA (USA)
    Development Engineer-Mesa, Product Support-Genz Benz
    Nice work Bobby. Understanding the principles makes the concept of class d and SMPS much less scary and foreign!
    For extra credit, try explaining this to the marketing folks!
    Bob Lee (QSC), dukeorock, Foz and 3 others like this.
  12. Nev375


    Nov 2, 2010
    I don't really understand. But I think the presentation is terrific with all the technical pictures and stuff.
    I really feel if I had just a few more brain cells survive my misspent youth I could probably fathom this information.

    Perhaps I should try a career in marketing.
    agedhorse and JimmyM like this.
  13. Foz


    Jul 26, 2008
    Jax FL USA
    Ah but grasshopper don't see? What Bobby is doing is marketing... at a higher level than the marketing guys can understand. Don't tell em, it would hurt their feelings.
    5port and dukeorock like this.
  14. dincz


    Sep 25, 2010
    Czech Republic
    Is this usually achieved by clipping or by limiting? Once you reach 0% or 100% pulse width, you've got maximum rated power and you can't get any more power out. This is rather different from a class A/B power stage where the rated power is normally at, or close to, the clipping point, but you can still get more power out although the signal is clipped and distorted.

    Could this difference account for the common impression that class D gives less "punch" (lack of headroom?) compared to class A/B with the same rated power output?
  15. teemuk


    Mar 1, 2011
    "Artifical clipping"... well, all it really takes is that the stage providing signal input to comparator is powered from power supply voltages that are below the peaks of the saw wave.

    Like that it's simply amplifier clipping to its rail limits and in general really no different from other amplifiers clipping to their rail limits.

    The output power increases with clipping because of the waveform arithmetics. Take sine wave for example: it has an average power rating and a peak power rating, which is twice as high as the average power rating. When you clip a sine wave it deforms, its amplitude all around increases and consequently this means the average power of such wave must increase too. In the extreme of clipping the wave would turn to a square wave and as said, square wave has twice the mean power of a sine wave (with square waves, peak power and average power are same). In reality it doesn't always work as ideally but this just serves as an example of where that additional power comes from. Important point is though, that it is not power at rated clean output.

    Class D is switching so it's basically outputting square waves and clipping to rails constantly. We don't really care about that. Distortion and clipping wise we care about how much the output deviates from the input. The power rating is for outputted sinusoidal waves anyway, not for outputted square waves. The supply voltage limit of the output stage is in practice simply just similar voltage limitation as it is in conventional class A or class AB amps.

    And if we clip the input signal to comparator the outcome is practically not too different from driving a generic class A/AB amp to clip to its power supply rail limits.

    But you are right that there are other ways to skin the cat with the "artificial" internal clipping: Instead of limiting the output amplitude by means of lower rail voltage one could utilize "clamps" like clipping diodes instead (or possibly much harder operating clamps with more headroom), or simply limit the input signal amplitude overall instead of just clipping the peaks. I think it really comes down to embodiment and since there are dozens and dozens of diffferent types of class-D designs (they may operate by same PWM principle but internal architectures and solutions still can differ drastically) one can't simply make a generalized statement that they handle the signal amplitude limiting like this or like that. I would think though, that conventional limiting would have a time delay in its operation and would have to be coupled to much faster peak clipping in addition.

    I think the only real way to find out how the limiting is handled is evaluate each design as is, case specifically. Either by examining actual amplifier schematics, datasheets of integrated chips possibly utilized in the circuitry, or most likely both.

    I don't think it's a "common impression", more likely a self-perpetuating myth. Besides, you can pick amps of very same topology and find specimens that seem to give out "less punch" than some others. "Punchyness" really does have many other factors besides the class of operation in addition.
    Last edited: Jun 15, 2014
    Foz and agedhorse like this.
  16. teemuk


    Mar 1, 2011

    This is an excerpt from Texas Instrument Overture series datasheets.


    I'm not saying that each and every manufacturer of class-D circuits deals with the issue the same way but overall you can find several patents concerning it that try to solve the "over-modulation" issue with some suitable circuitry.
    Last edited: Jun 15, 2014
    rdtsc likes this.
  17. BbbyBld


    Oct 13, 2005
    Meridian, MS
    @teemuk...The TI datasheet clip is illustrating artificial clipping.

    If you simply clip the signal before the comparator, you will lose about 1/3 of potential output power once you clip at a point where you prevent overmodulation.

    Aother thing to remember is that the gain of the modulator factors in to the gain of the power amp. Feedback works against this gain.
  18. michaelandrew

    michaelandrew The bass player is always right.

  19. SunnBass

    SunnBass All these blankets saved my life.

    Aug 31, 2010
    Columbia, Mo
    I'm scared, I need an adult, or a translator.:nailbiting:
    Linnin likes this.
  20. spankdaplank


    Jan 19, 2003
    Now that you have described what has to take place for the magic to happen, I am more worried then ever that one of the bazillion surface mount components in my amp is going to go POP and end the party permanently. I will think of you, Mr. Baldwin, as I lie awake tonight trying to resolve it all in my feeble mind.