Tuesday, May 5, 2026

Class-D Tales: From Unitiy 'til Infinity (which for practical reasons might be approximated as 101)

Foreword

For the newbies

When you start delving into (yeah, I know this is a AI indicator phrase - by I wrote it myself) electronic circuit design this is most likely one of the things you'd encounter rather soon

There is a comparator with a push-pull output generating either a positive voltage Vp or a negative Voltage Vn. This voltage again charges / discharges a capacitor until the capacitor voltage hits a threshold which is a fraction of the output voltage (a.k.a. hysteresis). There are several names for this arrangement like "astable multivibrator" and "RC oscillator" and there is a somewhat more sophisticated version where the capacitor is replaced with an active integrator.

This circuit doesn't only generate a square wave but also a triangle wave and as I already pointed out [1] by adding one resistor the circuit starts acting as a PWM modulator. In this context some DTU people coined the term "astable integrating multivibrator (AIM)" and Stefan Wehmeier opted for calling it "self oscillating digital feedback amplifier (SODFA)" even if it is very far from being digital.

As the input voltage is varied the dutycycle follows proportionally. But the frequency of the pulsetrain doesn't remain constant. However, for this circuit it is possible to find the relationship between switching frequency and modulation index (which is another way of expressing the duty cycle) symbolically as can be seen here (sorry for german / I stripped this from a larger document so this is why it looks a bit weird).
Unfortunately, for other circuits it's not possible to perform such easy symbolic analysis.

Remark: related terms are (among others): "bang bang control", "sliding mode control", etc.

For the veterans

A lot of people are convinced that comparator and switching stage can be seen as a unit called 'power comparator' [MEY06a] and demand it to be as fast as possible in order to improve linearity (remember that!). Stefan Wehmeier is one of them - which he unmistakably documented elsewhere [2].

For the switching stage itself this guiding principle is perfectly fine as slow transistors require more dead time in order to stay cool which again creates more distortion for which you will need more loopgain to compensate for. However, fast comparators such as the LT1713 mentioned by Wehmeier tend to be pretty good 'HF junk to NF noise converters' - which is probably not what you want in the first place.

Well, wait a second. What was that? Instead of spending money on fancy wide bandgap switches [3] one could simply use an opamp and a few passives for increasing loopgain in order to get low distortion... Sounds cool? Yes, but increased loopgain tends to make the Class-D loop unstable.

Wait again. It was said that a (self-osc.) Class-D loop cannot go unstable as it already oscillates [4]. The thing here is that when a linear amplifier goes unstable it starts oscillating. Instability in a Class-D loop means that it switches at an undesired frequency. Which could lead to thermal destruction.


About methods

Obviously it would be nice if one could predict the behavior of such loop. And there are three methods of doing so.

The brute force method

Put your circuit in a simulator and see what happens. The problem with that: optimization can only be done manually and will be a very cumbersome process because you will start multiple simulations (e.g. one for distortion, one for clipping behavior, etc.) per parametrization just to judge the result by eyeballing.


The universal method

Bruno claims to have found a mathematical model that takes into account the sampling nature of a Class-D loop (the SMPA is only sensitive for 'changes within the loop' during the switching process of the comparator) and therefore precisely predicts what happens. However, he wants to keep this as a trade secret [5]. 

His work is based on the findings presented in [RIS05] of which he says that he did not understand the math in the first place [4]. Personally I guess that I still haven't understood yet.

But I do have a guess:

  • Lars directly figured out that his comparator model 'just' works around 50% duty cycle. There it allows for finding the comparator gain as a function of frequency which perfectly matches the measured response using a bode analyzer. Obviously this is a huge step forward considering that until then the best approximation was a constant factor to be found by treating the comparator input as an independent signal [PUZ05].  
  • Look at the picture above called 'Figure 6' I took from his paper. Here he shows the waveforms of the 'clampled integrator comparator model' which is the basis for his further analysis. From the carrier c(t) he derives one slope factor.
  • Now my first guess is that his model works because of the implicit assumption that the slope at the subsequent zero crossing of the carrier ('falling edge') is identical.
  • And my second guess is that this is only true at 50% duty cycle. Look at the picture below called 'Figure 7' I took from [PUZ09] which depicts a carrier residual at 30%. The green line is clearly steeper than the red one. 

Apparently Bruno found a way to extend Lars' model at exactly this point...

The free method

So (unfortunately) the only thing that is left is the method / model Bruno disclosed in [PUZ09]. First of all he comes up with this:

There is an input, a feedback from the output, a LTI function H(s) and a power comparator. He states:

" 

A self-oscillating amplifier is essentially a square wave oscillator constructed as a comparator with a linear function wrapped around it. 

"

Believe me or not - there is a shitload of wisdom in these words! This is it. This is the archetype of an SMPA (I promised to come up with that [1])! Want to clock it? No problem, it's just another input [KEM12]. PSC? HC? No problem. One model fits all.

Subsequently, he starts building a criterion for the oscillation condition - referring to the figure above where I added my red and green lines:
" 
In a self-oscillating amplifier, frequency f and duty cycle h are dependent. A given combination of duty cycle and frequency is an oscillation condition if there exists a voltage V0 that, when compared against the output of the loop function driven by a square wave of said frequency and duty cycle, produces another identical square wave 
"

This already smells like an algorithm! Choose h, vary f and at some point the two square waves perfectly match. Still, executing that algorithm sounds like a lot of work. But the good thing is that it can be rewritten as a mathematical statement. For that he first provides us with Fourier series representation of a square wave that has 

  • an amplitude of 1 and -1 
  • a dutycycle h between 0 and 1 
  • a frequency f 
  • a first rising edge at t=0
  • a first falling edge at t=h/f

But wait, there is a problem. I did the math and can tell you that the sum starts at 1. Why is that? Starting with the inital cn-definition the sum runs from -inf to +inf. He then splits this sum into three parts:

  • the 'negative half' of the sum from -inf til -1
  • the 'positive half' of the sum from 1 til +inf
  • the DC coefficient c0
    • which turns out to equal 2h-1

 
Further inspection reveals that the lower half of the sum just equals the complex conjugate of the upper half of the sum. This means that the result of the addition equals two time the real part of one half of the sum of which it is more convenient to use the positive one - which starts at 1.

However, at the point where he finally derives the oscillation criterion everything is fine and the sum starts at 1: 

Bruno further points out that an equivalent expression looks like this:


Practical implementation

So, what do we need to actually work with that?

First of all we need to realize several things:

  • The 'Laplace s' is defined as s = i · ω = 2i · π · f
    • so the term H(2i · π · f · n) is another way of writing H(s · n)
  • There is no need to calculate the sum until +inf as there is not much energy (information) in the higher harmonics
    • Let's assume that the switching frequency to be found between 1 kHz and 500 kHz and that stopping the summation after 100 terms is sufficient. Then we need to know H(s) up to 50 MHz.
  • When running an .ac simulation in LTspice it is possible to extract H(s) in a usable format into a text file by selecting the waveform window, clicking File -> Export and choosing "Cartesian: re,im" from the format drop-down menue
    • The appropriate simulation statement would be: .ac lin 65535 1k 50meg

Here you can find the LTSpice file and H(s) output for the 'Fig. 2' example circuit in [PUZ09]:


Some years ago I put together a two step approach of dealing with this:

  • first I manually stripped the text file to plain CSV
  • second this was loaded into octave where a script did all the calculations
    • as LTspice can only output 65535 frequency points everything is interpolated to 20 Hz steps
    • create a duty cycle vector holding suitably spaced values between 0.05 and 0.95 or so
    • calculate the left portion of the equation above in order to retrieve one phase plot per element in the duty cycle vector
    • search for zero crossings in phase to determine the switching frequency per duty cycle


But wait, there's more!

Combing back to "Figure 7" which I used to draw the green and red line you will notice that there is an offset between V0 and the average of Vmod which is the effective DC at the comparator input. It is further shown in the paper that this can be calculated by evaluating the following expression:


The evaluation now works by inserting known combinations of f and h and calculating the sum accordingly. However, it should again start at 1. By calculating the derivative of this DC input term it is possible to obtain the actual DC gain of the modulator - which is basically nothing less than its linearity. Apparently, this linearity is 'just' a function of H(s). Chew on that for a while!

As I wanted to practice my vibe coding skills I used an LLM to combine the two steps into one python script together with some improvements to the old octave thingy. It can be downloaded here.


About optimization

What optimization?

Well, what have we gained so far? It is possible to predict switching frequency and modulator linearity at once but the actual tuning of a circuit is still requires brute force action - i.e. running the script for several H(s)

But this can be changed! Let's go back to the loop I presented in an earlier post [6]. 



This circuit can be split into a combination of a 'constant' Hc(s) and a parametric, tuneable Hp(s). The first (depicted in green) comprises components that are chosen due to criteria which are not (directly) linked to loopgain and modulator linearity - such as:
  • The output LC filter (15ish µH and 2ish µF is usually a good choice)
  • The feedback network (where one sets the overall gain and eventually adjusts the overall frequency response)
  • The propagation delay of comparator, driver and power stage (which is just there)
  • Minor contributors (such as a summing amplifier adding another pole at higher frequencies in order to fine-tune the switching frequency)
The latter comprises all other parts of the loop which are meant to increase the loopgain within the audio band. By expressing the transfer function of such (opamp) circuits in the Laplace domain it is rather simple to derive Hp(s) as a function of component values (or more abstract auxiliary values such as Q and f). By pre-fixing some of the components (e.g. the resistors shown in red) and limiting the values of other components to feasible ranges the complexity of the problem can be reduced.

Wait, which problem? Well, now it is possible to let a numerical optimization find these component values which (for example) result in the least possible deviation of the normalized DC-gain from unity.

That's it! Brute force is gone! However, I'll leave this part of the implementation as an exercise for the reader ;-)

For reference

Putting the NAD M22 loop [7] into the simulator yields the following result:


The normalized modulator gain stays around unitiy up to |m|=0.8 which means that the amplifier makes it well up to 0.64 times it's nominal output power until modulator distortion starts kicking in.

That's remarkable!


Cheers,
P.

No comments:

Post a Comment