Magic Sinewave Analysis using SPICE and a Simple Inverter Circuit

Robert Ackermann

Magic Sinewave pulse sequences, in this demonstration, drive H-bridge control gates (nodes 8, 9, 10, and 11 in the following schematic) associated with a simulated inverter circuit that produces a pure sinewave output. Circuit simulation and analysis is accomplished with the ngspice implementation of SPICE.

The H-bridge is constructed from four (X1, X2, X3, and X4) n-channel MOSFET devices that have an available SPICE subcircuit model (sihlz34s.lib). Experimenters may also consider substituting IGBT components and modules for the H-bridge role. The H-bridge is connected to a 12V, high-current source (V1). The H-bridge output (between nodes 2 and 3) generates full-cycle Magic Sinewave pulse sequences which spectrally contain a fundamental (60Hz) of desired amplitude, a chosen number of low-harmonics of zero amplitude, and higher harmonics of various amplitudes (see Don Lancaster's articles and calculator). The higher harmonics are removed by a low-pass filter (components L1, C1, and L2). A 1:16 step-up transformer (mutually coupled L3 and L4) increases the H-bridge output Magic Sinewave low-voltage amplitude to mains voltage amplitude. The load (R1) represents a 60W incandescent light bulb.

This is a demonstration of the characteristics and advantages of Magic Sinewave pulse sequences. It is not a complete reference design for an inverter.

Not much effort has been put into the low-pass filter design. The performance of the type of filter shown is dependent on the load impedance. For this demonstration, the filter is specifically tuned for a 60W nonreactive load (as seen through the transformer). A consideration was made, however, to move the cut-off frequency far to the right of the fundamental — while maintaining sufficient harmonic suppression — such that the filter phase shift does not make the load appear significantly reactive, which would result in increased distortion. For some applications, a more sophisticated filter will be desired. For other applications, no filter at all will be required. This SPICE inverter model can be modified to experiment with different methods of filtering the higher harmonics.

A Python utility program (buildsubckt.py) — that takes standard single-phase Magic Sinewave calculator (0 through 90 degree) pulse edge angle solutions as input — has been developed to automatically generate a SPICE subcircuit which generates, during transient analysis, Magic Sinewave pulse voltage waveforms appropriate for controlling the H-bridge input gates (nodes 8, 9, 10, and 11) over continuous full cycles:

    - it can accept output piped from bbemscalcnode.js

$ node bbemscalcnode.js -p 7 -a 0.875 | python buildsubckt.py >msp7a0875.lib

    - or it can accept, with a front-end filter, pulse angle-position pairs exported from Don Lancaster's calculator:

$ cat <<EOF | \
> awk '/ *[.0-9]+ +% +p/ {if(n==1){print x,$1;n=0}else{x=$1;n=1}}' | \
>  python buildsubckt.py >msp7a0875.lib
>  /angs87.5 [  % angle-position pairs 
>   11.1631494002 %  p1s 
>   13.4408124389 %  p1e 
>   22.4075819925 %  p2s 
>   26.9005175327 %  p2e 
>   33.8209337512 %  p3s 
>   40.4078895924 %  p3e 
>   45.5066429147 %  p4s 
>   54.0178871981 %  p4e 
>   57.6014119766 %  p5s 
>   67.8356547587 %  p5e 
>   70.3025529904 %  p6s 
>   81.9748444687 %  p6e 
>   83.8322930895 %  p7s 
>   90 %  p7e 
>    ] store
> EOF

The following is a listing of the SPICE subcircuit (msp7a0875.lib) generated as a result of the example commands shown above which specify as input a Bridged Best-Efficiency, 7 pulse, 0.875 amplitude Magic Sinewave solution:

.SUBCKT MAGSIN 1 2 3 4
* This is not a reference design for an H-bridge driver circuit.  This
* subcircuit generates H-bridge gate voltages driven by Magic Sinewave
* pulse sequences in the simplest way (that I could think of)
* Node 1 - right high side
* Node 2 - right low side
* Node 3 - left high side
* Node 4 - left low side
V1 5 0 DC 6
* En +out -out +cntrl -cntrl gain
E1 1 0 6 0 234
E2 5 2 6 0 78
E3 3 0 7 0 234
E4 5 4 7 0 78
R1 8 6 1000
V2 8 0 PULSE(0, 1, 0.0005168125, 0.0000001000, 0.0000001000, 0.0001054474, 0.0166666667)
R2 9 6 1000
V3 9 0 PULSE(0, 1, 0.0010373881, 0.0000001000, 0.0000001000, 0.0002080063, 0.0166666667)
R3 10 6 1000
V4 10 0 PULSE(0, 1, 0.0015657840, 0.0000001000, 0.0000001000, 0.0003049517, 0.0166666667)
... some PULSE statements removed to shorten listing ...
R24 31 7 1000
V25 31 0 PULSE(0, 1, 0.0147959310, 0.0000001000, 0.0000001000, 0.0003049517, 0.0166666667)
R25 32 7 1000
V26 32 0 PULSE(0, 1, 0.0154212723, 0.0000001000, 0.0000001000, 0.0002080063, 0.0166666667)
R26 33 7 1000
V27 33 0 PULSE(0, 1, 0.0160444068, 0.0000001000, 0.0000001000, 0.0001054474, 0.0166666667)
.ENDS

And, here is a listing of the main SPICE "deck" (msanalysis.net) which contains, along with additional control "cards," the netlist specifying the inverter circuit found in the schematic at the top of this page:

Magic Sinewave analysis through simple inverter example
.include msp7a0875.lib
.include sihlz34s.lib
V1 99 0 DC 12
R99 99 1 0.0001
X1 1 8 3 irlz34ns
X2 1 10 2 irlz34ns
X3 3 9 0 irlz34ns
X4 2 11 0 irlz34ns
X5 10 11 8 9 MAGSIN
L1 2 4 265e-6
C1 4 3 531e-6
L2 4 5 265e-6
*R98 5 3 .8 
L3 5 3 1
L4 6 7 256
K1 L3 L4 0.9999
R1 6 7 240 
R98 3 7 1000000
.options set fourgridsize=1000000
.options set nfreqs=100
* commented out cards below because I am going to
* work interactively
*.TRAN 0.00000005 0.05
*.TRAN 0.00005 0.05
*.PLOT TRAN V(2,3)
*.PRINT TRAN V(5,3)
*.FOUR 60 V(6,7)
.END

The SPICE "deck" (listed just above) includes the subcircuit (msp7a0875.lib) that generates Magic Sinewave pulse waveforms for the H-bridge and the subcircuit (sihlz34s.lib) that specifies a model for the n-channel MOSFET devices. The node numbers in the netlist correspond with the node numbers found in the schematic. For example, the twelfth line "C1 4 3 531e-6" specifies a 531μF capacitor connected from node 4 to node 3, which is found in the low-pass filter section of the inverter circuit.

The main SPICE "deck" is loaded into ngspice and then a transient analysis is performed, at sufficient resolution, over one 60Hz cycle. A time-series for each of the four H-bridge gate voltages is plotted:

$ ngspice msanalysis.net

ngspice-23 : Circuit level simulation program
... some output removed ...
Circuit: magic sinewave analysis through simple inverter example

ngspice 1 -> tran 0.0000166666 0.0166666
ngspice 2 -> plot V(10)
ngspice 3 -> plot V(11)
ngspice 4 -> plot V(8)
ngspice 5 -> plot V(9)

Note: the vertical scales representing voltage for the high-side and low-side plots differ. The high-side (n-channel) MOSFETs require a gate voltage that rises above the 12V source. When a high-side MOSFET is conducting the corresponding low-side MOSFET on the same leg is not conducting. When neither of the high-side MOSFETs are conducting, both of the low-side MOSFETs are conducting.

A time-series plot of the voltage between nodes 2 and 3 reveals, as expected, that the H-bridge is generating as output a full-cycle (360 degree) Magic Sinewave pulse sequence in response to the control waveforms on its input gates. There is a slight distortion evident in the plot which disappears when the low-pass filter is disconnected and a resistor of equal effective load (compared with R1 seen through the transformer) is placed directly between nodes 2 and 3. This model can be augmented to further investigate and potentially compensate for effects introduced by the phase and transient response of the low-pass filter.

ngspice 6 -> plot V(2,3)

A new transient analysis is performed over four cycles at a higher resolution appropriate for accurate Fourier analysis. The H-bridge full-cycle Magic Sinewave pulse sequence generated between nodes 2 and 3 is plotted again (this time four cycles) for verification:

$ ngspice msanalysis.net

ngspice-23 : Circuit level simulation program
... some output removed ...
Circuit: magic sinewave analysis through simple inverter example

ngspice 1 -> tran 0.00000006666 0.06736
No. of Data Rows : 1019842
ngspice 2 -> plot V(2,3)

A plot (below) of the voltage presented to the load, between nodes 6 and 7 following the low-pass filter and step-up transformer, reveals a reasonably pure sinusoidal waveform. There is some distortion displayed in the first quarter cycle due to the filter components transitioning from their initial state.

Readers that have, through experience, a feel for analog filter types, filter order, and their effect on general waveforms, should have an appreciation for how little of the Magic Sinewave pulse sequence (other than the fundamental) makes it through the modest filter implemented in this simulation. This is due to the fact that low harmonics for Magic Sinewave pulse sequences, other than the fundamental, have zero amplitude. For the 7 pulse Magic Sinewave employed in this demonstration, the first 26 (4 * pulses/quadrant - 2) harmonics have zero amplitude. Somewhat counterintuitively, a "simple" square wave at 60Hz fundamental frequency, albeit with resulting corner-rounding and ripple, would pass through the low-pass filter as implemented (3dB down at 600Hz) relatively intact. It is tempting to demonstrate that here, but I will do so in a separate post.

ngspice 3 -> plot V(6,7)

Fourier analysis on the sinusoidal waveform inverter output (nodes 6 and 7) measures a total harmonic distortion of 0.77%   The 151 volt amplitude of the fundamental (see table below) is a few volts shy of the peak voltage required to match nominal U.S. 110V RMS mains voltage. An adjustment can easily be made by increasing the amplitude of the Magic Sinewave solution. To satisfy some applications, the Magic Sinewave amplitude can be changed adaptively to accommodate varying loads. Note: "changing the amplitude of the Magic Sinewave solution" refers here to an adjustment in position and widths of the pulses, not a change in the pulse waveform voltage ("height").

ngspice 4 -> fourier 60 V(6,7)

  No. Harmonics: 100, THD: 0.768851 %, Gridsize: 1000000, Interpolation Degree: 1

Harmonic Frequency   Magnitude   Phase       Norm. Mag   Norm. Phase
-------- ---------   ---------   -----       ---------   -----------
 0       0           -0.031316   0           0           0          
 1       60          151.382     -1.0509     1           0          
 2       120         0.000401301 83.158      2.65092e-06 84.2088    
 3       180         0.0474222   -7.7573     0.000313262 -6.7065    
 4       240         6.72827e-06 118.29      4.44457e-08 119.34     
 5       300         0.00791262  9.06147     5.22693e-05 10.1123    
 6       360         2.46017e-05 115.981     1.62514e-07 117.032    
 7       420         0.0066997   12.6979     4.4257e-05  13.7487    
 8       480         1.29708e-05 14.4592     8.56824e-08 15.51      
 9       540         0.00436806  -40.462     2.88546e-05 -39.411    
 10      600         1.27634e-05 -116.84     8.43128e-08 -115.79    
 11      660         0.000881844 -59.516     5.8253e-06  -58.465    
 12      720         5.15231e-06 -121.25     3.40352e-08 -120.2     
 13      780         0.000169852 -46.105     1.12201e-06 -45.054    
 14      840         4.38448e-06 -162.02     2.89631e-08 -160.97    
 15      900         1.94147e-05 -157.44     1.2825e-07  -156.39    
 16      960         2.24248e-06 -148.44     1.48134e-08 -147.38    
 17      1020        9.95186e-05 -168.1      6.57401e-07 -167.05    
 18      1080        1.70762e-06 -161.19     1.12802e-08 -160.14    
 19      1140        0.000101702 -142.44     6.71822e-07 -141.39    
 20      1200        1.63422e-06 -168.71     1.07953e-08 -167.66    
 21      1260        0.000198376 -114.87     1.31043e-06 -113.82    
 22      1320        1.34116e-06 -148.11     8.85942e-09 -147.06    
 23      1380        6.87704e-05 -95.1       4.54285e-07 -94.049    
 24      1440        1.69876e-06 -164.67     1.12217e-08 -163.62    
 25      1500        0.000878678 -82.249     5.80439e-06 -81.199    
 26      1560        3.96438e-06 -174.56     2.61879e-08 -173.51    
 27      1620        1.06548     -32.101     0.00703837  -31.05     
 28      1680        1.6573e-06  43.9195     1.09478e-08 44.9704    
 29      1740        0.0375542   177.082     0.000248076 178.133    
 30      1800        1.08584e-06 121.466     7.17283e-09 122.517    
 31      1860        0.428928    -154.07     0.00283342  -153.02    
 32      1920        1.12694e-06 -138.01     7.44435e-09 -136.96    
 33      1980        0.157085    -124.91     0.00103768  -123.86    
 34      2040        7.26897e-07 -149.89     4.80175e-09 -148.84    
 35      2100        0.0233617   -95.67      0.000154323 -94.62     
 36      2160        6.30543e-07 -174.84     4.16525e-09 -173.79    
 37      2220        0.00194652  -66.372     1.28584e-05 -65.321    
 38      2280        5.83433e-07 -176.01     3.85405e-09 -174.96    
 39      2340        0.000207657 -36.879     1.37174e-06 -35.828    
 40      2400        6.18721e-07 -170.41     4.08715e-09 -169.35    
 41      2460        0.000196344 172.772     1.29701e-06 173.823    
 42      2520        5.47244e-07 -170.56     3.615e-09   -169.5     
 43      2580        0.000518977 22.2494     3.42827e-06 23.3003    
 44      2640        5.45036e-07 -170.73     3.60041e-09 -169.68    
 45      2700        0.00129682  -128.19     8.56656e-06 -127.14    
 46      2760        5.12174e-07 -170.8      3.38333e-09 -169.75    
 47      2820        0.00325663  81.4138     2.15127e-05 82.4647    
 48      2880        5.02915e-07 -172.68     3.32216e-09 -171.63    
 49      2940        0.00829746  -68.954     5.48115e-05 -67.904    
 50      3000        4.27048e-07 -170.71     2.821e-09   -169.66    
 51      3060        0.0215058   140.71      0.000142063 141.761    
 52      3120        5.85947e-07 -164.7      3.87066e-09 -163.65    
 53      3180        0.0689699   -9.6487     0.000455603 -8.5978    
 54      3240        4.00309e-07 167.966     2.64437e-09 169.017    
 55      3300        0.00276586  -159.95     1.82708e-05 -158.9     
 56      3360        4.0813e-07  -171.07     2.69603e-09 -170.02    
 57      3420        0.0016493   -130.54     1.0895e-05  -129.49    
 58      3480        3.43957e-07 -169.56     2.27211e-09 -168.51    
 59      3540        0.0168483   79.4903     0.000111297 80.5412    
 60      3600        4.28829e-07 -177.62     2.83276e-09 -176.57    
 61      3660        0.0100093   -70.714     6.61198e-05 -69.663    
 62      3720        3.79554e-07 -171.48     2.50726e-09 -170.43    
 63      3780        0.0191737   -40.998     0.000126658 -39.947    
 64      3840        3.21515e-07 -172.51     2.12387e-09 -171.46    
 65      3900        0.00987793  -11.247     6.52518e-05 -10.196    
 66      3960        3.31038e-07 -173.06     2.18677e-09 -172.01    
 67      4020        0.00257218  18.5138     1.69913e-05 19.5646    
 68      4080        3.38068e-07 -174.68     2.23322e-09 -173.63    
 69      4140        0.000851331 48.3361     5.62374e-06 49.387     
 70      4200        3.29614e-07 -173.7      2.17737e-09 -172.65    
 71      4260        0.00073197  -101.86     4.83526e-06 -100.8     
 72      4320        3.07054e-07 -174.51     2.02834e-09 -173.46    
 73      4380        0.00174678  107.978     1.15389e-05 109.029    
 74      4440        3.12627e-07 -174.29     2.06516e-09 -173.23    
 75      4500        0.00363623  -42.216     2.40203e-05 -41.165    
 76      4560        2.73622e-07 -176.41     1.8075e-09  -175.36    
 77      4620        0.00706749  167.607     4.66865e-05 168.658    
 78      4680        2.95084e-07 -168.98     1.94927e-09 -167.93    
 79      4740        0.0120395   17.4188     7.95306e-05 18.4696    
 80      4800        2.85762e-07 -178.16     1.88769e-09 -177.11    
 81      4860        0.0015627   47.2916     1.03229e-05 48.3425    
 82      4920        2.71585e-07 -174.86     1.79404e-09 -173.81    
 83      4980        0.00196086  77.1491     1.29531e-05 78.1999    
 84      5040        2.67524e-07 -176.84     1.76722e-09 -175.78    
 85      5100        0.000765064 106.869     5.05387e-06 107.92     
 86      5160        2.61439e-07 -175.86     1.72702e-09 -174.81    
 87      5220        0.00282893  -43.211     1.86874e-05 -42.16     
 88      5280        2.39927e-07 -178.05     1.58491e-09 -177       
 89      5340        0.00185083  166.691     1.22262e-05 167.742    
 90      5400        2.44777e-07 -176.1      1.61695e-09 -175.05    
 91      5460        0.00197718  -163.51     1.30609e-05 -162.46    
 92      5520        2.35846e-07 -173.64     1.55795e-09 -172.59    
 93      5580        0.00192508  46.4105     1.27167e-05 47.4614    
 94      5640        2.29664e-07 -176.29     1.51712e-09 -175.24    
 95      5700        0.00348778  76.2446     2.30396e-05 77.2954    
 96      5760        2.27401e-07 -177.3      1.50217e-09 -176.25    
 97      5820        0.00146309  106.096     9.66488e-06 107.147    
 98      5880        2.21334e-07 -176.86     1.46209e-09 -175.81    
 99      5940        0.00163507  135.98      1.0801e-05  137.031    

This demonstration SPICE simulation of a Magic Sinewave driven inverter is a foundation for developing a more comprehensive investigation of Magic Sinewave technology efficiency. I am particularly interested in exploring the parameters which govern selecting the appropriate number of pulses per quadrant optimal for particular applications. More pulses per quadrant, in theory, results in higher efficiency due to less harmonic content and reduced low-pass filter demands, but conversely, there is more loss due to excess resistance during the corresponding increased number of H-bridge transition intervals combined with stored energy lost from reactive components.