Basic Linear Algebra: Defining Vectors and Matrices

Vectors and Matrices what are they?

In Matlab everything is defined as either a vector or a matrix therefore it is imperative that you know what Vectors and Matrices are before you begin using Matlab.  The formal definition of a vector is something that has both a direction and a velocity. When using Matlab however, I think it is easier to think of a vector as either a row or a column of values. These values can be names, numbers, or anything you want. There are two kinds of vectors. These are row vectors and column vectors.

A Row Vector is a vector which has only One Row and can have as many columns as one wants. A row vector V with n columns is shown below.


 

 

Alternatively, a column vector is a vector which has only ONE Column and can have as many rows as one wants. A column vector V with m rows is shown below.

column-vector

Matrices

A matrix is a rectangular array of quantities or expressions. I prefer to think of them as 2-D vectors. Matrices have both numerous rows and columns.

The typical representation of a matrix is m x n meaning the matrix has m rows and n columns.

matrix

The subscripts of each element refer to its position in the matrix. Matrices come in all different sizes and shapes. A matrix who has the same number of rows as columns is called a Square Matrix.

How to define Vectors and Matrices in MATLAB

Row Vectors

row-vector-description

The use of the semicolon at the end of each line ensures that Matlab will not print off the value of V in the Command Window. If you wish to have it display this value when running, remove the semicolon.

Column Vectors

When defining column vectors in Matlab use the semicolon (;) to separate rows.

column-vector-description

Accessing Different Vector Indices

To access different indices in a vector the following notation is used.

To access the third index or the value of 7 in both of the vector examples above one uses V(3). This tells Matlab that you are referencing the third value in the vector V.

Lets say you wish to multiply the third and fourth entry of the vector V and store that value in the first entry. You would type

V(1)=V(3)*V(4)

Matrices

Matrices in Matlab are defined by combining both row and column vectors. A 3 by 3 matrix in Matlab would be defined as follows.

matrix-matlab

MATLAB Examples

1) Define a 4 element row vector and then replace the third element by the product of the first and fourth.

vector-example1

2) Define a 3 element column vector and then put the value of 5 into the second element.

vector-example2

3) Define a 4by5 matrix and then make it so when you run the Matlab script, the element in the 3rd row and 2nd column will be printed.

matrix-example

Practice Problems

1) Define a 3 by 2 matrix and replace the value on the second row second column with the value on the third row first column.

2) Define a row vector with 6 elements.

3) Define a column vector with 2 elements and make sure they both print when you run Matlab (Hint: semicolon)

Frequency Response for MOSFET/BJT

The frequency response of a BJT or MOSFET can be found using nearly the exact same process, with the only variations being caused by a single resistor and simple naming conventions that differ between the two devices.

Before we start let’s think a little bit about what we’re doing:
Our goal is going to be to find the pole(s) of the circuit.
Okay? What is a pole and why do I care where it is?
A pole is a frequency at which the gain of the device rolls off. (remember that when it rolls off , it will be at the -3dB frequency with a slope of -20dB/decade)

We care because if the gain of a device rolls off at a certain frequency, then we won’t be able to amplify a signal above that frequency very well because the gain will be decreasing by 20dB/decade.

The procedure is nearly identical whether we are using a BJT of a MOSFET, but we will work each of them side by side just in case there might be any confusion, and we’ll follow these steps as we go through.  (we will also use some values that came from the output file when running a simulation of this circuit in Cadence (or PSPICE) )mosfet-amplifier

bjt-amplifier
1. Take a look at one of the circuits and see what you notice, how about the MOSFET.  This step is just to help us with our knowledge understanding of the circuit.
– At a glance it just looks just like another MOSFET right? Sure is, but let’s take a look at a few things just for kicks. Notice that it is using a bypass capacitor at the source so we don’t have to worry about (at when working with high frequency).  Since the capacitor bypasses to ground, you should notice that this is a common-source amplifier.  You could notice the Values for and and start to think about what the Gate voltage is and how that may affect the circuit.
2. We are talking about frequency response so that means we are probably going to want to draw the small signal equivalent circuit.
Remember that the capacitors and will act like short circuits at high frequencies so we will ignore them, but we will have to account for some of the capacitance internal to the device.

Both devices have internal capacitances that are very similar.  As you can see from the small signal models for a MOSFET (above) and BJT (below), the only significant difference is that the BJT has an additional resistance Rpi between the Base and Emitter.

Most of the analysis we will do is based on the small signal model. Note that small signal models are not typically used in PSPICE so this picture may look a bit odd, especially the controlled source but for our purpose it is good to have a visual reference. To start we will point out what everything is. Cgs is an internal capacitance betwemosfet-small-signal-model

en the gate and source. The

values for Cgs was similar to one the a PSPICE simulation may give.  CM1 and CM2 are Miller capacitances which we will find values for laterbjt-small-signal-model.  ro is a Norton equivalent resistance that makes the model more ideal.  And just pretend that the G2 looks more like a voltage controlled current source and that their gains are gm*Vgs and gm*Vpi. For the BJT CM1 and CM2 are both Miller capacitances, Cpi is similar to Cgs and Rpi the additional component used for BJTs but not MOSFETs. The other part should look familiar from the other figures.

ON TO THE ANALYSIS!!!

We will find the device gain, overall gain, equivalent input and output capacitances, and the input and output poles. The process for both is essentially the same.

Device Gain: This is the gain from the control source to the output so we are looking for Vout/Vgs (or Vout/Vpi for a BJT). We will ignore CM2 for this process. Notice the resistances ro, RD, and RL are in parallel. Vout should be given by that equivalent resistance times the current though it which is gm*Vgs from the control source. So the equation for device gain is,

   (MOSFET)

  (BJT)

Overall Gain: This will be the gain from the source (Vs) to the output (Vout). We already know what Vout/Vgs is so if we find Vgs/Vs, we can multiply them to get Vout/Vs = (Vout/Vgs) * (Vgs/Vs).  Vgs/Vs is a simple voltage divider. Hopefully you can see this from the small signal model (remember that we are ignoring the capacitors for now but they will play a part later).  The equations we will get for Vgs/Vs and the overall gain are.

  (MOSFET)

Overall Gain:   (MOSFET)

  (BJT)

Overall Gain:   (BJT)

Now we will find the input and output poles.  For this we will need to look at the capacitances and use a formula to find the Miller capacitances, CM1 and CM2.  Any explanation for the miller capacitance will have to wait for another post or check out your Electronics Book, Wikipedia, Google, etc. but we will need to use a couple of special equations.  Overall we will need to find the input resistance and input capacitance for the input pole and the output resistance and output capacitance for the output pole.

Each pole will be at a frequency w=1/RC where the R and C are the equivalent R and C at that point, so to find the input pole, we will need to find the input resistance and the input capacitance.  These are found by looking into the input (the left side of the small signal model).  The voltage source will  act like a short so we see Rs in parallel with R1//R2 for the MOSFET (the BJT will have Rpi in parallel also).  The input capacitance will be Cgs in parallel with CM1 (the BJT will be the same).  The output resistance and capacitance are found the same way only looking in from the output (the right side of the small signal model).

      (MOSFET or BJT)

So the input pole will be: (MOSFET)

  =  950                                     =

  =                                               =

=                                                                          =

(BJT)

and the output pole will be: (MOSFET)

(BJT)

=                                  =

=                                                 =

=                                        =

To Do:

finish input & ouput R, input C, Pole (& calculate answers)

BJT Circuit and Symbol Conventions

The following is an explanation of symbol conventions , voltage polarities and current directions for npn and pnp BJTs. The goal is to help understand these characteristics but not on the physical level of electrons and holes. The following figure shows practical operation of each BJT in the active mode.

pnp-and-npn-bjts

npn or pnp

When looking at a BJT, the easiest way to decide whether it is npn or pnp is to look at the emitter, which is always modeled as the arrow. If you remember that the arrow tail is always at a ‘p’ node and the tip is at an ‘n’ node, you can easily decide whether the BJT is npn or pnp. Remember that the collector and emitter are always either both ‘n’ or both ‘p’.

Determining Voltage Polarities

It is important to know which direction the voltage’s will appear positive when we begin using nodal analysis to solve BJT circuits. Typically, there will be a voltage drop of .7 V over the nodes that will be used in these calculations. Whether or is positive is decided by the type of BJT. The voltage polarities are flipped between pnp and npn BJTs. Obviously, the only difference in the symbols between the two types of BJTS is the arrow, which is the emitter. If we remember the tip of the arrow is the lower voltage, we are able to deduce that for an npn BJT and for pnp.

To be in the active mode, a BJT’s collector-emitter voltage must be above approximately .3 V. As above, this voltage polarity is reversed between npn and pnp BJTs. To determine, whether or should be positive, we can use our deduction of the base-emitter voltage polarity. The voltages, in active mode, drop from collector to base to emitter in npn BJTs and from emitter to base to collector in pnp BJTs. So, if we have figured out that we are using an npn BJT because was a positive .7V, we know that the base voltage is higher than the emitter voltage. From here we know the collector must be higher than the base, and therefore, higher than the emitter. We have just figured out that must be greater than the .3V to be working in active mode. Using the same logic, must be greater than .3V for a pnp BJT to remain in active mode.

Current Flow Directions

Current directions are very simple to figure out. Just use the arrow. The collector and emitter currents always go in the direction of the arrow in active mode. The base current is a little more tricky to figure out, but is also fairly obvious when using the arrow as a reference. As you can see in the above npn circuit, where the arrow is ‘pointing’ away from the base, the base current flows towards the BJT, in the direction the arrow is pointing. Oppositely in the pnp circuit, the base current flows away from the BJT, in the direction the arrow is pointing. There is a table of basic equations listed in my post titled “BJT Transistor Nodal Analysis” which would allow us to calculate each current using a different current, but using Kirchhoff’s Current Law, knowing two currents, we could calculate the third. For a npn BJT, and for a pnp BJT . Note that both of these equations evaluate to .

BJT Transistor Nodal Analysis

Basic BJT Equations:

It is also important to know that can be modeled as .

These equations are not very informative by themselves so a few examples are demonstrated below. In both examples we will assume is very large. What this means for our calculations is . Since we also assume that .

Finding missing voltages in a BJT circuit

Example 1. Solve for V3:

bjt-voltagesThere are several ways to find . The more “difficult” way is to first find the emitter current, , and then use Ohm’s Law. Since we know , we can find the collector current, , and then solve for .

The easier way to find is to recall that behaves like a diode. For this pnp BJT: .

We know that so

may not always be a very large number. Had that been the case here, we would have started by finding the collector current (since it’s voltage drop and resistance are given) and since anymore, we would use the formulas above to the find the base and collector current.

Finding BJT Bias Voltages and Currents

Example 2 Solve for V2 and I1:

bjt-bias-current

Here we will want to start by finding . also equals which approximately equals and this collector current will allow us to find .

Notice that was given as .  If this had not been given, we would have been able to find it because and .

Similar to the previous example, if was not a very large number. We would first find the emitter current and then use the equations in the table to find the other branch currents.

Note that both of these examples used pnp BJTs. The difference in an npn BJT is the base-emitter voltage is reveresed. You would use .

General Rule of Thumb

Most of these problems are very simple to solve. Typically is given and you will need to use Ohm’s Law to identify one of the currents. After one of the currents is found you will be able to solve for the other currents using the basic equations listed above. If one of the currents is not immediately obvious, the base-emitter voltage is likely needed. Most problems have you deduce the emitter voltage from the base, but it is easily possible to find the base voltage from the emitter voltage and then use that to find the base current.

Time Shifting and Scaling of Functions

We’ll begin with a square function, f(t), that has a an amplitude of 1, a start time of 2 seconds and an end time of 4 seconds.

square-wave

Next, a time shift is demonstrated. Here our function is changed from f(t) to f(t-2). Notice that subtracting 2 from t in the function results in a positive shift of the graph.

positive-shifted-square-wave

In the next two graphs t will be scaled. Scaling t is not quite as intuitive as we may have expected. When we multiply t by 2, corresponding points of the function now occur at 1/2 the time they previously had. When we divide t by 2, each corresponding time on the graph occurs at a t that is now multiplied by 2. Notice that each of these factors directly affects the duration of the signal.

time-shifted-square-wave
time-shifted-square-wave2

Scaling the amplitude has more intuitive results. If we multiply f(t) by 2, the amplitude of 1 is changed to 2. Multiplying f(t) by 1/2 results in an amplitude of 1/2.

taller-square-wave
truncated-square-wave

Finally, multiplying t by -1 mirrors our function over the y-axis. Each time now occurs at its negative.

mirrored-square-wave


Example:

Here we will attempt to convert f(t) into 2*f(.5t+3). The graph of f(t) is shown below.

triangle-wave

The easiest way to handle this type of problem without error is to manipulate the function one step at a time. First, I have converted f(t) into 2*f(t). Only the peaks are changed here (by a factor of 2).

triangle-wave2

Next, I convert 2*f(t) into 2*f( t). Notice how the actually expands our graph duration by a factor of 2 (from a 6 sec duration to a 12 sec duration).

shifted-triangle-wave

Finally, we move from 2*f( t) to 2*f( t + 3). As shown in the discussion above, this is a time shift. Time shifts can be a little confusing because adding results in a negative shift of our graph. Try to think of it as our signal occurring 3 seconds earlier than before, reading from left to right on the graph. The easiest way to do this part is shift each x-intercept by 3 seconds (to the left, of course).

shifted-triangle-wave2