Modeling Guide, Part 1

Qucs-S is an open source electronic circuit simulation program. Qucs-S is cross-platform (Linux and Windows are supported) and written in C++ using a set of Qt libraries. My previous articles talk about this program. To run Qucs-S, it is also recommended to use the open source modeling engine Ngspice. The current release of Qucs-S is currently version 2.1.0. This article takes a closer look at the types of modeling available in Qucs-S. An initial guide to using the program can be found here: https://habr.com/ru/articles/678526/

Operation point calculation

Calculation of the DC operating point allows you to calculate the voltage and current in the nodes and components of the circuit in steady state, provided that there is no AC input signal. To start calculating the operating point, you need to select Simulation→ Calculate DC bias in the Qucs-S main menu or press the F8 key on the keyboard. If the circuit is assembled without errors, then next to the circuit nodes the program will show the voltage value, and next to the sources – the amount of current flowing through this source. You can also include voltmeters and ammeters in the circuit.

Calculation of the operating point for a bipolar transistor connected according to a common emitter circuit

Calculation of the operating point for a bipolar transistor connected according to a common emitter circuit

The screenshot shows an example of modeling the operating point of a simple bipolar transistor circuit. Ammeters are included in the collector circuit and the base circuit. An ideal transistor model with current transfer coefficient Bf=100 was used. From the simulation results it is clear that the collector current is approximately Bf times greater than the base current.

DC sweep simulation

DC sweep simulation also allows you to calculate the voltage and current in the nodes and components of the circuit in steady state, provided there is no AC input signal. But at the same time, it is possible to plot the dependence of the output signal on a certain voltage, current or resistance. Among the possible applications of this modeling is the construction of current-voltage characteristics (volt-ampere characteristics) of semiconductor and electric vacuum devices.

As an example, let’s look at how to simulate the output current-voltage characteristic of a field-effect transistor. As is known, the output current-voltage characteristic is the dependence of the drain current Ic of the transistor on the drain-source voltage Vsi at a constant bias voltage at the gate Vzi. As a rule, reference books provide a family of output current-voltage characteristics for different gate voltages. To carry out the simulation, in Qucs-S we assemble a circuit containing a transistor, two sources, and types of simulation.

Family of output current-voltage characteristics of a field-effect transistor

Family of output current-voltage characteristics of a field-effect transistor

Let’s take a BSS123 type transistor from the library. We connect two constant voltage sources V1 and V2 to the drain and gate, and also an ammeter (current probe) into the drain circuit, which will measure the drain current. We place three simulations on the diagram: DC analysis and two Parameter Sweep blocks. There is no separate DC sweep modeling in Qucs-S, so a combination of two types of modeling is used. Simulation Parameter Sweep has the first parameter Sim, in which you need to specify the type of simulation. In our case, we indicate DC1, as shown in the diagram. In the modeling properties dialog, you can select it from the list. We specify the source name as a parameter for the sweep (Param). In our case, this is V2, which is included in the drain circuit. Unlike the old Qucs, you only need to specify the source or resistor name, not the variable name. You should specify the range in the Start and Stop properties, and the number of points in the Points property. In our case, the drain voltage varies from 0 to 15 V.

A second Parameter Sweep simulation is needed to obtain the I-V family. At the same time, in the internal cycle we change the drain-source voltage (source V2), and in the external cycle the gate voltage is set (source V1). The gate voltage varies from 0 to 5 V. There will be 5 curves in the I-V family (Points=4). Once the simulation parameters are set, you can run simulations by selecting Simulation→ Simulate from the main menu. Then we place a Cartesian diagram on the diagram, on which we construct the variable i(pr1), representing the current through the ammeter. The result should be a family of output current-voltage characteristics.

Transient analysis

Transient simulation is used to obtain a virtual waveform of any voltage or current. This type of modeling is called Transient Simulation. Let’s look at a small example. Let’s assemble an amplifier circuit using one bipolar transistor and construct voltage oscillograms at the input and output. You should get the diagram shown in the screenshot.

Bipolar transistor amplifier stage

Bipolar transistor amplifier stage

The 2N2222 type transistor can be found in the component library (Library tab on the left of the window) by entering its name in the search bar above the library tree list. The amplifier is powered from source V1 with a voltage of 12V; an alternating voltage source with an amplitude of 100mV and a frequency of 2kHz is connected to the input. A load is connected to the output through an isolation capacitor. To build voltage oscillograms at the input and output, the corresponding nodes on the diagram need to be marked. To do this, use the Wire Label button on the toolbar. We place the “Transient simulation” simulation on the diagram. Double-clicking on this component opens the modeling properties dialog shown in the following screenshot.

Transient Simulation Settings

Transient Simulation Settings

In this window, you can set the initial (Start) and final (Stop) time, as well as the number of calculation points. In our case, the simulation duration is 4 ms, 200 points are required to be calculated, the calculation step is about 20 μs. We run the simulation, which should run without errors, and then place a Cartesian diagram on the circuit, on which we plot the signals v(in) and v(out). We see that the amplifier amplifies the input signal.

Simulation of the transient process with initial conditions

The initial conditions for transient simulation are usually calculated automatically. Before starting the calculation, the SPICE simulator simulates the operating point (initial DC) for direct current and substitutes the initial conditions from its results. But sometimes the initial conditions need to be set manually, for example, if the circuit has charged capacitors. To set the initial voltage on the capacitors, you need to enter a value in the “V” parameter in the capacitor properties dialog as shown in the screenshot. In a similar way, you can set the current for inductors.

Setting the initial voltage on the capacitor

Setting the initial voltage on the capacitor

In the transient modeling properties dialog, set the parameter “inittialDC=no”. By default it is yes.

Transient Simulation Settings

Transient Simulation Settings

As an example, consider a circuit in which a capacitor discharge is simulated. The initial voltage on the capacitor is set to 10V, and the automatic calculation of initial conditions is disabled. As a result, at node v(cap) we obtain an exponential voltage form. The time constant of the RC circuit in this case is 1 ms.

Simulation of the capacitor discharge process

Simulation of the capacitor discharge process

AC simulation (AC analysis)

Simulation on alternating current allows you to study the frequency response and phase response of various electronic circuits. As an example, let’s add frequency response modeling to the single-transistor amplifier circuit from the previous section. Let’s modify the diagram as shown in the screenshot.

Circuit with added AC simulation

Circuit with added AC simulation

We place the “AC simulation” component on the diagram. In the properties of this type of modeling, you can specify the initial (Start) and final (Stop) frequencies, as well as the sweep type. Linear and logarithmic sweep available. For a logarithmic sweep, you can specify purely simulation points per decade. Other types are not supported by Ngspice, and are required for compatibility with the Qucsator engine. The Simulation Properties dialog box is shown in the screenshot. In our case, we will carry out modeling in the frequency range from 10Hz to 100kHz with logarithmic sweep.

AC Simulation Settings

AC Simulation Settings

Next, we launch the simulation and plot the dependence of the gain (variable K) on frequency. The result shown in the screenshot is obtained.

Amplifier frequency response graph

Amplifier frequency response graph

S-parameter modeling

This type of simulation is used mainly for the analysis of high-frequency circuits. The modeling of S-parameters was discussed in more detail in my previous articles, and therefore we will not repeat it here. Let us just briefly mention that two simulation engines can be used to analyze RF circuits.

  • Ngspice since version 37 supports S-parameter modeling. Using this simulator, you can simulate circuits containing passive and active components. S-parameter modeling in Ngspice has some limitations. Thus, there are no microstrip line (MSL) models and only two-port modeling is supported. For more information about modeling S-parameters using Ngspice, see here: https://habr.com/ru/articles/735508/

  • Qucsator supports modeling of MSLs, waveguides, and other distributed circuits, but has very poor performance and convergence problems when modeling in the time domain. Third party SPICE models need to be converted as Qucsator has a different netlist format. Qucsator is not recommended for general purpose circuit modeling. For Linux, Qucsator needs to be compiled from source https://github.com/qucs/qucsator and for Windows can be taken from the installation package for Qucs version 0.0.19.

Starting from version 2.0.0 Qucs-S supports quick switching of the modeling engine through a drop-down list on the toolbar. Restarting the program is no longer required. The paths to the simulators must be configured through the Simulation→ Simulator settings menu. The screenshots below show examples of modeling in Ngspice and Qucsator.

S-parameter modeling for a wideband high-frequency amplifier.  Ngspice modeling engine

S-parameter modeling for a wideband high-frequency amplifier. Ngspice modeling engine

Simulation of a high-frequency amplifier with microstrip lines (MSL).  Qucsator simulation engine

Simulation of a high-frequency amplifier with microstrip lines (MSL). Qucsator simulation engine

Spectral Analysis (FFT)

Spectral analysis allows you to simulate the frequency composition of signals. This performs a fast Fourier transform and calculates the continuous spectrum. The simulator operates similarly to a spectrum analyzer. One application of spectral analysis is to evaluate intermodulation distortion in amplifiers. The corresponding theory can be read here: https://eax.me/amplifier-measurements/ For such measurements, a two-tone signal is supplied to the amplifier input and the spectrum of the output signal is analyzed.

As an example, let’s simulate the intermodulation spectrum of a broadband high-frequency amplifier for the HF range. This circuit is often used in amateur radio transceivers. In Qucs-S we assemble the circuit shown in the screenshot.

Modeling the spectrum at the output of a high-frequency amplifier

Modeling the spectrum at the output of a high-frequency amplifier

We take the 2N5109 transistor from the component library. The transformer is called “Mutual inductance” and is in a group with other passive components. This component allows you to set the inductance of the primary L1 and secondary L2 windings, as well as the coupling coefficient K. Two sources V4 and V2 are connected to the amplifier input, which simulate a two-tone signal with a frequency of 8 MHz with a frequency spacing of 100 kHz. On the diagram we also place the “Spectrum analysis” modeling type and the equation that converts the spectrum into decibels. The equation must be linked to the FFT simulation type in the first parameter (Simulation).

There are two diagrams on the diagram. Spectrum modeling in our case is carried out in the frequency band from 0 to 30 MHz. Therefore, on the spectral diagram it is necessary to highlight the area near the frequency of 8 MHz. For this purpose, the upper graph was built, for which manual setting of boundaries along the axes was used. We see that the spectrum of the output voltage v(out) consists of many intermodulation components. On the sides of the desired signal peaks at 8 MHz and 8.1 MHz, third-order intermodulation products can be seen at frequencies of 7.9 MHz and 8.2 MHz. By determining the amplitude of these components using markers on the graph, you can measure the parameter IP3, called the third-order intercept point and important for analyzing the dynamic range of amplifiers.

Let’s look at the parameters of the Spectrum Analysis modeling type. The Simulation Properties dialog box is shown in the screenshot.

Spectral Analysis Settings

Spectral Analysis Settings

The BW parameter allows you to set the frequency band. In our case, up to 30 MHz. The dF parameter is the frequency step. The smaller the step, the higher the modeling accuracy. But with a small step, spectrum calculations slow down significantly. In our case, the dF step is 1 kHz. The Window parameter allows you to set the type of window function. In most cases, you should leave the default value. You can specify an Order for the Gaussian window function. Otherwise, this option has no effect.

To calculate the spectrum, Ńgspice first performs a transient simulation. The signal is then converted from the frequency domain to the time domain using the Fourier transform. The transient process when the circuit is turned on can overlap the signal spectrum and distort the results. It is therefore useful to shift the start of the simulation to calculate the output spectrum for the steady-state circuit. To do this, use the Tstart parameter, which should be selected. In our case, the transient process is short and we can set Tstart=0, which speeds up the simulation, which is quite slow.

Fourier analysis

Fourier analysis allows you to calculate the harmonic composition of the signal and also obtain the amplitude and phase spectrum. In this case, instead of the Fourier transform, the Fourier series expansion is used. Unlike FFT spectral analysis, the spectrum here is obtained in the form of a discrete function. Fourier analysis is much faster than spectrum calculation, but is not suitable for all cases.

As an example, let’s simulate the spectrum of harmonic distortion for an amplifier using a single transistor. Let’s modify the diagram as shown in the screenshot. You should add a “Fourier simulation” component and increase the amplitude of the sine wave source at the input to 500 mV so that signal distortion is better visible.

Modeling the harmonic spectrum at the output of an amplifier using a single transistor using Fourier analysis

Modeling the harmonic spectrum at the output of an amplifier using a single transistor using Fourier analysis

As a result of the simulation, a discrete spectrum of harmonics of the output signal is obtained. To do this, display the variable magnitude(v(out)) on the graph. To make the graph more visual, you should set the line type (Style) as “arrows” in the properties, that is, arrows parallel to the vertical axis. From the graph we see that the second harmonic has the most significant amplitude. The spectrum diagram properties dialog box is shown in the screenshot.

Spectrum Chart Settings

Spectrum Chart Settings

Let’s consider the parameters of Fourier analysis. This modeling does not work on its own, but is attached to the modeling of the transient process. Therefore, the first parameter Sim must be the name of the transient process modeling component. In our case this is TR1. The second parameter numfreq is the number of harmonics in the calculation. In our case, the number 10 is written there, that is, the amplitude of the first 10 harmonics should be calculated. Parameter F0 is the frequency of the first harmonic. In our case, it is equal to the frequency of the source V2, that is, 1 kHz. The Vars parameter is a list of signals for which the harmonic spectrum is calculated. Signals here are recorded separated by a space. In our case, we calculate the spectrum for the signals v(out) and v(in), that is, the voltages at the circuit nodes in and out.

The Simulation Properties dialog box is shown in the screenshot.

Simulation Settings for Fourier Analysis

Simulation Settings for Fourier Analysis

For comparison, the harmonic distortion spectrum for a given circuit can be simulated using the FFT Fourier transform. A modified diagram with the simulation result is shown in the screenshot. The spectrum is calculated in a frequency band of 10 kHz with a step of 10 Hz.

Comparison of Fourier Analysis and FFT Results

Comparison of Fourier Analysis and FFT Results

Conclusion

This article did not cover all types of modeling available in Qucs-S. Parametric analysis, zero-pole modeling, script modeling and some general issues will be discussed in the next article, otherwise the scope will be exceeded. Finally, there is a list of resources on Qucs-S.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *