Useful Matlab Functions and Scripts for

This page contain mfile downloads
used in class examples and laboratory exercises. Mfiles are simply
text files. They can be copied and
pasted into the Matlab editor or workspace, or
downloaded to you computer from the links below. All mfiles were
hastily written by Kevin D. Donohue. A
tutorial script for introducing Matlab basics was
written by Kyle Dipery called tutor.m.
Download this function to your Matlab working
directory and type *tutor* at the Matlab prompt.

step response – This script computes and plots the voltage step response corresponding the capacitor voltage in a series RC circuit. Circuit and plot parameters can be changed in the script for variations.

freqresponse.m – This script computes and plots the magnitude and phase of the frequency response corresponding the capacitor voltage in a series RC circuit. Circuit and plot parameters can be changed in the script for variations.

fithpmag.m – This script opens a data file generate by the Labview frequency sweep program plots the magnitude of the frequency response and finds the best cut-off frequency assuming a first order high-pass filter. An example data file that this script will open and process can be downloaded from this link: hpfs1.txt

fithpang.m – This script opens a data file generate by the Labview frequency sweep program plots the phase of the frequency response and finds the best cut-off frequency assuming a first order high-pass filter. An example data file that this script will open and process can be downloaded from this link: hpfs1.txt

hpfs1.txt – Sample data file of a frequency sweep of a high-pass filter (used for the fithpmag.m and fithpang.m programs).

lpfcap.txt – Sample data file of a frequency sweep of a low-pass filter (used for pre-lab 1 assignments where the fithpmag.m and fithpang.m programs must be modified).

getcurves.m – This function opens a data file generated as CVS output from a TI 370B curve tracer and converts trace information to cell array. (see example in opendiodetc.m and openfettc.m, ).

interpcurves.m – This function processes cell array created by getcurves.m and puts them in matrix form. (see example in opendiodetc.m and openfettc.m).

peakfind.m - Function for finding peaks of an array.

E121600E.CSV – Sample data file, direct CVS output from a TI 370B curve tracer of a diode transfer characteristic (used with getcurves.m and sample script opendiodetc.m).

E121555E.CSV – Sample data file, direct CVS output from a TI 370B curve tracer of an FET transfer characteristic (used with getcurves.m and sample script openfettc.m).

lpfcap.txt – Sample data file of a frequency sweep of a low-pass filter (used for pre-lab 1 assignments where the fithpmag.m and fithpang.m programs must be modified).

csinplot.m – This function computes and plots a clipped sine wave at a specified amplitude, phase, frequency, time range, sampling rate, and clipping levels. The output is a plot and 2 vectors representing the clipped sine waveform and the corresponding time axis.

poweranaly.m – This script computes power absorbed or delivered in every circuit component of an example presented in the lectures notes for the clipping circuits lab (Lab 3). The symbolic toolbox is used to segment the different regions of operation and integrate to obtain rms values for non-sinusoidal waveform. The analysis shows for this nonlinear circuit that power absorbed equals power delivered.

nmos.m – This function generates the drain-source current values “Ids" for an NMOS transistor as a function of the drain-source voltage "Vds". It requires input parameters describing the transistor and the output is a vector of current values “Ids” corresponding to the elements of input vector “Vds”.

pmos.m – This function generates the drain-source current values “Ids" for an NMOS transistor as a function of the drain-source voltage "Vds". It requires input parameters describing the transistor and the output is a vector of current values “Ids” corresponding to the elements of input vector “Vds”.

loadlineex.m – This script is an example of using the NMOS.M function with a load-line equation the plot the changes in drain-source voltage Vds for changes in the gate voltage Vgs.

qpoint_iter.m
– This script is an iterative WHIL

ampdist.m – This function applied values of a sampled transfer characteristic (TC) curve of amplifier to an input signal to create an output signal with the distortion defined by the TC curve.

scrpdist.m – This script uses the nmos.m and ampdist.m function to show an example of setting an amplifier operating point, computing an amplifier TC, and plotting and playing a sinusoidal response at several levels of distortion.

loadlinecmos.m – This script is an example of using the NMOS.M and PMOS.M functions for a CMOS logic circuit to dynamically show the input and output voltages through the intersections of the TC curves as the input swings from 0 to 5 volts. When finished sweeping through the input values, the TC of the circuit is plotted along with the output current and power.

bjt.m – This function generates the collector current values “Ic" for a bjt transistor as a function of the collector-emitter voltages "Vce". It requires input parameters describing the transistor and the output is a vector of current values “Ic” corresponding to the elements of input vector “Vce”. It applies a simple linear approximation to the saturation region.