Function reference

DCvalue

% dcVal = DCvalue(executionResult) substitutes s==0 in executionResult.results
% and assigns executionResult.results to the variable dcVal. The data type
% of the analysis shoud be set to 'NUMER', 'DENOM' or 'LAPLACE'
%
% Argument:
%
% executionResult (structured array, required): the return value of the
%   function execute.m.
%
% Example:

dataType('laplace');
gainType('gain');
execResult = execute();
DCgain = DCvalue(execResult);

Fourier

%Fourier replaces the contents of the .results field of the structured
%array obtained from the execution of an instruction with dataType
%'laplace' with the Fourier transform by replacing s with 2j*pi*F.
%It also sets the .postProc field to 'Fourier'.
%
%dataType('laplace');
%FourierResult = Fourier(execute());

Help

% Help() opens the SLiCAP html help in the MATLAB browser.
%
% Examples:

Help
Help()

LTspiceNetlist

% LTspiceNetlist(fileName) Generates a netlist from 'fileName.asc' file,
% using LTspice in batch mode. You can edit the file LTspiceNetlist.m to
% modify the default path settings and LTspice version. Its current value is:
%   MSWindows   : "C:/Program Files/LTC/LTspiceXVIIx64.exe"
%   Linux (Wine): wine ~/.wine/drive_c/Program\ Files/LTC/LTspiceXVII/XVIIx64.exe
%
% Arguments:
%
% fileName (char, required): Name of the LTspice schematic file without
%                            the file extension '.asc'
%
% Example:

LTspiceNetlist('myCircuit') % Creates 'myCircuit.net' from 'myCircuit.asc'.

RMSnoise

% RMSnoise(noiseSpectra, F_min, F_max [, tau])
% Returns the RMS noise of the input noise spectra over a frequency range
% from F_min to F_max: RMSnoise = sqrt(int(noiseSpectra, F_min, F_max)).
% The optional argument tau, should be given incases in which the function
% doCDS(noiseResults, tau) has been applied. It should equal the CDS delay
% time.

SLiCAPlog


checkCircuit

% noOfErrors = checkCircuit(fileName) checks a SLiCAP netlist file, expands
% the models and the sub circuits and builds the MNA matrices and returns
% the number of errors found during checking and expansion of the netlist.
%
% Arguments:
%
% fileName (char, required) : Name of the file witout the '.cir' extension.
%
% Return value:
%
% 0                        : if no errors are found,
% exception (Error message): if errors are found.
%
% Example:

checkCircuit('mycircuit') % Checks 'myCircuit.cir'

checkForUpdate

% tf = checkForUpdate() checks if the SLiCAP server can be
% reached and if the latest version of SLiCAP is installed.
%
% return variables:
% tf: locical; true if the SLiCAP server can be reached, and an update is
%     available, false otherwise

coeffsTransfer

% allCoeffs = coeffsTransfer(laplaceRational)
% assigns the coefficients of the numerator and of the the denominator of
% 'laplaceRational' to allCoeffs. The coefficients are ranked in ascending
% order and the coefficient of the lowest order of s of the denominator
% will be normalized to unity.
%
% Arguments:
%
% laplaceRational (sym, required): a rational function of the Laplace
%                                  variable s=sym('s').
%
% Return value:
%
% Two symbolic arrays: one with coefficients of the numerator and one with
% coefficients of the denominator; both in ascending order.
%
% Examples:

syms('s', 'b_0', 'b_1', 'b_2', 'a_0', 'a_1', 'a_3');
myTransferFunction = (b_0 + b_1*s + b_2*s^2)/(a_0 + a_1*s + a_3*s^3)
allCoeffs = coeffsTransfer(myTransferFunction);
numerCoeffs = allCoeffs(1);
denomCoeffs = allCoeffs(2);

dataType('laplace');
execResult = execute();
myTransferFunction = execResult.results(1);
allCoeffs = coeffsTransfer(myTransferFunction);
numerCoeffs = allCoeffs(1);
denomCoeffs = allCoeffs(2);

coeffsTransfer2html

% coeffsTransfershtml Displays the coefficients of s of a Laplace rational
% on the active html page.
%
% coeffsTransfer2html(coeffsTransferResult) displays the coefficients
% in coeffsTransferResult on the active html page.
%
% Arguments:
%
% coeffsTransferResult (sym, required): the return value of the function
% coeffsTransfer.m
%
% Return value:
%
% None
%
% Examples:

syms('s', 'b_0', 'b_1', 'b_2', 'a_0', 'a_1', 'a_3');
myTransferFunction = (b_0 + b_1*s + b_2*s^2)/(a_0 + a_1*s + a_3*s^3)
allCoeffs = coeffsTransfer(myTransferFunction);
coeffsTransfer2html(allCoeffs);

dataType('laplace');
execResult = execute();
myTransferFunction = execResult.results(1);
coeffsTransfer2html(coeffsTransfer(myTransferFunction));

controlled

% controlledSources = controlled() assigns a cell array, carrying the
% identifiers of controlled sources that can be assigned as loop gain
% reference, to the variable 'controlledSources'.
%
% Example:

controlledSources = controlled();

csv2html

% csv2html(myCSVfile) places a table on the current html page with the
% contents of myCSVfile.csv
%
% Arguments:
%
% myCSVfile: name of a csv file (without '.csv' extension) that contains
%            the table header and data
%
% Example:

csv2html('myCSVtable');

dataType

% dType = dataType(myDataType) defines  the SLiCAP dataType and/or assigns
% its value to the variable (char) 'dType'.
%
% Arguments:
%
% myDataType: (char, required) can be one of the following:
%   '?'         : Returns current data type without changing it
%   'matrix'    : Caculates matrix equation of the circiut; default data type
%   'laplace'   : Caculates laplace transform of gain type
%   'solve'     : Caculates the network solution; only for gain type 'vi'
%   'numer'     : Caculates numerator of laplace transform of gain type
%   'denom'     : Caculates denominator of laplace transform of gain type
%   'time'      : Caculates inverse laplace transform of detector voltage
%                 or current only for gain type 'vi'; may not work with
%                 symbolic values
%   'impulse'   : Caculates inverse laplace transform of gain type not for
%                 gain type 'vi'; may not work with symbolic values
%   'step'      : Caculates inverse laplace transform of (1/s) * gain type
%                 not for gain type 'vi'; may not work with symbolic values
%   'poles'     : Calculates complex solutions of the denominator of the
%                 laplace transform; not for gain type 'vi';
%                 may not work with symbolic values
%   'zeros'     : Calculates complex solutions of the dnumerator of the
%                 laplace transform; not for gain type 'vi';
%                 may not work with symbolic values
%   'pz'        : Caculates DC transfer and poles and zeros of the Laplace
%                 transform; not for gain type 'vi';
%                 may not work with symbolic values
%   'noise'     : Caculates source-referred and detector-referred noise
%                 contributions of all noise sources; only for gain type 'vi'
%   'dc'        : Caculates DC value of the detector voltage or the detector
%                 current; only for gain type 'vi'
%   'dcvar'     : Caculates source-referred and detector-referred variance
%                 due to variances of all voltage source, current sources
%                 and resistors; only for gain type 'vi'
%   'dcsolve'   : Caculates DC solution of the network.
%
% Examples:

dType = dataType('laplace');
dType = dataType('?');

dc2html

% dc2html
%
% dc2html(execResult) prints the DC solution of a dc variance analysis to
% the active HTML page.
%
% Arguments:
%
% execResult: structured array obtained from execute()
%
% Example:

gainType('vi');
dataType('dcvar');
dc2html(execute());

dcStd2html

% dcStd2html(execResult) calculates the source and detector referred
% standard deviation of the DC solution from execResult. It prints the DC
% solution as well as the standard deviations to the active HTML page.
%
% Arguments:
%
% execResult: structured array obtained from execute()
%
% Example:

gainType('vi');
dataType('dcvar');
dcStd2html(execute());

dcVar2html

% dcVar2html prints the variance of the DC detector voltage or current,
%  the source referred variance as well as all contributions to these
%  variances to the active HTML page.
%
% dcVar2html(execResult) prints the source-referred and detector-referred
% variances of the DC solution and all contributions to it to the active
% html page.
%
% Arguments:
%
% execResult: structured array obtained from execute()
%
% Example:

gainType('vi');
dataType('dcvar');
dcVar2html(execute());

defPar

% parVal = defPar(parName, parValue); assigns parValue to the parameter
% parName and to the variable (sym) 'parVal'.
%
% Arguments:
%
% parName (char, required)                        : parameter name
% parValue (sym, char or int or double, required) : parameter value or char
%                                                   that can be converted
%                                                   into an expression
%
% Return value:
%
% parameter value (sym) or FALSE
%
% Examples:

defPar('c_pi', 'c_je + g_m*tau_F');
defPar('c_pi', '10p');
defPar('c_pi', 1e-11');

defPars

% newParDefs = defPar([sym1==val1, sym2==val2, sym3==val3]);
% assigns val1, val2 and val3 to the parameters sym1, sym2 and sym3, respectively.
%
% Arguments:
%
% sym1 (sym, required)                   : parameter name
% val1 (sym, or int or double, required) : parameter value or symbolic
%                                          expression
% Return value:
%
% [sym1==val1, sym2==val2, sym3==val3] or FALSE
%
% Example:

syms('R_f', 'C_ell');
allParams = defPars([R_f == 500, C_ell == 10E-12]);

delPar

% delPar(parName); deletes the deninition of the parameter parName and
% returns the logical '1' if the parameter definition has been removed
% succesfully, else '0'.
%
% Arguments:
%
% parName (char, required) : parameter name
%
% Return value             : (logical)
%
% Examples:

delPar('c_pi');

delay

%delay() replaces the contentes of the .results field of the structured
%array obtained from the execution of an instruction with dataType 'laplace'
%with the group delay in seconds after s has been substituted with 2j*pi*F.
%It also sets the .postProc field to 'Delay'.
%
%dataType('laplace');
%delayResult = delay(execute());
%

depVars

% depVars(); returns a list with names of nodal voltages and branch
% currents that can be used as signal detector.
%
% Return value:
%
% Cell array with names of dependent variables
%
% Example:

availableDetectors =depVars();

detector

% detector(charValue) defines and/or returns the name of the dependent
% variable (nodal voltage or branch current) that is used as signal
% detector.
%
% Arguments:
%
% charValue (char, required)
%   '?' or identifier(s) of dependent variable(s)
%
% Return value:
%
% Array (list, sym) with identifiers of independent variable(s) used as
%   detector
%
% Example:

detector('?');              % Returns the name of the independent variable
                            % used as detector.
detector('I_V1');           % Detector is defined as current through 'V1'
detector('V_1');            % Detector is defined as voltage at node '1'
detector('V_pos', 'V_neg'); % Detector is defined as voltage between node
                            % 'pos' en node 'neg'.

doCDS

% doCDS(noiseResultStructArray, tau) Performs correlated double sampling on
% the noise analysis results in the structured array obtained from a noise
% analysis. It sets the 'postProc' field to 'CDS'and multiplies all the
% noise analysis results in the 'results' field with: (2*sin(pi*F*tau))^2,
% where F is the frequency in [Hz].
%
% Arguments:
%
% noiseResultStructArray (structured array, required):
%                 structured array obtained from a noise analysis
% tau (sym, int or double, required):
%                 value or expression for the time between the two samples.
%
% Return value:
%
% input structured array with the contens of its fields modified. The
% 'postProc' field has been set to 'CDS'.
%
% Example:

noiseResult    = execute();
CDSnoiseResult = doCDS(noiseResult);

elementData2html

% elementData2html() prints all data of the elements of the expanded circuit
%   to the active HTML page.
%
% Example:

elementData2html();

elementValues2html

% elementValues2html
%
% elementValues2html(cellArrayWithEmenentIdentifiers) prints the symbolic
% and the numeric values of circuit elements of the expanded circuit to the
% active HTML page.
%
% Arguments:
%
% cellArrayWithEmenentIdentifiers (cell array, required): identifiers of the
%   elements
%
% Example:

checkCircuit(myFirstRCnetwork);
elementValues2html({'R1', 'C1'});

elements

% elements() = returns a cell array with names of circuit elements.
%
% Return value: cell array with element IDs
%
% Examples:

elementIDs = elements();
firstElementID = elementIDs{1};

eps2pdf

%EPS2PDF Converts an eps file to a pdf file using GhostScript (GS)
%
%   [result,msg] = eps2pdf(epsFile,fullGsPath,orientation)
%
%   - epsFile:      eps file name to be converted to pdf file
%   - fullGsPath:   (optional) FULL GS path, including the file name, to
%                   the GS executable (on win32 it could be c:\program
%                   files\gs\gs8.14\bin\gswin32c.exe). The existence for
%                   fullGsPath will be checked for if given. On the other
%                   hand, if fullGsPath is not given or empty it defaults
%                   to 'gswin32c' for pcs and 'gs' for unix and the
%                   existence will not be checked for. But in this, latter
%                   case, GS's path must be in the system's path variable.
%   - orientation:  (optional) a flag that tells how the orientation tag in eps file should be treated
%                   just before the conversion (orientation tag is changed or even removed):
%                       0 -> no change (default)
%                       1 -> flip orientation
%                       2 -> remove orientation
%
%   - result:       0 if ok, anything else otherwise
%   - msg:          resulting status on file being processed
%
%   NOTES: GhostScript is needed for this function to work. Orientation can
%   also be changed - use this only if you have problems with the orientation - in
%   such a case try with orientation=1 first and then orientation=2 if the first option is
%   not the right one.
%
%   EPS2PDF converts an existing EPS file to a PDF file using Ghostscript. EPS2PDF
%   reads an eps file, modifies the bounding box and creates a pdf file whose size
%   is determined by the bounding box and not by the paper size. This can not be
%   accomplished by using Ghostscript only. So, all that one needs is of course
%   Matlab and Ghostscript drivers.
%
%   This tool is especially suited for LaTeX (TeX) users who want to create pdf
%   documents on the fly (by including pdf graphics and using either pdftex or
%   pdflatex). An example would be, if you are using LaTeX (TeX) to typeset
%   documents then the usual (simple) way to include graphics is to include eps
%   graphics using for example (if there exists myfigure.eps)
%   \begin{figure}
%       \centering
%       \includegraphics[scale=0.8]{myfigure}\\
%       \caption{some caption.}
%   \end{figure}
%   To use pdflatex (pdftex) you do not need to change anything but provide another
%   file myfigure.pdf in the same directory along with myfigure.eps. And this file,
%   of course, can be generated by EPS2PDF.
%
%   This function was tested on win32 system running Matlab R13sp1. It should work
%   on all platforms, if not, contact the author.
%
%   SOURCE:     The original idea came from the "eps-to-pdf" converter written in perl by Sebastian Rahtz
%
%   Primoz Cermelj, 24.08.2004
%   (c) Primoz Cermelj, primoz.cermelj@email.si
%
%   Version: 0.9.3
%   Last revision: 04.10.2004
%--------------------------------------------------------------------------

eps2svg

% eps2svg(epsFileName) Converts a .eps graphics file into a .svg file.
% The file will first be converted into a PDF file by calling eps2pdf.m.
%
% Argument:
%
% epsFileName (char, required) : name of postscript file without (.eps) extension
%
% Return value: none
%
% Example:

eps2svg('myPostScriptFile');

eqn2html

% eqn2html(sym1, sym2) prints sym1 = sym2 (n) to the active html page,
% where n is the number of the equation on the page.
%
% Arguments:
%
% sym1 (sym, required): symbol or symbolic expression.
% sym2 (sym, required): symbol or symbolic expression.
%
% Example:

htmlPage('Laplace Transform');
dataType('laplace');
syms('H_s');
laplaceResult = execute();
TransferFunction = laplaceResult.results(1);
eqn2html(H_s, laplaceResult);

equateCoeffs

% equateCoeffs(H1_s, H2_s) returns the solution of H1_s = H2_s. Both
% equations should have the same shape.
%
% Arguments:
%
% H1_s (sym, required): Laplace rational function prototype
% H2_s (sym, required): Laplace rational function of the same shape as H1_s
%                       with circuit parameters to be solved.
%
% Note: All the coefficients of the Laplace variable s=sym('s') are assumed
%       real.
%
% Return value:
%
% solution of H1_s = H2_s (sym)
%
% Example:

syms('s', 'L', 'C', 'R');
protoTransfer      = 0.5/(1 + 0.1*s +0.01*s^2);
LRCnetworkTransfer = R/(C*L*s^2 + C*R*s + 1);
equateCoeffs(protoTransfer, LRCnetworkTransfer)

% This will return:

ans =

[ C == 1/5, L == 1/20, R == 1/2]

% If no solution is found equateCoeffs.m returns FALSE.

execute

% execute() returns a structured array with the execution results of the
% instruction.
%
% Return value:
%
% Strucured array with results and settings of the instruction.
%
% Example:

result             = execute();        % execute() returns a structured
                                       % array with the fields described below
calculatedResult   = result.results    % results of the execution, nested
                                       % lists depend on setting of dataType
instrSimType       = result.simType    % setting of the simulation type for
                                       % this instruction
instrGainType      = result.gainType   % setting of the gain type for this
                                       % instruction
instrDataType      = result.dataType   % setting of the data type for this
                                       % instruction
instrSource        = result.source     % name of the signal source for this
                                       % instruction
instrDetector      = result.detector   % setting of the detector for this
                                       % instruction
instrLgRef         = result.lgRef      % setting of the loop gain reference
                                       % variable for this instruction
instrStepTrueFalse = result.step       % setting of parameter stepping for
                                       % this instruction
instrStepVar       = result.stepVar    % name of the step parameter for this
                                       % instruction
instrStepMethod    = result.stepMethod % setting of the step method for this
                                       % instruction
instrStepList      = result.stepList   % step list generated from start value
                                       % stop value and step method
instrPostProc      = result.postProc   % post processing field

% The contents of the .results field depends on the data type of the
% instruction. Please view the execute section of the help file for more
% details.

expr2char

% TeXexpression = expr2char(EXPR) assigns EXPR in LaTeX format between '$'
% to the variable TeXexpression.
%
% Arguments:
%
% EXPR (sym, required): Symbolic expression
%
% Return value:
%
% TeXexpression (char): LaTeX form of the expression between '$' signs.
%
% Example:

syms('a', 'b', 'c', 'x');
expr = a*x^2 + b*x + c;
htmlPage('Quadratic equation');
text2html(['Example of a quadratic equation: ', expr2char(expr), '.']);

expr2html

% expr2html(EXPR) prints EXPR in TeX format on a new line on the active
% html page.
%
% Arguments:
%
% EXPR (sym, required): Symbolic expression
%
% Examples:

syms('a', 'b', 'c', 'x');
expr = a*x^2 + b*x + c;
htmlPage('Quadratic equation');
text2html('Example of a quadratic equation: ');
expr2html(expr);

dataType('laplace');
lapaceResult = execute();
laplaceFunction = lapaceResult.results(1);
expr2html(laplaceFunction);

fig2html

% fig2html(figName, figFileName, w) displays the MATLAB figure object
% 'figName' on the active htmlPage. The figure will be saved in the
% graphics file 'figFile' in the html/img/ project subdirectory and
% the displayed width will be 'w' pixels.
%
% Arguments:
%
% figName (char, required):     Name of the matlab figure object
% figFileName (char, required): Name of the graphics file in which the
%                               figure will be stored (in the ~/html/img/
%                               project subdirectory)
% w (int, required)             width of the figure in pixels
%
% Return value:
%
% none
%
% Example:

simType('numeric);
dataType('laplace');
gainType('gain');
magPlot = plotdBmag('Magnitude Plot', execute(), 10, 10e6, 200);
fig2html(magPlot, 'magnitudePlot.svg', 800);

file2html

% file2html(fileName) prints the contents of the ASCII file 'fileName' to
% the active html page.
%
% Arguments:
%
% fileName (char, required): name of the ASCII file. This file may include
%                            html content as well as LaTeX expressions. The
%                            latter ones need to be placed between single '$'
%                            for in-line math and between '$$' for displayed
%                            math with equation numbers.
%
% Example:

file2html('description.txt')

findServoBandwidth

% findServoBandwidth returns the frequencies [Hz] of intersection of the
% asymptotes of the magnitude characteristics of the loop gain with unity,
% the order of the slopes at the frequency of intersection (positive for
% falling slope) and the largest value of the asymptotic approximation of
% mid-band the loop gain and its first frequency [Hz] of occurence.
%
% Argument:
%
% loopGain (sym, required): rational expression of the laplace variable
%                           s=sym(s) with numeric coefficients only.
% Return Value:
%
% result (struct array) with the following fields:
%
% result.hpf      = high-pass unity gain frequency of asymptotes of the
%                   magnitude chracteristic of loopGain
% result.hpo      = order of the asymptotes of the magnitude chacteristic
%                   of loopGain with unity at the high-pass frequency of
%                   intersection
% result.lpf      = low-pass unity gain frequency of asymptotes of the
%                   magnitude chracteristic of loopGain
% result.lpo      = order of the asymptotes of the magnitude chacteristic
%                   of loopGain with unity at the low-pass frequency of
%                   intersection
% result.mbv      = largest value of loopGain at midband frequencies
% result.mbf      = first frequency of occurence of result.mbv
%
% Example:

syms 's'
loopGainNumer   = -s*(1 + s/20)*(1 + s/40)/2;
loopGainDenom   = (s + 1)^2*(1 + s/4e3)*(1 + s/50e3)*(1 + s/1e6);
loopGain        = loopGainNumer/loopGainDenom;
servoInfo       = findServoBandwidth(loopGain);
highPassFreq    = servoInfo.hpf;
highPassOrder   = servoInfo.hpo;
lowPassFreq     = servoInfo.lpf;
lowPassOrder    = servoInfo.lpo;
midBandValue    = servoInfo.mbv;
midBandFreq     = servoInfo.mbf;

% View documentation for more details.

funType

% funType(symExpression) returns the type of the expression
% 'symExpression', such as '_power', '_mult' or '_plus', 'sin', 'cos', etc.
% funType() can be used to decompose symbolic expressions.

gainType

% gainType(gType) defines the gain type for simulation and/or returns
% the current setting of the simulation gain type.
%
% argument:
%
% gType (char, required): one of the following:
%
% '?'          : Returns the current gain type setting
% 'asymptotic' : Asymptotic-gain according to the asymptotic-gain negative
%                feedback model. It requires the definition of a source, a
%                detector, as well as the asignment of a control of a
%                controlled source as a loop gain reference variable
%                (see the function lgRef())
%                It calculates the source-to-load transfer after this
%                controlled source has been replaced with a nullor
% 'direct'     : Direct transfer according to the asymptotic-gain negative
%                feedback model.  It requires the definition of a source, a
%                detector, as well as the asignment of a control of a
%                controlled source as a loop gain reference variable
%                (see the function lgRef()).
%                It calculates the source-to-load transfer after the gain
%                of this controlled source has been set to
%                zero.
% 'gain'       : The source to load transfer.
% 'loopgain'   : Loop gain according to the asymptotic-gain negative
%                feedback model.  It requires the signment of a control of
%                a controlled source as a loop gain reference variable
%                (see the function lgRef()).
%                It calculates the transfer from the output of the controlled
%                source to its input (return ratio).
% 'servo'      : Servo function. The servo function is defined as:
%
%                         -L
%                Servo = -----, where L is the loop gain (see above).
%                        1 - L
%
% 'vi'         : Voltage or current. This will calculate a voltage or current.
%                This gain type has to be used for data types:
%                'time', 'dc', 'dcvar' and 'noise'.
%                It cannot be used with data types:
%                'impulse', 'step', 'poles', 'zeros' and 'pz'.
%
% Return value: Current setting of the gain type (char).
%
% Examples:

currentGainType = gainType('?');
gainType('loopgain');

getCoeffs

% getCoeffs(laplacePoly) returns the coefficients of the of laplacePoly
% in ascending order.
%
% Arguments:
%
% laplacePoly (sym, required): a polynomial function of the Laplace
%   variable s=sym('s').
%
% Return value:
%
% Artray with coefficients of the polynomial in ascending order.
%
% Examples:

syms('s', 'a_0', 'a_1', 'a_3');
myTPoly = a_0 + a_1*s + a_3*s^3
polyCoeffs = getCoeffs(myPoly);

dataType('denom');
execResult = execute();
charPoly = execResult.results(1);
charPolyCoeffs = getCoeffs(charPoly);

getElementValues

% getElementValue(elementIDs, field) returns the value of the elements
%   of which the ID corresponds with one in elementIDs.
%   If the simulation type (simType) has been set to 'symbolic' it returns
%   the values of the element definition in the netlist of the circuit.
%   If the simulation type has been set to 'numeric' it returns the values
%   after recursive substitution of the parameter definitions.
%
% Arguments:
%
% elementIDs (char, optional), Cell array with element names; default all
% elements of the circuit
% field (char, optional), value field, depends on element type. Valid
% fields are:
%   'value', (default) Laplace value, can be used with any element
%   'dc'   , DC value of an independent current source or voltage source
%   'dcvar', DC variance of the DC voltage or current in A^2 or V^2,
%            respectively
%   'noise', Noise spectral density of an independent current or voltage
%            source in A^2/Hz or in V^2/Hz, respectively.
%   'zs'   , Laplace value of a series source impedance of an element with
%            model 'EZ' or model 'Hz'.
%
% Return: if length elementIDs > 1 symbolic matrix with name-value pairs,
%         else value of the requested element
%
% Examples:

R1 = getElementValues('R1');
allValues =  getElementValues();
allNoiseSources = getElementValues(elements(), 'noise');
Zout_E1 = getElementValues('E1', 'zs');

getInoise

% iNoise = getInoise(noiseResult [, sourceName]) returns the source-
% referred noise from noiseResult and assigns it to the variable iNoise.
% If the optional argument 'sourceName' is given, the function returns
% the source-referred noise contribution of this noise source only.
%
% Arguments:
%
% noiseResult (structured array, required): Structured array obtained from
%   execute() with dataType set to 'noise'
% sourceName (char, optional): identifier of a noise source
%
% Return value: symbolic array with source-referred noise for each run.
%
% Examples:

gainType('vi');    % gain type required for noise analysis
dataType('noise'); % data type for noise analysis
noiseResult = execute();
inoise = getInoise(noiseResult);
firstRunNoiseResult = inoise(1);

getOnoise

% oNoise = getOnoise(noiseResult [, sourceName]) returns the detector-
% referred noise from noiseResult and assigns it to the variable oNoise.
% If the optional argument 'sourceName' is given, the function returns
% the detector-referred noise contribution of this noise source only.
%
% Arguments:
%
% noiseResult (structured array, required): Structured array obtained from
%   execute() with dataType set to 'noise'
% sourceName (char, optional): identifier of a noise source
%
% Return value: symbolic array with detector-referred noise for each run.
%
% Examples:

gainType('vi');    % gain type required for noise analysis
dataType('noise'); % data type for noise analysis
noiseResult = execute();
onoise = getOnoise(noiseResult);
firstRunNoiseResult = onoise(1);

getParValue

% getParValue(parName, field) returns the value of the parameter parName.
% If the simulation type (simType) has been set to 'symbolic' it returns
% the symbolic definition of the parameter.
% If the simulation type has been set to 'numeric' it returns its value
% after recursive substitution of all parameter definitions.
%
% Arguments:
%
% parName (char, required), Parameter name
%
% Return: symbolic expression of numeric value
%
% Example:

tau_1 = getParValue('tau_1');

getStepParams

% getStepParams(paramList) returns the values of parameters as a function
% of the step parameter.
%
% For more info please read the section 'Parameter stepping' in the Help
% file.

haveInet

% tf = haveInet() returns true if the site
% 'https://www.analog-electronics.eu' can be reached and false otherwise.

head2html

% head2html(Header) places the  section header 'Header' on the active
% HTML page.
%
% Argument:
%
% Header (char, required): Section header.
%
% Example:

head2html('My level-2 header name');

head3html

% head3html(Header) places the subsection header 'Heade'r on the active
% HTML page.
%
% Argument:
%
% Header (char, required): Subsection header.
%
% Example:

head2html('My level-3 header name');

htmlPage

% htmlPage('pageTitle') Closes the active HTML page and opens a new page
% with the title 'pageTitle' as active page.
% It places a link to this page on the index page of the current circuit.
%
% Example:

htmlPage('My new HTML page');

img2html

% img2html(imgFile, imgWidth) Displays the image form the file 'imgFile'on
% the current html page and copies the image file to the html/figures/ sub-
% directory. The image file should be located in the project directory.
%
% Example:

imgWidth = 800 % Width of the image in pixels
img2html('myCircuit.svg', imgWidth);
img2html('myCircuit.svg', 600);

indepVars

% indepVars() returns a cell array with the names of the independent sources.
% These independent sources can be used as signal source.
%
% Example:

sources = indepVars();
source(indepVars{1});   % Definition of the signal source

initProject

% initProject(projectName, pathName) Initializes a SLiCAP
% project. It creates the following file structure:
%   < projectPath >/html/            % html report pages
%   < projectPath >/html/css/        % html style sheets
%   < projectPath >/html/css/images/ % html style sheets images
%   < projectPath >/html/figures/    % figures and images on html pages
%   < projectPath >/rst/             % restructured text files for generating
%                                    % Python Sphinx documentation
% It copies SLiCAP.css to: < projectPath >/html/css/SLiCAP.css
% It copies images of the style sheet to: < projectPath >/html/css/images/*.*
% It creates  < projectPath >//SLiCAPsettings.mu.
% This MuPAD file can be edited for customization of project path settings,
% mathJax settings and global variables.
%
% It creates  < projectPath >/html/index.html
%     Note:
%           This HTML file needs to be closed when finishing the SLiCAP-MATLAB
%           session for this project by executing: 'stophtml()'.
%
% Arguments:
%
% projectName (char, required): Name of the project, it will be placed on
%                               the index.html page of the project.
% pathName:                     path to the m files of the project; use:
%                               mfilename() for automatic detection, or
%                               mfilename('fullpath') for automatic
%                               detection when running this project as
%                               a sub project (by calling it from another
%                               SLiCAP project).
%
% Notes:                        After installing a new version or changing
%                               the install path of SLiCAP, the file
%                               'SLiCAPsettings.mu' has to be updated. It
%                               can be deleted and will be regenerated when
%                               running initProject.m again.
%
%                               It is strongly adviced to preceed the running
%                               of initProject.m with 'clear all'.
%
% Example:

clear all;
initProject('myFirstProject', mfilename());

installSLiCAP

% installSLiCAP() installs the latest version of SLiCAP.

lgRef

% lgRef(srcName) Defines the controlled source srcName as loop gain
% referencea ccording for the asymptotic gain feedback model.
%
% Argument:
%
% srcName (char, required) name of a controlled source in the circuit.
%
% Example:

controlledSources = controlled(); % This returns a cell array with names
                                  % of controlled sources in the circuit.
lgRef = controlledSources{1};     % This assigns the loop gain reference.

listPZ

% listPZ(pzExecutionResult) displays a table with poles and/or zeros
%   obtained from the execution of an instruction with data type: 'poles',
%   'zeros' or 'pz', in the MATLAB Command Window. If the data Type is 'pz'
%   it also displays the zero-frequency value of the transfer function.
%   For the definition of the transfer type see 'gainType()'.
%
% Argument:
%
% pzExecutionResult (structured array, required): Returns variable of
%   'execute()' with data type 'poles', 'zeros' or 'pz'.
%
% Example:

gainType('gain');
dataType('pz');
pzResult = execute();
listPZ(pzResult);

ltspice2matlab

%
%
% LTSPICE2MATLAB -- Reads an LTspice IV .RAW waveform file containing data from a Transient Analysis (.tran) or
%           AC Analysis (.ac) simulation, and converts voltages and currents vs. time into Matlab variables.
%           This function can read compressed binary, uncompressed binary, and ASCII file formats.  It does not
%           currently support files saved in the Fast Access Format.  In the case of compressed binary,
%           the data is automatically uncompressed using fast quadratic point insertion.
%
%           LTspice IV is an excellent Spice III simulator & schematic capture tool freely avaliable for
%           download at www.linear.com/designtools/software.  It is optimized for simulation of switching regulators, but
%           can simulate many other types of circuits as well and comes with a wide variety of component models.  Note
%           that the LTspice uses a lossy compression format (enabled by default) with user adjustable error bounds.
%
%           Use LTSPICE2MATLAB to import LTspice waveforms into Matlab for additional analysis or to
%           compare with measured data.
%
%           This function has been tested with LTspice IV version 4.01p, and Matlab versions 6.1 and 7.5.  Regression
%           testing has been used to expose the function to a wide range of LTspice settings.
%           Author:  Paul Wagner  4/25/2009
%
%
%    Calling Convention:
%        RAW_DATA = LTSPICE2MATLAB( FILENAME );                  %Returns all variables found in FILENAME
%                             (or)
%        RAW_DATA = LTSPICE2MATLAB( FILENAME, SELECTED_VARS );   %Returns only those variables covered by SELECTED_VARS
%               Set SELECTED_VARS to [] to quickly determine the number and names of variables present in FILENAME without
%               actually loading the variables.
%                             (or)
%        RAW_DATA = LTSPICE2MATLAB( FILENAME, SELECTED_VARS, N );
%               Returns variables listed in SELECTED_VARS, with all waveforms downsampled by N.  Set N > 1 to load
%               very large data files using less memory, at the price of degraded waveform accuracy and possible aliasing.
%
%    Inputs:  FILENAME is a string containing the name and path of the LTspiceIV .raw file to be converted.
%
%             SELECTED_VARS (optional) is a vector of indexes indicating which variables to extract from the .raw file.
%                  For example, if a .raw file has 14 variables and SELECTED_VARS is [1 8 9], then the output
%                  RAW_DATA.VARIABLE_MAT will be a 3 x NUM_DATA_PNTS matrix containing waveforms for
%                  variables 1, 8, and 9 only.  Note that SELECTED_VARS does not cover the time (or frequency) variable
%                  (index 0), which is returned separately in RAW_DATA.TIME_VECT (or RAW_DATA.FREQ_VECT).  Extracting only
%                  of subset of variables is a way to use less memory when loading very large simulation files.
%
%                  If this parameter is not specified, then all variables are returned by default.  Setting
%                  SELECTED_VARS to 'all' will also cause all variables to be returned.
%
%             *  To quickly determine the number and names of variables present in a .raw file, call LTspice2Matlab with
%                  SELECTED_VARS set to [].  In this case, all fields in RAW_DATA will be populated, except
%                  .TIME_VECT (or .FREQ_VECT) and .VARIABLE_MAT, which will both be empty ([]).  Since only the header
%                  is read, the function call should execute very quickly, even for large files.
%
%             N (optional) must be a positive integer >= 1.  If N is specified, then SELECTED_VARS must also be specified.
%                  If N is unspecified, it defaults to 1, which does not change the sampling rate.  If this value is 2
%                  or larger, the returned voltage, current, and time data will be downsampled by keeping every N-th sample
%                  in the original data, starting with the first.
%                  Caution:  No lowpass filtering is applied prior to downsampling, so aliasing may occur.  Also,
%                  in many cases LTspice saves data with a non-constant sampling rate, in which case downsampling can
%                  result in substantial waveform distortion.  This option should only be used if the waveform of
%                  interest is initially oversampled.
%
%    Outputs:  RAW_DATA is a Matlab structure containing the following fields ...
%                  title:                String containing the title appearing in the .RAW file header.
%                  date:                 String containing the date appearing in the .RAW file header.
%                  plotname:             String indicating simulation type ('Transient Analysis', 'AC Analysis')
%                  conversion_notes:     Description of modifications (if any) done to the data during conversion.
%                  num_variables:        Number of variables (does not include the "time" or "frequency" variable)
%                  variable_type_list:   A cell of strings indicating the variable type (i.e. voltage, current etc.)
%                  variable_name_list:   A cell of strings indicating the name of each variable.
%                  selected_vars:        A vector of indicies referencing VARIABLE_TYPE_LIST cells, corresponding
%                                        to each row in VARIABLE_MAT.
%                  num_data_pnts:        Number of data points for each variable.
%                  variable_mat:         Double precision matrix with NUM_VARIABLES rows and NUM_DATA_PNTS columns.
%                                        This matrix contains node voltages (in Volts) and device currents (in Amps)
%                                        for each variable and each time point listed in TIME_VECT (or FREQ_VECT).
%                                        For AC Analysis simulations, VARIABLE_MAT will have complex values showing
%                                        the real and imaginary components of the voltage or current at the
%                                        corresponding frequency.  To convert this to log magnitude and normalized
%                                        phase representation used in LTspice plots, use the following formulas:
%                                            Log_Magnitude_dB    =  20*log10(abs(variable_mat))
%                                            Norm_Phase_degrees  =  angle(variable_mat)*180/pi
%                  time_vect:            [Field returned for Transient Analysis only] Double precision row vector of
%                                        time values (in seconds) at each simulation point
%                    (or)
%                  freq_vect:            [Field returned for AC Analysis only] Double precision row vector of
%                                        frequency values (in Hz) at each simulation point
%
%    ** Currently this function is able to import results from Transient Analysis (.tran) and AC Analysis (.ac)
%       simulations only.
%
%
%    Examples
%    --------
%    These examples assume you've run a .TRAN simulation in LTspice for a hypothetical file called
%    BASIC_CIRCUIT.ASC, and that an output file called BASIC_CIRCUIT.RAW has been created.  It also assumes your
%    current Matlab directory is pointing to the directory where the .RAW file is located (or that you prepended
%    the full path to the input parameter FILENAME).
%
%    To import BASIC_CIRCUIT.RAW into Matlab and create a labeled plot of a single variable vs. time:
%
%       raw_data = LTspice2Matlab('BASIC_CIRCUIT.RAW');
%       variable_to_plot = 1;   %This example plots the first variable in the data structure.
%       plot(raw_data.time_vect, raw_data.variable_mat(variable_to_plot,:), 'k');
%       title(sprintf('Waveform %s', raw_data.variable_name_list{variable_to_plot}));
%       ylabel(raw_data.variable_type_list{variable_to_plot} );
%       xlabel('Time (sec)' );
%
%   To superimpose all variables in BASIC_CIRCUIT.RAW on a single graph with a legend:
%
%       raw_data = LTspice2Matlab('BASIC_CIRCUIT.RAW');
%       plot(raw_data.time_vect, raw_data.variable_mat);
%       title(sprintf( 'File:  %s', raw_data.title));
%       legend(raw_data.variable_name_list);
%       ylabel('Voltage (V) or Current (A)');
%       xlabel('Time (sec)');
%
%   To quickly determine the number and names of variables in BASIC_CIRCUIT.RAW without loading the entire file:
%
%       raw_data = LTspice2Matlab('BASIC_CIRCUIT.RAW', []);
%       disp(sprintf( '\n\nThis file contains %.0f variables:\n', raw_data.num_variables));
%       disp(sprintf('NAME         TYPE\n-------------------------'));
%       disp([char(raw_data.variable_name_list), char(zeros(raw_data.num_variables,5)), char(raw_data.variable_type_list)]);
%
%
%

mag

%mag replaces the contents of the .results field of the structured array
%obtained from the execution of an instruction with dataType 'laplace' with
%the magnitude after s has been substituted with 2j*pi*F.
%It also sets the .postProc field to 'Mag'.
%
%dataType('laplace');
%magResult = mag(execute());

makeNetlist

% makeNetlist(fileName, cirTitle, netLister) generates a netlist file from
%   a schematic file. It places cirTitle on the first line and forces the
%   use of 'netLister' for netlist generation.
%
% Arguments:
%
% fileName (char, required):  name of the schematic file without file extension
% cirTitle (char, optional):  title of the circuit, this will be the first
%                             line in the circuit file.
% netLister (char, optional): force the use of 'ltspice' or 'gschem' as netlister
%
% Remark:
%
% If LTspice is used as netlister, please check and/or modify the command
% for calling LTspice from the command line in the file 'LTspiceNetlist.m'.
%
% Examples:

makeNetlist('myCircuit') % Generates the file 'myCircuit.cir' from
                         % 'myCircuit.asc' or from 'myCircuit.sch'. The
                         % title of the circuit will be: 'myCircuit'.
makeNetlist('myCircuit', 'My Circuit Title') % Generates the file
                         % 'myCircuit.cir' from 'myCircuit.asc' or from
                         % 'myCircuit.sch'. The title of the circuit will
                         % be: 'My Circuit Title'.
makeNetlist('myCircuit', 'My Circuit Title', 'ltspice') % Generates the
                         % file 'myCircuit.cir' from 'myCircuit.asc'.
                         % The title of the circuit will be:
                         % 'My Circuit Title'.

matrices2html

% matrices2html(matrixExecutionResult) prints the MNA matrix equation of
% the circuit to the active html page.
%
% Argument:
%
% matrixExecutionResult (structured array, required): Return variable of an
% execute() instruction with data type set to 'matrix'.
%
% Example:

checkCircuit('myCircuit');
dataType('matrix');
matrices2html(execute());

netlist2html

% netlist2html(netListFileName) prints the contents of the file
% 'netListFileName.cir' to the active html page.
%
% Example:

netlist2html(myFirstCircuit');

noise2html

% noise2html(noiseResult) prints the contents of noiseResult to the active
%   html page.
%
% Arguments:
%
% noiseResult (structured array, required): return value of execute() with
%   data type set to 'noise'.
%
% Example:

dataType('noise');
noiseResult = execute();
noise2html(noiseResult);

parDefs

% parDefs() returns a symbolic array with the parameter definitions
%
% Return value: symbolic array with symbolic definitions:
%               [parName1 == parDef1, parName2 == parDef2, ... ]
%
% Example:

allParDefs = parDefs();

params

% params() returns a symbolic array with the symbolic variables used in the
%   circuit.
%
% Example:

allParams = params();
param_1 = allParams(1);

params2html

% params2html() prints all the parameter definitions and the numeric values
%   (after recursive substitution of all parameter definitions) to the
%   active html page.
%
% Example:

htmlPage('Circuit Data'):
params2html();

pdf2svg

% pdf2svg('fileName') converts fileName.pdf to fileName.svg
%
% Argument: fileName (char, required) : name of PDF file without (.pdf) extension
%
% Example:

pdf2svg('myPDFfile');

phase

%phase replaces the contents of the .results field of the structured array
%obtained from the execution of an instruction with dataType 'laplace' with
%the phase in degrees after s has been substituted with 2j*pi*F.
%It also sets the .postProc field to 'Phase'.
%
%dataType('laplace');
%phaseResult = phase(execute());

phaseMargin

% phaseMargin(executionResult) returns the phase margin of the loop gain.
% It requires data type 'laplace' and gain type 'loopgain'.
%
% Argument:
%
% executionResult (structured array, required): Return value of execute()
% with data type set to 'laplace' and gain type set to 'loopgain'.
%
% Return value:
%
% [[pm1, pmf1], [pm2, pmf2], ... ].
% pm1:  phase margin; run 1
% pmf1: frequency at unity-gain magnitude of loop gain; run 1
% pm2:  phase margin; run 2
% pmf2: frequency at unity-gain magnitude of loop gain; run 2
%
% Number of runs is equal to the number of steps.
%
% Example:

dataType('laplace');
gainType('loopgain');
PMresults = phaseMargin(execute());
PMresults = PMresults.results(1);
PM   = PMresults(1);
Freq = PMresults(2);

plotDelay

% plotDelay(figTitle, results, fStart, fStop, fNum) Creates a MATLAB figure
% object with a group delay plot on a logarithmic frequency axis, from a
% number of structured arrays, each obtained from execution of an
% instruction with data type set to 'laplace'. The group delay is
% calculated as -diff(phase, FREQUENCY), where phase = angle(r.results)
% in which the Laplace variable 's' has been substituted with 1i*FREQUENCY.
%
% Arguments:
%
% figTitle (char, required):                      Title of the figure, will
%                                                 be placed on top of the
%                                                 axis.
% results (array of structured arrays, required): Array with execution
%                                                 results, with data type
%                                                 set to 'laplace'.
% fStart (int or double, required):               Start frequency in [Hz].
% fStop (int or double, required):                Stopfrequency in [Hz].
% fNum (int, required):                           Number of points.
%
% Example:

dataType('laplace');
gainType('gain');
gResult = execute();
gainType('loopgain');
lgResult = execute();
plotDelay('Gain', gResult, 10e2, 10e6, 100);
plotDelay('Loop gain', lgResult, 10e2, 10e6, 100);
plotDelay('Gain and loop gain', [gResult, lgResult], 10e2, 10e6, 100);

plotImag

% plotImag(figTitle, results, fStart, fStop, fNum) Creates a MATLAB figure
% object with a plot of the imaginary part on a logarithmic frequency axis,
% from a number of structured arrays, each obtained from execution of an
% instruction with data type set to 'laplace'.
%
% Arguments:
%
% figTitle (char, required):                      Title of the figure, will
%                                                 be placed on top of the
%                                                 axis.
% results (array of structured arrays, required): Array with execution
%                                                 results, with data type
%                                                 set to 'laplace'.
% fStart (int or double, required):               Start frequency in [Hz].
% fStop (int or double, required):                Stopfrequency in [Hz].
% fNum (int, required):                           Number of points.
%
% Example:

dataType('laplace');
gainType('gain');
gResult = execute();
gainType('loopgain');
lgResult = execute();
plotImag('Gain', gResult, 10e2, 10e6, 100);
plotImag('Loop gain', lgResult, 10e2, 10e6, 100);
plotImag('Gain and loop gain', [gResult, lgResult], 10e2, 10e6, 100);

plotInoise

% plotInoise(figTitle, results, fStart, fStop, fNum) generates a MATLAB
% figure object, displaying the spectrum of the source-referred noise in
% V/rt(Hz) or A/rt(Hz) on a logarithmic frequency axis, from a number of
% structured arrays, each obtained from execution of an instruction with
% the data type set to 'noise'.
%
% Arguments:
%
% figTitle (char, required):                      Title of the figure, will
%                                                 be placed on top of the
%                                                 axis.
% results (array of structured arrays, required): Array with execution
%                                                 results, with data type
%                                                 set to 'noise'.
% fStart (int or double, required):               Start frequency in [Hz].
% fStop (int or double, required):                Stopfrequency in [Hz].
% fNum (int, required):                           Number of points.
%
% Example:

gainType('vi');
dataType('noise');
nResult = execute();
plotInoise('Source-referred noise', nResult, 10e2, 10e6, 100);

plotMag

% plotMag(figTitle, results, fStart, fStop, fNum) Creates a MATLAB figure
% object with a magnitude plot on a log-log axis from a number of structured
% arrays, each obtained from execution of an instruction with data type set
% to 'laplace'.
%
% Arguments:
%
% figTitle (char, required):                      Title of the figure, will
%                                                 be placed on top of the
%                                                 axis.
% results (array of structured arrays, required): Array with execution
%                                                 results, with data type
%                                                 set to 'laplace'.
% fStart (int or double, required):               Start frequency in [Hz].
% fStop (int or double, required):                Stopfrequency in [Hz].
% fNum (int, required):                           Number of points.
%
% Example:

dataType('laplace');
gainType('gain');
gResult = execute();
gainType('loopgain');
lgResult = execute();
plotMag('Gain', gResult, 10e2, 10e6, 100);
plotMag('Loop gain', lgResult, 10e2, 10e6, 100);
plotMag('Gain and loop gain', [gResult, lgResult], 10e2, 10e6, 100);

plotMagLin

% plotMagLin(figTitle, results, fStart, fStop, fNum) Creates a MATLAB figure
% object with a magnitude plot on a log-lin axis from a number of structured
% arrays, each obtained from execution of an instruction with data type set
% to 'laplace'.
%
% Arguments:
%
% figTitle (char, required):                      Title of the figure, will
%                                                 be placed on top of the
%                                                 axis.
% results (array of structured arrays, required): Array with execution
%                                                 results, with data type
%                                                 set to 'laplace'.
% fStart (int or double, required):               Start frequency in [Hz].
% fStop (int or double, required):                Stopfrequency in [Hz].
% fNum (int, required):                           Number of points.
%
% Example:

dataType('laplace');
gainType('gain');
gResult = execute();
gainType('loopgain');
lgResult = execute();
plotMagLin('Gain', gResult, 10e2, 10e6, 100);
plotMagLin('Loop gain', lgResult, 10e2, 10e6, 100);
plotMagLin('Gain and loop gain', [gResult, lgResult], 10e2, 10e6, 100);

plotNyquist

% plotNyquist(figTitle, results, fStart, fStop, fNum) generates a MATLAB
% figure object, displaying a polar plot of the loop gain multiplied with -1.
% This multiplication is done because the loop gain of a negative feedback
% circuit, according to the asymptotic-gain model is negative.
% By doing so, the meaning of the point (-1,0) is this Nyquist plot is
% preserved.
% The data type set should be set to 'laplace' and the gain type should be
% set to 'loopgain'.
%
% Arguments:
%
% figTitle (char, required):                      Title of the figure, will
%                                                 be placed on top of the
%                                                 axis.
% results (array of structured arrays, required): Array with execution
%                                                 results, with data type
%                                                 set to 'noise'.
% fStart (int or double, required):               Start frequency in [Hz].
% fStop (int or double, required):                Stopfrequency in [Hz].
% fNum (int, required):                           Number of points.
%
% Example:

gainType('loopgain');
dataType('laplace');
nResult = execute();
plotNyquist('Polar plot of -L(s)', nResult, 10e2, 10e6, 100);

plotOnoise

% plotOnoise(figTitle, results, fStart, fStop, fNum) generates a MATLAB
% figure object, displaying the spectrum of the detector-referred noise in
% V/rt(Hz) or A/rt(Hz) on a logarithmic frequency axis, from a number of
% structured arrays, each obtained from execution of an instruction with
% the data type set to 'noise'.
%
% Arguments:
%
% figTitle (char, required):                      Title of the figure, will
%                                                 be placed on top of the
%                                                 axis.
% results (array of structured arrays, required): Array with execution
%                                                 results, with data type
%                                                 set to 'noise'.
% fStart (int or double, required):               Start frequency in [Hz].
% fStop (int or double, required):                Stopfrequency in [Hz].
% fNum (int, required):                           Number of points.
%
% Example:

gainType('vi');
dataType('noise');
nResult = execute();
plotOnoise('Detector-referred noise', nResult, 10e2, 10e6, 100);

plotPZ

% plotPhase(figTitle, results, xLim, yLim) Creates a MATLAB figure object
% with a complex frequency domain plot, from a number of structured arrays,
% each obtained from execution of an instruction with the data type set to
% 'poles', 'zeros' or 'pz'.
%
% Arguments:
%
% figTitle (char, required):                      Title of the figure, will
%                                                 be placed on top of the
%                                                 axis.
% results (array of structured arrays, required): Array with execution
%                                                 results, with data type
%                                                 set to 'laplace'.
% xLim ('auto' or [xMin, xMax], required):        x-axis limits.
% yLim ('auto' or [xMin, xMax], required):        y-axis limits.
%
% Example:

dataType('pz');
gainType('gain');
gResult = execute();
gainType('loopgain');
lgResult = execute();
plotPZ('Poles and zeros of gain', gResult, 'auto', 'auto');
plotPZ('Poles and zeros of loop gain', lgResult, 'auto', 'auto');
plotPZ('Poles and zeros', [gResult, lgResult], -[20e6, 0] , [-10e6, 10e6]);

plotParams

% plotParams(plotData) creates a MATLAB figure object from the structured
% array plotData. It plots the values of two parameters against each other
% on an xy plot.
%
% Argument:
%
% plotData (structured array, required): Structured array with the
%   following fields:
%
%   plotData.sweepVar   : sweep parameter, this must be a variable in the parameter expressions
%   plotData.start      : start value of the sweep parameter
%   plotData.stop       : stop value of the sweep parameter
%   plotData.num        : number of values of the sweep parameter, default = 50
%   plotData.stepMethod : sweep method of the sweep variable, default = 'lin', can also be 'log'
%   plotData.stepVar    : name of a step parameter, the sweep variable will be swept with this variable as parameter
%   plotData.stepVarName: name of the step parameter to be placed in the legend
%   plotData.parSteps   : array with step values, the sweep value will be swept for each value of this list, default = []
%   plotData.xVar       : x-axis parameter name, can be any parameter, does not need to be the sweep variable
%   plotData.xVarName   : x-axis name to be displayed as axis label, default = plotData.xvar
%   plotData.yVar       : y-axis parameter name
%   plotData.yVarName   : y-axis name to be displayed as axis label, default = plotData.yvar
%   plotData.title      : Title of the plot, default = yVarName(xVarName)
%
% Examples are given in the Help file in section:
%   Parameter stepping > Plot parameters against each other.

plotPhase

% plotPhase(figTitle, results, fStart, fStop, fNum) Creates a MATLAB figure
% object dispaying a phase plot on a logarithmic frequency axis, from a
% number of structured arrays, each obtained from execution of an
% instruction with data type set to 'laplace'.
%
% Arguments:
%
% figTitle (char, required):                      Title of the figure, will
%                                                 be placed on top of the
%                                                 axis.
% results (array of structured arrays, required): Array with execution
%                                                 results, with data type
%                                                 set to 'laplace'.
% fStart (int or double, required):               Start frequency in [Hz].
% fStop (int or double, required):                Stopfrequency in [Hz].
% fNum (int, required):                           Number of points.
%
% Example:

dataType('laplace');
gainType('gain');
gResult = execute();
gainType('loopgain');
lgResult = execute();
plotPhase('Gain', gResult, 10e2, 10e6, 100);
plotPhase('Loop gain', lgResult, 10e2, 10e6, 100);
plotPhase('Gain and loop gain', [gResult, lgResult], 10e2, 10e6, 100);

plotPhaseMargin

% plotPhaseMargin(figTitle, result) creates a MATLAB figure object with
%   a plot of the phase margin versus the step variable. It calls the
%   function 'phaseMargin' to calculate the phase margin of the loop gain
%   for each value of the step variable.
%
% Arguments:
%
% figTitle (char, required):          Title of the figure, will be placed
%                                     on top of the axis.
% result (structured array, reuired): Return value of execute() with gain
%                                     type set to 'loopgain' en data type
%                                     set to 'laplace'.
%
% Example:

gainType('loopgain');
dataType('laplace');
stepVar('C_c');        Assume a frequency compensation capacitor 'C_c'
                       in the circuit. Its value will be stepped from
                       zero to 100pF using 50 steps.
stepStart(0);
stepStop('100p');
stepNum(50);
plotPhaseMargin('Phase margin versus C_c', execute());

plotPolarLin

% plotPolarLin(figTitle, results, fStart, fStop, fNum) Creates a MATLAB figure
% object with a magnitude plot on a polar axis with linear scale, from a
% number of structured arrays, each obtained from execution of an
% instruction with the data type set to 'laplace'.
%
% Arguments:
%
% figTitle (char, required):                      Title of the figure, will
%                                                 be placed on top of the
%                                                 axis.
% results (array of structured arrays, required): Array with execution
%                                                 results, with data type
%                                                 set to 'laplace'.
% fStart (int or double, required):               Start frequency in [Hz].
% fStop (int or double, required):                Stopfrequency in [Hz].
% fNum (int, required):                           Number of points.
%
% Example:

dataType('laplace');
gainType('loopgain');
lgResult = execute();
plotPolarLin('Loop gain', lgResult, 10e2, 10e6, 100);

plotPolardB

% plotPolardB(figTitle, results, fStart, fStop, fNum) Creates a MATLAB figure
% object with a magnitude plot on a polar axis with dB scale, from a number
% of structured arrays, each obtained from execution of an instruction with
% the data type set to 'laplace'.
%
% Arguments:
%
% figTitle (char, required):                      Title of the figure, will
%                                                 be placed on top of the
%                                                 axis.
% results (array of structured arrays, required): Array with execution
%                                                 results, with data type
%                                                 set to 'laplace'.
% fStart (int or double, required):               Start frequency in [Hz].
% fStop (int or double, required):                Stopfrequency in [Hz].
% fNum (int, required):                           Number of points.
%
% Example:

dataType('laplace');
gainType('loopgain');
lgResult = execute();
plotPolardB('Loop gain', lgResult, 10e2, 10e6, 100);

plotReal

% plotReal(figTitle, results, fStart, fStop, fNum) Creates a MATLAB figure
% object with a plot of the real part on a logarithmic frequency axis, from
% a number of structured arrays, each obtained from execution of an
% instruction with the data type set to 'laplace'.
%
% Arguments:
%
% figTitle (char, required):                      Title of the figure, will
%                                                 be placed on top of the
%                                                 axis.
% results (array of structured arrays, required): Array with execution
%                                                 results, with data type
%                                                 set to 'laplace'.
% fStart (int or double, required):               Start frequency in [Hz].
% fStop (int or double, required):                Stopfrequency in [Hz].
% fNum (int, required):                           Number of points.
%
% Example:

dataType('laplace');
gainType('gain');
gResult = execute();
gainType('loopgain');
lgResult = execute();
plotReal('Gain', gResult, 10e2, 10e6, 100);
plotReal('Loop gain', lgResult, 10e2, 10e6, 100);
plotReal('Gain and loop gain', [gResult, lgResult], 10e2, 10e6, 100);

plotTime

% plotTime(figTitle, results, tStart, tStop, tNum) Creates a MATLAB figure
% object with a time domain plot, from a number of structured arrays, each
% obtained from execution of an instruction with data type set to 'time',
% 'impulse', or 'step'.
%
% Arguments:
%
% figTitle (char, required):                      Title of the figure, will
%                                                 be placed on top of the
%                                                 axis.
% results (array of structured arrays, required): Array with execution
%                                                 results, with data type
%                                                 set to 'laplace'.
% tStart (int or double, required):               Start time in seconds.
% tStop (int or double, required):                Stop time in seconds.
% tNum (int, required):                           Number of points.
%
% Example:

gainType('gain');
dataType('step');
gResult = execute();
plotTime('Step resonse of the gain', gResult, 0, 1e-6, 100);

plotVsStep

% plotVsStep(figTitle, results, goalFuncArgs) Creates a MATLAB figure
% object from a structured array, obtained from execution of a stepped
% instruction using goal functions.
% This figure contains a parameteric plot with the step variable along the
% x-axis and the result of a goal function of the simulated data along the
% y-axis.
%
% Arguments:
%
% figTitle (char, required):                      Title of the figure, will
%                                                 be placed on top of the
%                                                 axis.
% results (array of structured arrays, required): Array with execution
%                                                 results with parameter
%                                                 stepping.
% goal FuncArgs (cell array, required):           Goal function with
%                                                 arguments.
%   Goal functions that have been implemented are:
%       {'totalInoise', fMin, fMax} : plots the total source-referred noise
%                                     over F = fMin .. fMax, versus the
%                                     value of the step variable.
%                                     Requires data type 'noise' and the
%                                     definition of a source.
%       {'totalOnoise', fMin, fMax [, tau]} :
%                                     plots the total source-referred noise
%                                     over F = fMin .. fMax, versus the
%                                     value of the step variable.
%                                     Requires data type 'noise'. The optional
%                                     variable tau is the CDS delay time.
%       {'noiseFigure', fMin, fMax [, tau]} :
%                                     plots the noise figure
%                                     over F = fMin .. fMax, versus the
%                                     value of the step variable.
%                                     Requires data type 'noise' and the
%                                     definition of a source. The optional
%                                     variable tau is the CDS delay time.
%       {'dc'}                      : plots the DC detector value versus
%                                     the step variable.
%                                     Requires data type 'dc'.
%       {'detVariance'}             : plots the DC variance at the detector
%                                     versus the step variable.
%                                     Requires data type 'dcvar'.
%       {'detStdev'}                : plots the DC standard deviation at
%                                     the detector versus the step variable.
%                                     Requires data type 'dcvar'.
%       {'srcVariance'}             : plots the DC variance at the source
%                                     versus the step variable.
%                                     Requires data type 'dcvar' and the
%                                     definition of a source.
%       {'srcStdev'}                : plots the DC standard deviation at
%                                     the source versus the step variable.
%                                     Requires data type 'dcvar' and the
%                                     definition of a source.
%
% An example is found in the section Create plots > Goal functions of the Help file.

plotdBmag

% plotdBmag(figTitle, results, fStart, fStop, fNum) Creates a MATLAB figure
% object with a dB magnitude plot on a logarithmic frequency axis from a
% number of structured arrays, each obtained from execution of an
% instruction with data type set to 'laplace'.
%
% Arguments:
%
% figTitle (char, required):                      Title of the figure, will
%                                                 be placed on top of the
%                                                 axis.
% results (array of structured arrays, required): Array with execution
%                                                 results, with data type
%                                                 set to 'laplace'.
% fStart (int or double, required):               Start frequency in [Hz].
% fStop (int or double, required):                Stopfrequency in [Hz].
% fNum (int, required):                           Number of points.
%
% Example:

dataType('laplace');
gainType('gain');
gResult = execute();
gainType('loopgain');
lgResult = execute();
plotdBmag('Gain', gResult, 10e2, 10e6, 100);
plotdBmag('Loop gain', lgResult, 10e2, 10e6, 100);
plotdBmag('Gain and loop gain', [gResult, lgResult], 10e2, 10e6, 100);

printElementValues

% printElementValues(elementIDs, field) displays the values of the elements
% of which the ID corresponds with one in elementIDs.
% If the simulation type (simType) has been set to 'symbolic' it
% displays the values of the element definition in the netlist of the
% circuit. If the simulation type has been set to 'numeric' it displays
% the values after recursive substitution of the parameter definitions.
%
% Arguments:
%
% elementIDs (char, optional), Cell array with element names; default all
% elements of the circuit
% field (char, optional), value field, depends on element type. Valid
% fields are:
%   'value', (default) Laplace value, can be used with any element
%   'dc'   , DC value of an independent current source or voltage source
%   'dcvar', DC variance of the DC voltage or current in A^2 or V^2,
%            respectively
%   'noise', Noise spectral density of an independent current or voltage
%            source in A^2/Hz or in V^2/Hz, respectively.
%   'zs'   , Laplace value of a series source impedance of an element with
%            model 'EZ' or model 'HZ'.
%
% Return: symbolic matrix with name-value pairs
%
% Example:

printElementValues();
printElementValues('R1', 'value');
printElementValues(elements(), 'noise');

pz2html

% pz2html(pzResults) prints the results of an analysis with data type
% 'poles', zeros' or 'pz' the the active HTML page. It does not allow for
% parameter stepping.
%
% Argument:
%
% pzResult (structured array, required): Return value of an execute()
%   instruction with the data type set to 'poles', 'zeros' or 'pz' and
%   parameter stepping disabled (stepOff()).
%
% Example:

gainType('gain');
dataType('pz');
stepOff();
pz2html(execute());

routh

%   RA = routh(R) returns the symbolic Routh array RA for
%   polynomial R(s). The following special cases are considered:
%   1) zero first elements and 2) rows of zeros. All zero first
%   elements are replaced with the symbolic variable 'epsilon'
%   which can be later substituted with positive and negative
%   small numbers using SUBS(RA,epsilon,...). When a row of
%   zeros is found, the auxiliary polynomial is used.
%
%   Author:  Rivera-Santos, Edmundo J.
%   E-mail:  edmundo@alum.mit.edu
%
%   The function has been adapted by A. Montagne for use with SLiCAP:
%   - Coefficients of poly are in ascending order
%   - 'epsilon' is not required as argument

saveTeX

% saveTex
%
% saveTeX(texExpressionFile, myExpression) saves myExpression in LaTeX
% format between '$$' delimiters to texExpressionFile.
%
% Arguments:
%
% texExpressionFile (char, required) name of the file to store the expression
% myExpression: MuPAD symbolic expression
%
% Return value: none
%
% Example:

saveTeX('myExpression.txt', sym('A')^2);

script2html

% script2html('mySLiCAPscript') prints the file 'mySLiCAPscript.m' to a new
% html page.
%
% Argument:
%
% 'mySLiCAPscript' (char, required): name of a MATLAB script file (without
%                                    '.m' file extension) that resides in
%                                    the project directory.

simType

% simType(simulationType): defines and/or returns the simulation type
%
% Argument:
%
% simulationType (char, required): can be:
%
%   'symbolic' : symbolic simulation
%   'numeric'  : numeric simulation; all parameters in element expressions
%                will recursively be substituted by the parameter definitions.
%   '?'        : returns the simulation type setting but does not change it.
%
% Return value:
%
% Current setting of the simulation type (char).
%
% Examples:

currentSimType = simType('?');
currentSimType = simType('symbolic');
simType('numeric');

source

% source(arg); returns the name of the independent source that is used as
% signal source.
%
% Arguments:
%
% arg (char, required) = '?' or identifier(s) (char) of an independent source
%
% Return value:
%
% Identifier (char) of the signal source.
%
% Example:

source('?');  Returns the name of the independent source used as signal source.
source('V1'); Source is defined as 'V1'

stepArray

% stepArray(stepMatrix) defines and/or returns the array with step values
% of multiple step variables that can be stepped concurrently using the
% 'array' step method.
%
% Arguments:
%
% stepMatrix (matrix or char, required)
%   stepMatrix = '?' returns the array.
%   stepMatrix = [var1_val1, var2_val2, ...; var1_val2, var2_val2, ...]
%
% Return value: the matrix for with values for array stepping
%
% Name of the step variable (char).
%
% Examples:

stepVars({'C_1' 'R_1'});       % Defines C_1 and R_1 as step parameters
                                 for array stepping
stepArray([1e-9 10; 1e-8, 20]) % This will cause a two-run execution:
                                 one run with C_1=1e-9 and R_1=10 and a
                                 second run with C_1=1e-8 and R_1=20
stepArray('?')

stepList

% stepList(stepMatrix) defines and/or returns a list with step values of
% the step variable that will be stepped using the 'list' step method.
%
% Arguments:
%
% stepMatrix (matrix or char, required)
%   stepMatrix = '?' returns the array.
%   stepMatrix = [val1, val2, val3, ...]
%
% Return value: the matrix for with values for list stepping
%
% Name of the step variable (char).
%
% Examples:

stepVars({C_1');              % Defines C_1 as step parameter
stepMethod('list');           % Defines the step method
stepList([1e-9, 1e-8, 5e-7]); % This will cause a three-run execution
                                with subsequent values for C_1.
myStepList = stepList('?');

stepMethod

% stepMethod(arg); defines and/or returns the step method for parameter
%   stepping.
%
% Arguments:
%
% arg (char, required)
%   stepMethod('?')         % returns the current setting of the step method
%   stepMethod('lin');      % sets the step method to linear
%   stepMethod('log');      % sets the step method to logarithmic
%   stepMethod('list');     % sets the step method to list
%   stepMethod('array');    % sets the step method to array
%
% Return value: the setting of the step method (char)
%
% Examples: see the section 'Parameter stepping' in the Help file.

stepNum

% stepNum(arg); defines and/or returns the number of steps for linear or
%   logarthmic stepping of parameters. The number of values is 1 + the
%   number of steps!
%
% Arguments:
%
% arg (int or char, required)
%   stepNum('?')    % returns the current setting of the step value.
%   stepNum(10);    % defines 10 steps for linear or logarithmic stepping.
%
% Return value: the setting of the number of steps (int).
%
% Examples: see the section 'Parameter stepping' in the Help file.

stepOff

% stepOff() disables parameter stepping. Step data will not be deleted!
%
% Return value:
%
% logical: current setting of parameter stepping '1'= on '0'=off
%
% Example:

stepTrue = stepOff();

stepOn

% stepOn() enables parameter stepping.
%
% Return value:
%
% logical: current setting of parameter stepping '1'= on '0'=off
%
% Example:

stepTrue = stepOn();

stepParams

% stepParams() returns a structure with an array of parameter names and an
% array with arrays of values for each parameter. The values are obtained
% after recursive substitution of the value of the step variable in the
% parameter expressions.
%
% Example:

stepVar('I_DS');
stepNum(30);
stepStart('1u');
stepStop('1m');
stepMethod('log');
stepOn();
paramStruct = stepParams();
parNames = paramStruct.names;
parValues = paramStruct.values;

stepStart

% stepStart(arg); defines and/or returns the start value of the step
%   variable.
%
% Arguments:
%
% arg (char, int, double, required) = '?' or identifier(s) (char)
%   representing a number, or a double or an integer.
%
% Return value:
%
% Number (int, double).
%
% Examples:

startValue = stepStart('?');
startValue = stepStart('1k');
stepStart(1000);

stepStop

% stepStop(arg); defines and/or returns the stop value of the step
%   variable.
%
% Arguments:
%
% arg (char, int, double, required) = '?' or identifier(s) (char)
%   representing a number, or a double or an integer.
%
% Return value:
%
% Number (int, double).
%
% Examples:

stopValue = stepStop('?');
stopValue = stepStop('1k');
stepStop(1000);

stepVar

% stepVar(arg); defines and/or returns the step variable for parameter
%   stepping.
%
% Arguments:
%
% arg (char, required) = '?' or identifier(s) (char) representing a parameter name.
%
% Return value:
%
% Name of the step variable (char).
%
% Examples:

stepVariable = stepVar('?');
stepVariable = stepVar('A_0');
stepVar('A_0');

stepVars

% stepVars(arg); defines and/or returns the step variables for concurrent
%   stepping of multiple parameters.
%
% Arguments:
%
% arg (char or cell array, required)
%   stepVars('?')                   : returns an array with the step parameters that have been
%                   defined as step variables.
%   stepVars({'par1', 'par2', ...});
%
% Return value:
%
% Name of the step variable (char).
%
% Examples:

stepVariable = stepVar('?');
stepVariable = stepVar('A_0');
stepVar('A_0');

stophtml

% stophtml() closes the active html page
%
% Example:

stophtml();

text2html

% text2html(textString) places text on the active html page. The text may
% include LaTeX, which should be placed between '$' signs. Alternatively,
% you may use expr2text to convert an expression into a LaTeX expression
% for in-line placement in the text.
%
% Examples:

text2html('This is some text to be placed on an HTML page');

updateSLiCAP