FREQUENCY WARPING AND CHAOTIC BEHAVIOUR GENERATED BY SPICE Boštjan Peršič, Niko Basarič University of Ljubljana, Slovenia Keywords: physics, electrotechnics, circuit analysis, SPICE computer tools, DSP, Digital Signal Processing, frequency warping, numerical integrations, Z-transform, LAPLACE transform, chaos Abstract: The numerical procedure of the SPICE simulator is a compromise between accuracy and speed, so that due to efficiency, the simulator can yield errors. One source is frequency warping, which is discussed in the article. The simulator is presented as a digital signal processor. General terms describing the distortion emanating from a time discrete treatment of the continuous signal are achieved in the frequency domain by comparing the Z-transform of the simulator model to the Laplace transform of the model of the actual circuit. The theoretical derivations are illustrated by examples treating autonomous circuits. Within the first example, the SPICE transient analysis is analysed and the discrepancy between actual and calculated responses is presented in the time domain. In addition to frequency warping, the discrete treatment can generate chaotic behaviour. This is presented in the second example, an analysis of a CL oscillator. This example demonstrates the influence of magnitude of the numerical integration step. It is shown that if a step is not limited, the simulation does not follow the behaviour of the circuit and an unpredictable shape is output. The calculated response seems to be chaotic, despite the actual circuit having a closed limit cycle. Frekvenčno izkrivljanje in kaotično obnašanje simulatorja SPICE Ključne besede: fizika, elektrotehnika, analize vezij, SPICE orodja računalniška, DSP obdelava signalov digitalna, izkrivljanje frekvenčno, integracije numerične, Z-transformacija, LAPLACE transformacije, kaos Povzetek: Numerični postopki, ki jih uporablja simulator SPICE, so kompromis med učinkovitostjo in točnostjo. Članek opisuje nekaj vidikov frekvenčnega izkrivljanja in kaotičnega obnašanja CL oscilatorja pri analizi s simulatorjem SPICE. Simulator smo predstavili kot digitalni procesor signala. Splošne analitične izraze za popačenja, ki nastanejo zaradi diskretnega obravnavanja zveznega signala, smo izpeljali v frekvenčnem prostoru prek primerjave rezultatov Z-transformacije odziva modela simulatorja in Laplaceove transformacije odziva dejanskega vezja. Teoretične izpeljave ilustrirata dva zgleda analize avtonomnih vezij. Prvi zgled obdeluje linearno vezje. Napake tranzientne analize simulatorja SPICE so prikazane v prostoru stanj in časovnem prostoru. Drugi zgled je nelinearno vezje, pri katerem je poudarjen vpliv velikosti koraka numerične integracije. Če je maksimalni dopustni korak numerične integracije prevelik, analiza vezja s simulatorjem ne sledi obnašanju dejanskega vezja, temveč generira nepredvidljive rezultate. Izračunani izhodni signal je tedaj videti kaotične oblike, čeprav ima obravnavano vezje zaključen limitni cikel. 1. INTRODUCTION Implementation in microelectronics technology is impossible without the use of a wide palette of CAD tools. The basic tool, which yields circuit responses at the level of elements, is the SPICE simulator (Simulation Program with Integrated Circuits Emphasis) /1/. The simulation is performed on a digital computer, so its behaviour is similar to digital signal processing. Digital signal processing does not encompass the entire signal; it treats a chain of discrete samples only, and the samples have a limited number of values. This discrete approach introduces some inevitable impairment of the signal. The transformation of the magnitude from continuous to discrete values is a distortion that is presented as quantization noise. The amount of the noise is inversely proportional to the distance between two neighbouring levels. Similar distortion is caused by errors emanating from unavoidable truncations and by rounding off the intermediate results of mathematical operations /2,3/. Naturally, the noise impairs the signals calculated. In addition, manipulation of a signal in discrete instants of time is the second source of errors 121. The sampling theorem states that an original signal can be reconstructed by its sam- ples if they are nearer each other than half a period of the highest spectral component. If this condition is violated, the spectrum transposed around multiples of the sampling frequency is added to the baseband spectrum, which causes irreparable corruption of the original signal. A detailed analysis reveals that the treatment of a signal in discrete instants introduces distortion, even if they are close enough to fulfil the requirement of the theorem. This distortion is called frequency warping. Its size depends on the ratio between the frequency of the signal and the sampling frequency. Assuming that an exact result would be obtained incorporating an infinite number of samples, the difference between the actual result, acquired by a limited amount of samples, and the exact one can be defined as the error. The quantitative estimate of frequency warping is normally done in the frequency domain by comparing a Z-transform of the discrete system to a Laplace transform of the continuous counterpart /3, 4/. The error caused by the discrete approach comes into play as the observed system is excited by a different frequency, which changes the shape of the response /3/. Within some applications, analog circuit simulators evaluate the response in discrete points of time; therefore, they have all the essential properties of a digital signal processor. The feature denoted is incorporated into the SPICE simulator. The result of SPICE transient analysis can be presented as an output of a digital integrator /5, 6/ whereby sampling time, numerical accuracy and the integration method can be selected. Due to its discrete nature, numerical integration causes the distortion mentioned above. Contrary to standard digital signal processing, SPICE does not maintain a constant distance between samples. In order to accelerate analysis, the integration step of the simulator continues until an initially controlled error surpasses the threshold value chosen. Interrupting a lengthy step by an abrupt change in a signal can be another source of errors. The error can even transform an undoubtedly unstable response into a stable one 111. In addition, it can cause completely irregular results /8/. Despite the possibility of chaotic behaviour in a Colpitts oscillator /9,10/, a circuit which has a simple closed limit cycle with no bifurcation can yield a strange response with no steady state. It has been confirmed that the unexpected results are consequences of the imprecise numerical integration of the simulator. 2. MODEL OF SPICE TRANSIENT ANALYSIS SPICE transient analysis has been created to be a numerical solver of differential equations. In fact, the analysis has been adapted to cover non-linear circuits and uses implicit integration methods /1/, where the magnitudes of signals and their derivatives are simultaneously calculated by previous values. However, since we wish to avoid an overly intricate explanation by omitting facts not essential to our topic, the circuit analysed is assumed to be linear and is presented by a system of equations in a normal form. The excitation vector, the state vector, and its time derivative are depicted by u(0, y(0 and y(t) respectively. A and B are corresponding matrices. If this is so, vectors can be replaced by their samples u(t)^u(kh) = uk, y(t)^y(kh) = yk, y(t)-> y(kh) = yk. The usual numerical integration technique exploited by the simulalor is the trapezoidal method. The procedure for one integration step is presented by (3) where h depicts the time step. h . h . Vk+i = Vk + ^Vk +-^yk+i (3) Derivatives of the state vector in the equation above can be replaced by the right side of the equation (1) for matching instants. After some rearrangement, (4) is obtained: A B yk+1 = yk + hy(yk + yk+i) + h^(Uk+Uk+i) A system operating according to equation (4) is sketched in Figure 1. The block depicts a time delay lasting one integration step. The input signals of the middle summator are formed by the mean value of the present and past samples of the output signal and the excitation, multiplied by A and B respectively. The integrator is presented as an accumulator. y(t) = Ay(t) + Bu(t) (1) Fig. 1. Model of the trapezoid method Figure 1 confirms that numerical integration can be treated similarly to digital processing of signals, and that consequently the SPICE transient analysis can be regarded as a digital signal processor. The logical conclusion is that this task of the simulator has all the main features, including deficiencies, of a processor of this kind. The explicit form of the signal y(t) can be obtained by integrating the differential equation. y(t)= fy(t)dt= f(Ay(t) + Bu(t))dt (2) The simulator captures and manipulates signals at discrete time instants only. Suppose that these instants are equidistant and that they are h units of time apart. 3. FREQUENCY WARPING IN THE FREUENCY DOMAIN Frequency warping is the phenomenon where a discrete system corresponds to its continuous counterpart at a distinct frequency This discrepancy increases significantly if the frequency of the signal approaches a value limited by the sampling theorem. An error can be caused if this fact is neglected when analysing an oscillator /4/. Our quantitative description of the phe- nomenon inside the SPICE analysis is divided into steps, as follows. 3.1. Comparison of Transfer Functions The transfer function of the continuous integrator can be obtained by performing a Laplace transform on basic equations (1) or (2) that describe the behaviour of the system. H(s) = B Y(s)^_ U(s) s-A (5) Equation (3) presents the signal in discrete time instants; therefore, the natural approach is a Z-transform. The transfer function of a numerical integrator which exploits the trapezoidal method is given by (6). H(z) = 2 z-1 h z + 1 A (6) Ml 2 , coh r = 1 ; co*^ = - arctan — h 2 (8) The map of the ordinate of the s-plane is a circle in the z-plane, as shown in Figure 2. The frequency of the discrete system corresponds to the phase in the z-plane. Im(^) 5-plane jOJ Ro(s) Re(z) A comparison of equations (6) and (5) confirms that the discrete approach alters the transfer function of a system. Consequently, a change in the transfer function results in a difference between the responses of the discrete system and its continuous (e.g. actual) counterpart. Nevertheless, it can be noticed that the structure of equation (5) is equal to the structure of (6), except that the variable s is replaced by the fraction. The transfer functions are identical if mapping, defined by equation (7), is introduced. 2 z~1 s =--- h z + 1 => z = • 2 + hs 2-hs (7) As the variables of the transforms have both real and imaginary parts, the last equation describes two-dimensional mapping. The map of a significant curve is additionally highlighted in the next subsection. 3.2. Map of s-Piane Ordinate to z-Plane The continuous complex frequency s is expressed as a sum of the real and imaginary parts ( s = a + jm ), and variable z by its polar co-ordi-nates (z = r-eJ"^). To distinguish the frequencies, the upper index in the parenthesis is added at the discrete signal {(ü^nscreie'^ portrayal of harmonic signals in the s-plane is its ordinate. As our main concern is studying relations between the frequencies of continuous and discrete systems, a map of this curve into the z-plane can explain the point. After replacing the variable s in equation (7) by yoo and after some manipulation, the relation presented by (8) can be found. Fig. 2. Map of the ordinate of the s-piane into the z-piane according to the trapezoidai method. The relation between continuous and discrete frequencies, dictated by equation (8), is presented in Figure 3. The abscissa is proportional to the frequency in a continuous (actual) system, and the ordinate to the frequency of its discrete counterpart (simulated system). The scales of both axes are normalised by the sampling frequency, which is calculated from the time step {f=^/h). 0,4 0,2 0,5 f/L Fig. 3. Reiations between frequencies of the continuous system and the discrete system if equal responses are required. The curve reveals the relation between the systems. It can be inferred that the test tone frequency inside the simulator (/c^) has to differ from the actual frequency (,/) if the same magnitude of response is required. If the ratio between the test and the sampling frequency is small, the value of the function arc tan is almost equal to its argument and the differences between the responses are hardly observed. When the ratio approaches or even exceeds one half, the corresponding discrete frequency is significantly distinct. This non-linear relation emanates from the treatment of the signal in discrete time instants. 3.3. Approximation Equation (8) is the exact description of the distortion of a signal due to treatment of a continuous system by the simulator. The error can be easily estimated if a non-linear tangent function is expanded into a truncated Taylor series. The result of the procedure is equation (9). A detailed analysis reveals that with ten samples per period, the first neglected term is approximately 4% of the last included term. 1 + (co'^)hf 12 (9) As the integration step of the SPICE transient analysis is adapted automatically to changes in the signal [11], the number of steps in a period is normally greater than ten, especially if the signal is formed by a single spectral component. With this in mind, the approximations of the distortion seem acceptable for obtaining a fair estimate of an error of frequency obtained by the simulator. 4. EXAMPLE I - FREQUENCY WARPING This section illustrates the subject through an example. It aims to display the typical effect of frequency warping and to clarify the relation (9). 4.1. The circuit The simplest form of an autonomous circuit, producing a response that incorporates only the imaginary part of the complex frequency ( s = jcoo ), is a CL combination with an initial state (u(0), /(0)) different from zero. The circuit is presented in Figure 4. It can be described by an homogeneous second order linear differential equation. Its solution is undamped oscillation . C U d'u(t) u(t)_Q dt^ CL u(t) = Asin(ü)ot + q)) Fig. 4. The circuit in Example 1 4.2. Numerical Integration in the Time Domain Frequency warping of the example is demonstrated in the time domain. The trapezoidal method has no amplitude distortion /3/; therefore, any point of the sig- nals acquired by numerical integration defines a sine curve with given constant amplitude. The trapezoidal algorithm (3) includes the initial and the final derivatives of the signal within each integration step. For convenience, the step should be divided into two equal parts. During the first part, the signal of the discrete integrator is assumed to be changing according to the slope through the initial point. This slope can be unambiguously found from the known point of the signal. During the second half of the interval, the simulator follows the tangent of the final point. Presentation of the outcome without calculation is rather intricate, as the final point is unknown. For a particular case, the obscurity can be bypassed by choosing an initial point on the abscissa (y(,=0) and by setting the magnitude of the integration step to the value where the signal reaches amplitude during its first half. With this intermediate result, the only solution at the end of the integration step is the slope parallel to the abscissa, which holds only at the maximum value of the harmonic signal. The point after the second integration step is obtained similarly The first move within the step is parallel to the abscissa, and the second has maximum slope: therefore the abscissa is reached again, as shown in Figure 5. Fig. 5. Frequency warping demonstrated in time domain. The three points describe half a period of the calculated signal. It can be observed in Figure 5 that the peak of the signal obtained is shifted rightwards compared to the actual signal. The delay is depicted by At. Sequential integration steps add the same delay and the period is prolonged, which means that the frequency of the response is lowered. The difference can be approximated by (9). 5. EXAMPLE II-CHAOS As noted, transient analysis of the simulator consists of numerical integration with discrete time increments. A circuit has to be solved inside each step, which results in a considerable amount of calculations if the increments are tiny. To output a result in a reasonable time, the standard SPICE simulator tends to enlarge the increment towards (T, -7, J/50 or 7 , whichever ^ stop Stan' max' is smaller/11/. The times mentioned are the second, third and fourth parameters in the .TRAN statement respectively. Another limitation stems from the slopes of signals. Slowly varying signals enlarge the time increment, and vice versa. If an abrupt change occurs in a signal, the integration step shrinks gradually. The gradual change and asynchronism between the integration instants and the abrupt change can be another source of errors. 5.1. The circuit The active element of the circuit in Figure 7 is a general purpose NPN transistor in a common emitter orientation, loaded by a resistor. Two capacitors and an inductor form the feedback. The latter provides the quiescent current into the base, so that the transistor operates near saturation. Note that the ratio of capacitances causes a considerable signal at the base; therefore, the transistor is forced to traverse a strongly non-linear region. The non-linearity yields significant digress of actual frequency of oscillation (18.5 kHz) from the resonant frequency of the passive n feedback circuit (8.9 kHz). L rww C, R \ Q C 'U, cc Fig. 7. The oscillator analysed (U^^ = 5V, Q -2N2222, 47nF, IC = 0.6074422 V, 100nF 361650 V, L= 10 mH, IC ^ 28.98162E-6 A) 5.2. Results of simulations The first solution presented is referred to as exact. Setting a small enough time between outputted results and the maximum time increment of the numerical integration (7^J, and starting the simulation with adequate initial conditions, an actual steady-state response is obtained. Observing the actual time increment of the integration in the raw file, it was confirmed that chosen defines the time increment inside the entire period. Figure 8 displays the current into the base, the collector-emitter voltage in the time domain and the current through the inductor in the frequency domain. 0.8 0.4 10 30 50 70 90 r/jis iJmA 10 30 50 70 90 /7kHz Fig. 8. Base current, base-emitter voltage and the spectrum of the inductor current Leaving unchanged and significantly increased, the simulation is repeated. Figure 9 shows the results in the state domain formed by the voltage across the capacitor at the collector side and the inductor current. The upper part of the trajectory is spitted. The inset explains that the vertices of curves are merely different points of the original trajectory. Thus, presenting the signals using a small number of points, the distortion appears. iJmA Fig. 9. The trajectory with increased =1,5 = 50 ns) A simulation with slightly increased causes the spectral lines to be lower and wider and the noise floor raised. In the state domain, the points calculated randomly diverge from the original trajectory, but the limit cycle can be unambiguously confirmed. Omitting T^^^ leads to an unpredictable yield of the simulator (Figure 10). The spectrum has some peaks around the original frequency of oscillation. The spikes are less than 6dB above the vicinity, so all spectral components are significant inside a limited interval. In addition, the trajectory gained is not a closed curve; moreover, it seems chaotic. 0.2} tiJmA 0.1' 4 10 30 50 70 90 //kHz Fig. 10. The spectrum and the trajectory (T^^^^ = 1,5 = omitted). 5.3. Comments Observing the current at the base side (Figure 8), it can be inferred that significant changes occur when the transistor passes from the cut-off to the active region. As the amplifier is idle for almost the entire period except inside this short interval, the slopes of signals are defined mainly by passive feedback. Thus, all signals are smooth before the spike of the base current occurs. In observing the raw results, it can be found that the integration increment has its maximum allowed value at the beginning of the abrupt change. Overly large steps cause alternation of the calculated base current. If this numerically provoked alternation is not damped enough, the process can continue through the entire period. Not being synchronised with the signal, the moments of calculation are not congruent to the response. Given this, the calculated amount of the charge injected into the base randomly varies from cycle to cycle, so the response is aperiodic. 2. CONCLUSION The aim of the contribution is to highlight some deficiencies of the SPICE simulator. In addition, it explains the origin of frequency warping and the irregular behaviour due to manipulation of a signal in discrete time instants. Considering the equidistant time steps, a similar approach is found within digital signal processing, so the transient analysis of the SPICE simulator is presented as a digital signal processor. Expressions for the distortion caused by numerical integration are derived in the frequency domain. It is shown that the discrepancy between a continuous system and its discrete counterpart increases if a time steps approach is made to periods of signals. A simple incorporated electronic circuit, the solution to which is harmonic oscillation, is presented to illustrate these features. The circuit is simulated exploiting numerical integration. Within this example, the distortion is additionally surveyed in the time domain. In addition, the SPICE simulator varies the time step of numerical integration, which introduces another error, treated in the second example. The circuit used in the example is a Colpitis oscillator. It has been confirmed that the simulator outputs the periodic signals if adequate controls are set. However, the automatic adaptation of the time increment leads to an aperiodic response. It must be stressed that the SPICE simulator is an excellent tool for circuit analyses, and usually accomplishes its job requiring no additional actions by its users. Sometimes the facts mentioned above prevail, so outcomes contain errors. We hope that the paper clearly elucidates some unpleasant features of the SPICE simulator, and trust that consideration of the features and their consequences will facilitate detection of false results. We advise that a survey of the simulator's outputs should be made and if they seen doubtful, additional controls must be utilised. As the examples illustrate, the most powerful control is the limitation of the time step. References /1/ L.W. Nagel, A Computer Program to Simulate Semiconductor Circuits. Memorandum No. ERL-M520, Berl