The Designer's Guide Community Forum
https://designers-guide.org/forum/YaBB.pl
Simulators >> Circuit Simulators >> Accurate Fourier analysis for circuit simulators
https://designers-guide.org/forum/YaBB.pl?num=1199039997

Message started by Visjnoe on Dec 30th, 2007, 10:39am

Title: Accurate Fourier analysis for circuit simulators
Post by Visjnoe on Dec 30th, 2007, 10:39am

Dear Ken,

I recently read the paper "Accurate Fourier analysis for circuit simulators". I don't have access to Spectre, therefore I wanted to try out the described Fourier analysis by writing a custom MATLAB script that processes the SPICE output.

I wanted to start on the ua741 example from the paper to have a good reference and than go forward from there. However, when trying to reproduce the 'normal' Fourier analysis results from SPICE, I could not come up with the numbers presented in the paper. These are the numbers SPICE reports (THD is smaller than reported in the paper):


Code:
Fourier analysis for vout:
 No. Harmonics: 10, THD: 2.93336 %, Gridsize: 200, Interpolation Degree: 1

Harmonic Frequency   Magnitude   Phase       Norm. Mag   Norm. Phase
-------- ---------   ---------   -----       ---------   -----------
0       0           -0.0027612  0           0           0
1       1000        0.94215     0.271005    1           0
2       2000        0.00485751  -115.89     0.00515577  -116.16
3       3000        0.00667308  136.829     0.00708282  136.558
4       4000        0.00713215  -42.948     0.00757008  -43.219
5       5000        0.000858787 -51.735     0.000911518 -52.006
6       6000        0.0181092   -49.895     0.0192211   -50.166
7       7000        0.00353059  -55.709     0.00374738  -55.98
8       8000        0.0173587   129.745     0.0184246   129.474
9       9000        0.00152307  127.297     0.00161659  127.026



I see some possible causes for this and it would be nice if you could comment on them:

1. Different SPICE version: I used spice3f5 while the paper mentions spice2g6.

2. SPICE testbench: this is my SPICE deck:

Code:
*
* uA741 opamp Fourier analysis
*


* Netlist
.include UA741_model.sp

X1 vin vout vdd vss vout UA741


* Bias
Vdd vdd 0 dc 12
Vss 0 vss dc 12


* Input
Vin vin 0 sin(0 1.0 1e3 0 0 0)


* Analysis
.tran 1e-9 10e-3
.four 1e3 vout


* Output
.print tran v(vin) v(vout)



.end


3. ua741 model: I used the so called Oregano model:

Code:
.subckt UA741         1 2 3 4 5
* connections:        | | | | |
*                     | | | | |
*   non-inverting input | | | |
*         inverting input | | |
*     positive power supply | |
*       negative power supply |
*                        output
*
*
 c1   11 12 8.661E-12
 c2    6  7 30.00E-12
 dc    5 53 dx
 de   54  5 dx
 dlp  90 91 dx
 dln  92 90 dx
 dp    4  3 dx

*SPICE2:
*  egnd 99  0 poly(2) (3,0) (4,0) 0  .5  .5
*SPICE3:
 Begnd 99 0 V = .5*V(3,0) + .5*V(4,0)

*SPICE2:
*  fb    7 99 poly(5) vb vc ve vlp vln 0 10.61E6 -10E6 10E6 10E6 -10E6
*SPICE3:
 Bfb 7 99 I = 10.61E6*I(vb) + -10E6*I(vc) + 10E6*I(ve) + 10E6*I(vlp) + -10E6*I(vln)
 ga    6  0 11 12 188.5E-6
 gcm   0  6 10 99 5.961E-9
 iee  10  4 dc 15.16E-6
 hlim 90  0 vlim 1K
 q1   11  2 13 qx
 q2   12  1 14 qx
 r2    6  9 100.0E3
 rc1   3 11 5.305E3
 rc2   3 12 5.305E3
 re1  13 10 1.836E3
 re2  14 10 1.836E3
 ree  10 99 13.19E6
 ro1   8  5 50
 ro2   7 99 100
 rp    3  4 18.16E3
 vb    9  0 dc 0
 vc    3 53 dc 1
 ve   54  4 dc 1
 vlim  7  8 dc 0
 vlp  91  0 dc 40
 vln   0 92 dc 40
.model dx D(Is=800.0E-18 Rs=1)
.model qx NPN(Is=800.0E-18 Bf=93.75)
.ends UA741


My gut feeling says the model is the culprit...

Kind Regards

Peter

Title: Re: Accurate Fourier analysis for circuit simulato
Post by Ken Kundert on Dec 31st, 2007, 12:39am

Fourier analysis accuracy is a sensitive function of the circuit, the simulator, and the options. Any of the changes you made could account for the difference. I used an actual transistor model of the circuit, not a macromodel. I have included it below, but I could not find the SPICE netlist, all I had was a Spectre netlist.


Code:
// ua741
simulator lang=spectre

// models
model  NPNdiode  diode is=.1fA
model  NPNbjt  bjt type=npn bf=80 vaf=50 cje=3pf cjc=2pf cjs=2pF tf=.3nS tr=6nS
model  PNPbjt  bjt type=pnp bf=10 vaf=50 cje=6pf cjc=4pf tf=1nS tr=20nS

// ua741 operational amplifier
subckt ua741 (pin nin out vcc vee)
   // Transistors
   Q1  (1    pin  3    vee)  NPNbjt
   Q2  (1    nin  2    vee)  NPNbjt
   Q3  (5    16   3    vcc)  PNPbjt
   Q4  (4    16   2    vcc)  PNPbjt
   Q5  (5    8    7    vee)  NPNbjt
   Q6  (4    8    6    vee)  NPNbjt
   Q7  (vcc  5    8    vee)  NPNbjt
   Q9  (16   1    vcc  vcc)  PNPbjt
   Q14 (vcc  13   15   vee)  NPNbjt
   Q16 (vcc  4    9    vee)  NPNbjt
   Q17 (11   9    10   vee)  NPNbjt
   Q18 (13   12   17   vee)  NPNbjt
   Q20 (vee  17   14   vcc)  PNPbjt
   Q23 (vee  11   17   vcc)  PNPbjt

   // Diodes
   D8  (vcc  1)    NPNdiode
   D19 (13   12)   NPNdiode

   // Resistors
   R1  (7    vee)  resistor r=1k
   R2  (6    vee)  resistor r=1k
   R3  (8    vee)  resistor r=50k
   R4  (9    vee)  resistor r=50k
   R5  (10   vee)  resistor r=100
   R6  (12   17)   resistor r=40k
   R8  (15   out)  resistor r=27
   R9  (14   out)  resistor r=22

   // Capacitors
   C1  4    11   capacitor c=30pF

   // Current Sources
   I1  (16   vee)  isource dc=19uA
   I2  (vcc  11)   isource dc=550uA
   I3  (vcc  13)   isource dc=180uA
ends ua741

// Sources
Vcc     (vcc  0)    vsource dc=15
Vee     (vee  0)    vsource dc=-15
Vin     (pin  0)    vsource mag=1 type=sine ampl=1 freq=1kHz
Vfb     (nin  out)  vsource

// Op Amps
OA1    (pin   nin  out  vcc  vee)  ua741

// Resistors
Rload   (out  0)    resistor r=10k

// Fourier analyzer
FA1     (out  0   pin   0)  fourier fund=1kHz


// ANALYSES
freqResp ac start=1 stop=100MHz dec=20
sineResp tran stop=10ms
ssSineResp pss tstab=10ms period=1ms
save pin out


The real value of the method presented in that paper will not be demonstrated with the ua741. It differs from standard Fourier analysis in that it includes every point in the calculation, whereas traditional Fourier analysis samples the waveform first. There are certain types of circuits where sampling discards important information, circuits such as pulse width modulators. This approach is indispensable for such circuits. For other circuits, circuits like the ua741, the method tends to be a bit better than traditional methods if you only need a few harmonics because more attention is focused on controlling errors. You will likely not see this benefit when post-processing the waveforms with Matlab because the errors are controlled by changing the behavior of the simulator algorithms. If you need lots of harmonics, a traditional approach based on the FFT is best.

-Ken

Title: Re: Accurate Fourier analysis for circuit simulato
Post by Visjnoe on Dec 31st, 2007, 3:19am

Dear Ken,


thank you for the ua741 Spectre netlist, I think I will be able to convert this to SPICE format. I personally think the difference between the actual device-level netlist and the macro-model will account for much of the difference between the Fourier analysis results.

As I understand your reply correctly, my effort of implementing the proposed Fourier analysis using Matlab does not  make sense.

When I read the paper, I thought I could just take the waveform I'm interested in straight from SPICE and than calculate the sum of integrals as discussed in the paper (these are all just numerical calculations).

As I understand it now (please correct me if I'm wrong), the problem lies in the polynomial fit of the waveform. My approach would be to fit an N-degree polynomial through every (N+1) points from the calculated SPICE solution. I know SPICE already performs such a fit, therefore the only benefit would be to obtain the coefficients of the polynomial.

Of course, it might very well be that the order of the polynomial fit SPICE uses changes during simulation and than my approach would not work well.

Otherwise, I think I can still obtain the coefficients of the polynomial (dubbed 'cm' in the paper) and calculate the sum of integrals.

Regards

Peter

Title: Re: Accurate Fourier analysis for circuit simulato
Post by Ken Kundert on Dec 31st, 2007, 11:21am

No, I am saying something different. What I am saying is that there are two important differences between what I presented in the paper and what SPICE normally provides.
1. The algorithm from the paper acts on the data from every timepoint. In this way it implements a true Fourier integral approach to Fourier analysis. SPICE uses a discrete Fourier transform (DFT) approach, and so ignores the waveform between sample points. For the ua741, either approach works okay. This is not true for a pulse-width-modulator, where the DFT does not give accurate results but the Fourier intergral approach would.
2. The implementation described in the paper tends to give more accurate results than SPICE because it is accompanied by improved simulation control. This is the thing that would be hard for you to implement in a post-processing based approach.

-Ken

Title: Re: Accurate Fourier analysis for circuit simulato
Post by Visjnoe on Jan 1st, 2008, 3:45am

Dear Ken,

ok, I understand your point now.

One more thing though (for my understanding): you state that the presented methodology's benefits are not so apparent on the ua741 example as they are on the PWM example.

I understand why the method is much better for the PWM case (compared to DFT), but in your paper, the Spectre results (implementing this method) are also much better than the SPICE2g6 results (using 'traditional' .four analysis), apart from the RELTOL setting which is equal for both.
So based on those results, I would conclude that the presented method also has *significant* (tens of dB more resolution compared to SPICE2g6) benefits for a ua741 type of circuit, although a DFT would also be able to provide the same accuracy/resolution, given enough FFT points (~simulation time).

Regards

Peter

The Designer's Guide Community Forum » Powered by YaBB 2.2.2!
YaBB © 2000-2008. All Rights Reserved.