This is an old revision of the document!
| Chapter | Assignments | Course Topic | Matlab Topic |
|---|---|---|---|
| Ch 0 | MT240.NR.0 | Intro to MATLAB | Matlab Basic Operations, Matrix Operations, |
| Array Operations, Script Files | |||
| Ch 1 | MT240.NR.1 | Electrical Engineering Overview | |
| MT240.NR.1.6.1 | Power and Energy | Graph Function , Axis Control, | |
| Annotation, Figures | |||
| Ch 2 | MT240.NR.2 | Circuit Elements | |
| Ch 3 | MT240.NR.3 | Simple Resistive Circuit | |
| MT240.NR.3.2.1 | Resistors in Parallel | Function Files | |
| MT240.NR.3.4.1 | Voltage and Current Division | Function Files | |
| Ch 4 | MT240.NR.4 | Techniques of Circuit Analysis | |
| MT240.NR.4.3.1 | Node-Voltage w/ Dep. Sources | Inverse Matrix | |
| MT240.NR.4.12.1 | Maximum Power Transfer | Review | |
| Ch 5 | MT240.NR.5 | Operational Amplifier | |
| MT240.NR.5.3.1 | The Inverting-Amplifier Circuit | If-statement, For-loop | |
| MT240.NR.5.4.1 | The Summing-Amplifier Circuit | Functions continued | |
| Ch 6 | MT240.NR.6 | Inductance & Capacitance | |
| MT240.NR.6.2.1 | The Capacitor | Perform an Integral using a for-loop | |
| Ch 7 | MT240.NR.7 | Response of 1st-Order RL & RC | |
| MT240.NR.7.2.1 | Natural Response of RC Circuit | Review | |
| Ch 8 | MT240.NR.8 | Nat. & Step. Resp. of RLC Circuit | |
| MT240.NR.8.2.1 | Forms Nat. Resp. of Parallel RLC | Polynomial Roots, Real and Imaginary Command | |
| Ch 9 | MT240.NR.9 | Sinusoidal Steady-State Analysis | |
| MT240.NR.9.1.1 | The Sinusoidal Source | Review | |
| MT240.NR.9.9.1 | Mesh-Current Method | Mesh, Complex Numbers | |
| Ch 10 | MT240.NR.10 | Sinusoidal Steady-State Power Calc | |
| MT240.NR.10.4.1 | Complex Power | Text | |
| Ch 12 | MT240.NR.12 | Intro to L. Transform | |
| Ch 13 | MT240.NR.13 | L Transform in Circuit Analysis | |
| Ch 14 | MT240.NR.14 | Intro to Freq. Selective Circuits | |
| MT240.NR.14.4.1 | Band-Pass Filter | Logarithmic Plots | |
| Ch 15 | MT240.NR.15 | Active Filter Circuits | |
| MT240.NR.15.1.1 | First-Order Low-Pass & High-Pass | Review |
Read and follow along with the document to get an introduction to MATLAB.
After completing the document, make sure that you feel comfortable with the following MATLAB topics:
Matlab Basic Operations
Matrix Operations
Array Operations
Script Files
Even if you feel comfortable, click on the links above and become familiar with the MATLAB guide
provided on the wiki page. You may need to reference it later in the course.
(Not required, but for fun)
Fun application Any wave or signal can be made up of tons of sinusoidal signals composed of different frequencies and amplitudes. The program below creates a square wave from n-number of input signals. Play around with the number of input signals to see the effect of adding more and more input signals.
To run this program you will need to edit the code and use your summing op amp function.
MT240_NR_7_2_1 Natural Response of RC Circuit
Objective: Gain a visual understanding of how resistors affect the rate a
capacitor dissipates energy by analysing the voltage across the
capacitor as a function of time and tau.
Exercise: You have several 20mF capacitors with an initial voltage of 20V.
You design circuits composing of one capacitor and one
resistor. Every resistor has a different value, and the
resistor values range from
R = 1e3:1e3:10e3
The resistor and capacitor are connected together at t = 0.
Analyse the voltage across every capacitor as a function of
time.
C = 20e-3; the value of the capacitor
Vinit = 20; initial voltage across the capacitor at t =
0s
a) Calculate the various values of tau for every RC circuit.
tau = R*C.
tau = INSERT CODE HERE
b) Create the time array to use for every circuit. The duration of
time must be >= 5*tau of the largest tau.
the largest tau is from the largest resistor.
time_beg = 0;
time_step = 10;
time_end = 5*tau(?); index you tau array
t = time_beg:time_step:time_end; an array of time
c) Calculate the voltage across the capacitors as a function of
time.
V(t) = Vinit*exp(INSERT CODE HERE);
d) Calculate the voltage across the capacitor as a function of tau;
t_tau = 0:0.1:5; array of tau
V(tau) = Vinit*exp(-t_tau);
e) Create two plots: one with the voltage as a function of time and the other
with voltage as a function of tau.
f) Questions:
1) How does resistance affect the rate at which a capacitor
discharges?
2) Why are the plots the same when going by tau?
MT240_NR_8_2_1 RLC Circuit
Objective: Gain a visual understanding of how the resistance in an RLC
circuit can affect the circuit's response.
Commands: roots, real, imag
Background: So far you have explored specific solutions to the three RLC
cases: underdamped, overdamped, and critically damped. In this program
you will explore the general solution of a parallel RLC circuit that generates
all three cases. Your book introduces the general solution in section 8-1,
and we will use it to derive the necessary equation.
The goal is to create the general solution as shown below.
X(t) = A1*exp(s1*t) + A2*exp(s2*t)
Below I will explain how to derive the general solution
The second order differential equation for a parallel RLC circuit is
d^2i/dt + (1/RC)di/dt + I/LC = 0.
This equation is transformed into the characteristic equation.
s^2 + (1/RC)*S + 1/LC = 0
Notice how the equation is a second order polynomial that can be solved.
By solving for the roots of the characteristic equation you obtain s1, and
s2.
With s1 and s2 known, you can set up a system of equations to solve for
A1 and A2.
X_init = A1*exp(s1*0) + A2*exp(s2*0)
dx/dt = A1*s1*exp(s1*0) + A2*s2*exp(s2*0)
Now that A1, A2, s1, and s2 are found, you can generate the general
solution.
X(t) = A1*exp(s1*t) + A2*exp(s2*t)
Exercise: You have a parallel RLC circuit as shown in the image below.
The current source has a value of 3A, the capacitor 100uF, the inductor
4H, and a potentionmeter (R) assumes the values R = 70:200:1070. Assume
that the switch has been closed for a long time before opening it at t =
0s.
a) Calculate the general solution to the RLC circuit for every resistor.
There should be 6 resistor values.
b) Plot the current through the inductor as a function of time for all
values of R.
c) What happens as resistance increases? And why?
MT240_NR_9_1_1 Sinusoid Source
Objective: Gain a visual understanding of how fast a capacitor can
discharge and charge for a given tau. Also, learn how to identify the
voltage waveform of a capacitor.
Background: It is possible to model a sinusoidal source using a DC source
if the DC source is connected to a toggling switch that turns on and off.
In this exercise you will model a sinusoidal source using a DC source.
Exercise: You have a circuit as described in the image below. The switch
toggles between position a and position b. At t = 0 there is no energy
stored in the capacitor and the switch is in position a. At t = 2*tau
the switch moves to position b and so on as indicated in the table.
Note that at each switch even time starts over at t = 0.
| time | position |
| t = 0 | a |
| t = 2*tau | b |
| t = 2*tau | a |
| t = 4*tau | b |
| t = tau/4 | a |
| t = 4*tau | b |
| t = tau/6 | a |
| t = 2*tau | b |
| t = tau/10 | a |
| t = 4*tau | end | End the simulation
a) calculate the voltage as a function of time
b) plot the voltage as a function of time with time being in ms
c) How would you create a waveform that closely approximates a triangle?
In other words, how fast must the switch toggle between position a and
b?
MT240_9_9_1 Mesh_Current Method
Objective: Design a circuit using capacitors and resistors that cause
Vout to be 180 degrees out of phase with Vin.
Background: Oscillators can be constructed from op-amps and an RC network.
The basic theory is to create a 180 degree phase shift between Vin and
Vout. This will cuase the op-amp to continuously oscillate in attempt to
make both inputs the same voltage level (virtual short).
Exercise: Refer to the provided image for this problem.
You want to design a circuit that will oscillate at 40e3 Hz. You only
have one resistor value (R = 1e3 ohms), but you have the various
capacitors available (C = 1e-9:1e-10:20e-9). You decide to write a
program to calculate the angle of Vout in reference to Vin as a function of
Capacitance. To simplify calculations, you decide that every resistor
must have the same value and every capacitor must have the same value.
Also, since you are only interested in the phase shift of Vout, assume
Vin to have a value of 1AC
%Variables
C = 1e-9:1e-10:20e-9;
R = 1e3;
w = 2*pi*40000;
ZC = 1./(1j*w*C);
Vin = 1;
ic = zeros(1,length(ZC)); allocate space
a) Label the currents in each mesh from left to right ia,ib, and ic.
Use mesh current method to write a system of equations.
System of Equations
Vin = ia(...) + ib(...) + ic(...)
0 = ia(...) + ib(...) + ic(...)
0 = ia(...) + ib(...) + ic(...)
Put the system of equations into matrix form.
Matrices
Impedances Currents A
| (...) (...) (...) | * | ia | = | Vin |
| (...) (...) (...) | * | ib | = | 0 |
| (...) (...) (...) | * | ic | = | 0 |
b) Solve for ic for every capacitor value. Remember that all
three capacitors will have the same value. This means that
you should have 191 different values of ic.
%Solve for Currents: ia, ib, ic
for m = 1:length(C)
Impedances = [INSERT CODE HERE];
A = [Vin;0;0];
Currents = INSERT CODE HERE;
ic(m) = Currents(3);
end
c) Calculate Vout for every value of ic.
d) Calculate the phase shift of Vout in Reference to Vin.
e) Plot the phase shift as a function of capacitance
f) Question: Approximate the capacitor value that would create
a phase shift of 180 degrees.
MT240_10_4_1 Complex Power
Objective: Gain a visual understanding of complex power
Functions to learn: refline (this could be useful) to plot avg P and
reactive P. text (this could be useful) to label your average and
reactive power.
Exercise: You have seven black boxes(representing unknown circuits), each with terminals
coming out of them. You are curious to identify which circuits are more inductive, capacitive, or neither.
You begin by measuring the voltage and current across each terminal and measure the voltage phase shift in
reference to the current phase shift by setting the current phase shift to zero. From your measurements you
gather the following parameters:
V = 5*cos(w*t + thetaV), with 'w' being the frequency in rads/s (w = 100*pi),
't' being the duration of time (t = 0:T/100:2*T - T/100), 'T' being the period
of the signal (T = 2*pi/w), thetaV being the voltage phase shift,
(thetaV = [-pi/2, -pi/4, -pi/6, 0, pi/6, pi/4, pi/2]. thetaV(1) represents the first
black box, thetaV(2) the second and so on), and a current I = 1.25*cos(w*t). To gain a visual
understanding you decide to calculate and plot the average power, reactive power, and instantaneous
power for the different voltage phase shifts using the parameters given.
a) Calculate the voltages as a function of time for all values of thetaV.
b) Calculate the Vrms and Irms using a for-loop to approximate an integral
Vrms = sqrt((1/T)*integral(V(t), from 0 to T)dt) bounds of integration are
from 0 to T. Verify your calculation using the equation Vrms =
Vm/sqrt(2).
c) Calculate average, reactive, and instantaneous power for every thetaV.
d) Plot voltage, current, average, reactive, and instantaneous power obtained from part c.
It might be best to create a single plot for each theta since you are
plotting a lot of information on each graph. Using a legend, titles,
and labels will help you sort through the information.
e) Why are all of the calculated Vrms values the same even though the
phase shift was different?
f) When the reactant power is zero what is the relationship between the
phases of voltage and current? What does this tell you about the
circuit.
g) When the reactant power is below zero does the voltage lead or lag the current.
Is the circuit more inductive or capacitive?
h) When the current and voltage are in phase, why is the instantaneous
power never below 0? When it is below zero what is happening to the
power?
MT240_14_4_1 Cross over network
Objective: Gain an understanding how you can use matlab to help you
design lowpass, bandpass, and highpass filters.
functions to learn: log10, semilogx
Introduction: A crossover network consists of a highpass, lowpass, and
bandpass filter. They are often used in stereo systems that separates
a signal into three signals (bass, treble, and midrange). You will design
a basic crossover network as depicted in the image below.
Exercise: Design a crossover network with the following specifications:
| | Low pass | Bandpass | High pass |
|Lower cut off frequency | N/A | 250Hz | 2000Hz |
|Upper cut off frequency | 250Hz | 2000Hz | N/A |
a) For each filter design you will be calculating the transfer function
of the voltage across each resistor. The equations should be simple
voltage division as shown in the book. See chapter 14. Design your
circuits choosing appropriate values for the capacitors and inductors.
b) Find the magnitudes (|H(jw)|) for v1, v2, and v3 as a function of 'w'
(frequency) with w being w = 0:10*2*pi:3e5*2*pi. Note that this is the
transfer function (H(jw) = vout/vin) thus the amplitude of the input voltage
source isn't needed in your calculations.
1) The midrange is a little more difficult so I provided you with the
steps.
a) Calculate the bandwidth. B = upper corner frequency - lower fc
b) Solve for the inductor using the relationship B = R/L
c) Solve for the capacitor value.
c) Plot the magnitude in decibels vs the frequency(Hz) using a
logarithmic scale. (use semilogx for this).
d) How could you design a bandreject filter that rejects frequencies
between 250Hz and 2000Hz?
MT240_15_1_1 Active Filter
Objective: Design a an active, low-pass filter using an op-amp
Commands: none
Background: While designing your crossover network you realized that
the bass speaker's (low pass) amplifier has broken. You then decide to
build the low pass filter and amplifier as one unit using an op-amp.
You decide to get fancy and use a variable capacitor so that you can
change the corner frequency.
Exercise: You decide to have design according to the topology shown in
the image below.
a) Design your circuit to have a max gain of 10.
b) Your variable capacitor can assume values within the range: C = 1e-8:1e-7:1e-6;
c) For every capacitor value calculate the transfer function |H(jw)| as a
a function of frequency using w(rads/sec) = 0:5*2*pi:3e5*2*pi;
d) Create a bode plot of the results obtained in part c. Plot them all on
the same graph.
d) What value should the capacitor be if you want a corner frequency of
about 140 Hz?
e) What affect does the size of the capacitor have on the bandwidth?