# Introductory Examples

### Introduction

The netlists and scripts on this page are straightforward examples that users of MacSpice 3, and other Spice-compatible simulators may refer to and adapt. There are some more advanced examples elsewhere on this site.

### 01 RC Circuit

The netlist describes a low-pass RC-filter driven by a voltage source. The time-domain
behaviour the voltage source is to delay of 0.2 ms an then step between 0.0 V and 1.0 V.
The commands first perform a transient (*i.e.* time-domain) analysis specified by a suggested
time-step of 0.1 ms, a duration of 10 ms, collecting data from the start,
and limiting the maximum time-step to 0.2 ms. The results are placed in a data structure that
becomes the current 'plot'. Do not confuse this type of 'plot' with the
plot command used to display a graph of the calculated values at 'node 2',
*i.e.* the junction connecting R1 and C1. As no x-axis is specified, the default 'scale' vector is
used. In this case time-points calculated by the tran analysis.

Next, an AC (*i.e.* frequency-domain) analysis is performed and the results are displayed.
Modifiers on the command lines specify that a logarithmic distribution of 10 points per decade
should be used, and the magnitude of voltage at node 2 should be plotted in decibels against a
logarithmic x-axis.

### 02 Simple Differential Pair

the netlist describes a four-transistor differential input stage and the commands characterise the circuit.

The process starts with a tf (transfer function) analysis. This applies a slowly varying input
to the circuit and creates a plot containing vectors representing values of the DC transfer
function (*i.e* the 'responsivity'
δ*V*_{out}/δ*V*_{in}), output resistance, and input
resistance. The vector names are sufficiently descriptive that 'print all' produces an adequate
report.

幸运飞艇超稳计划群 the dc (sweep) analysis shows that the amplifier is fairly linear for inputs in the range ±100 mv and confirms the value of the responsivity reported by the tf analysis.

The AC analysis shows a flat frequency response up to about 1 MHz. The AC amplitude of
*V*_{in} is 1.0 V so the magnitude of the output voltage is numerically equal
to the gain. There is rarely a good reason to specify an AC magnitude that is not 1.0 V
because this analysis uses a linearised model. Both the magnitude and phase have been plotted on
the same graph; this is not good practice because the two quantities have differing units.

the final graph illustrates that, in cases when they occur, start-up transients must be given time to decay away at the start of a transient analyses.

### 03 Poles of a Low-Pass Filter

This example first extracts the poles and zeros of a 5th order low pass filter. The results agree with values from HSpice (Star-HSpice Manual (1998), Chapter 24).

Next, the interactive interpreter language is used to perform some calculations with complex
numbers. It uses the pole/zero values to construct the factorised transfer function *pzfn*
which is plotted (offset) for comparison with the results of an AC analysis. Vectors from two
plots are needed to calculate *pzfn*; the 'ac.' prefix can be omitted from
*ac.frequency* because 'ac' is the current plot but vectors in the pz plot must be referred
to explicitly.

the macspice db() function is 'smart'. it is 10log() if the argument has units like 'power', and 20log() if the units are voltage, current, resistance, etc.

Take heed of the comments in the User's Guide (§1.1.4): keep the circuit be analysed as simple as possible and always examine the results of a pole-zero analysis critically. However, when it works pole-zero analysis is a beautiful thing.

### 04 Noise Analysis

This example illustrates a 'noise' analysis of a single transistor amplfier. The 'noise' command can be confusing because it puts its results into two separate plots. The example file contains echo幸运飞艇超稳计划群 commands that produce a commentary intended to explain what's going on.

### 05 Distortion Analysis

This example illustrates a 'disto' analysis of a single transistor amplfier. Like the noise analysis, the 'Distortion Analysis' command can be confusing because it puts its results into two separate plots.