Top Banner
Sim Lab 8 Part 1 MATLAB
21

Sim Lab 8 Part 1 MATLAB

May 15, 2022

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Sim Lab 8 Part 1 MATLAB

Sim Lab 8 Part 1 –M ATL AB

Page 2: Sim Lab 8 Part 1 MATLAB

Prerequisites

● Please make sure you have completed the following:○ Lab 7 LTspiceTutorial Part 1 (Download and Installation)○ Lab 7 LTspiceTutorial Part 2 (Components and Basic Interface)○ Lab 7 LTspiceTutorial Part 3 (Basic Circuits)○ Lab 7 LTspiceTutorial Part 4 (Intermediate Circuits)

Page 3: Sim Lab 8 Part 1 MATLAB

Learning O b jec tives

1. Calculate an RC-circuit time constant from the values of resistance and capacitance.

2. Use LTspiceto generate and export data.3. Use MATLAB to load LTspicedata and produce plots.4. Measure rise time from an exponential voltage plot.5. Use rise time to estimate the time constant.

Page 4: Sim Lab 8 Part 1 MATLAB

Basic Terminology● Time Constant (RC):

○ The time constant, 𝜏𝜏 in seconds, of a resistor and capacitor circuit controls the rate at which the thecapacitor charges / discharges. The time constant (𝜏𝜏 = 𝑅𝑅𝑅𝑅) is the product of the effective resistance (in O hms) and capacitance (in Farads) of the circuit. The charge in the capacitor increasses exponentially starting at 0 when the capacitor is fully discharged to a final charge Q when the capacitor is fully charged.

○ O ften, the rise time, 𝑡𝑡𝑟𝑟 , or the time a voltage signal travels from 10% to 90% of its final value, serves as a convenient way to approximate the time constant from a circuit implementation, 𝑡𝑡𝑟𝑟 ≈ 2.2𝜏𝜏 [1].

○ An example can be found below [2]:

Eg. The time constant for the circuit above is 𝜏𝜏 = 𝑅𝑅𝑅𝑅= 1e+3 Ω x 10e-6 𝐹𝐹=10e-3 𝑠𝑠 = 10 𝑚𝑚𝑠𝑠, and we would expect a rise time 𝑡𝑡𝑟𝑟 ≈ 22 𝑚𝑚𝑠𝑠.

𝑡𝑡𝑟𝑟

Page 5: Sim Lab 8 Part 1 MATLAB

Performing basic RC circuit analysisIn this exercise, you will gather data from LTspice, save it to a file, and plot it in MATLAB.

In Lab 7 LTspiceTutorial Part 3 –Basic Circuits, you should have completed the two circuits found below.

Page 6: Sim Lab 8 Part 1 MATLAB

Performing basic RC circuit analysisLoad your prior code and run the simulation.

Page 7: Sim Lab 8 Part 1 MATLAB

Performing basic RC circuit analysisProbe Vout1 and Vout2 as shown.

Page 8: Sim Lab 8 Part 1 MATLAB

Performing basic RC circuit analysis

Your output should look like this:

Page 9: Sim Lab 8 Part 1 MATLAB

Performing basic RC circuit analysis

To plot the currents, place a probe over C1 and C2.

Page 10: Sim Lab 8 Part 1 MATLAB

Performing basic RC circuit analysis

Your output should look like this

Page 11: Sim Lab 8 Part 1 MATLAB

Exporting Data from LTSpice

After selecting the graph window, go to

File⇒ Export data as text

Page 12: Sim Lab 8 Part 1 MATLAB

Exporting Data from LTSpice• From “Select Traces to Export” choose “V(vout1)”, “V(vout2)”, “I(IC1)”, and “I(IC2)” ⇒ Browse

to the location where you want to save the text file containing your data.• Save to a location that you can easily access.)

Click OK

Page 13: Sim Lab 8 Part 1 MATLAB

MATLAB P lottin g

● Now open MATLAB ● From “New” ⇒ C hoose “Script”● An editor window will open

● You are welcome to use another software besides M ATLAB (Python, for instance), but you will need to learn to load the data and generate the plots yourself as this document will not provide the explicit steps.

Page 14: Sim Lab 8 Part 1 MATLAB

MATLAB P lottin gIn the editor, type something like the following, using your own path to the data.

Typical code for multiple plots on multiple figures:figure(1)plot(...)hold onplot(...)legend()xlabel(...)ylabel(...)title(...)figure(2)plot(...)hold onplot(...)legend()xlabel(...)ylabel(...)title(...)

Page 15: Sim Lab 8 Part 1 MATLAB

Matlab Plotting

● Make sure that you have done the following in your code:○ Full path to your file (Make sure it is a “.txt” file) ○ Your file name should not be the same as this one. This is just an example path. ○ Make sure that you are importing the same text file that you retrieved from LTSpice.

Page 16: Sim Lab 8 Part 1 MATLAB

Matlab Plotting

● The text file that you retrieved from LTspiceshould look something like this:

● After importing the Data you will find the data from “Variables column” as shown below:

Page 17: Sim Lab 8 Part 1 MATLAB

Matlab Plotting● Please make sure you are choosing the correct column to plot your data

For this example:The “data” matrix contains the data as follows:● Column 1: time● Column 2: Vout1● Column 3: Vout2 ● Column 4: IC1● Column 5: IC2

Page 18: Sim Lab 8 Part 1 MATLAB

Matlab Plotting

● You should see the two exponential voltage traces with two different time constants.

Page 19: Sim Lab 8 Part 1 MATLAB

Matlab Plotting

● You can also produce a currentplot like the one here.

Page 20: Sim Lab 8 Part 1 MATLAB

Questions :

1. Enter your UIN into the title of every MATLAB plot you produce to verify ownership.

2. Create one circuit and its voltage vs time graph with the specifications below:

a. R1 is going to be 1 𝑘𝑘Ω times fourth digit of your UINb. C 1 is going to be 1 𝜇𝜇𝐹𝐹 times the first digit of your UINIf your UIN digit is 0, use 10 instead.

3. W hat is the rise time, 𝑡𝑡𝑟𝑟 , of your circuit? That is, what is the time required for the voltage to go from 10 to 90% of its final value?

4. W hat is the time constant, 𝜏𝜏, of your circuit as estimated by the rise time?

Page 21: Sim Lab 8 Part 1 MATLAB

Citations

● [1] “RC time constant,” Wikipedia, 23-Mar-2020. [Online]. Available: https:// en.wikipedia.org/wiki/RC_time_constant. [Accessed: 30-Mar-2020].

● [2] “Integrated Publishing, Inc. - A (SDVOSB) Service Disabled Veteran Owned Small Business,” Integrated Publishing - Your source for military specifications and educational publications. [Online]. Available: http://www.tpub.com/neets/book2/3d.htm. [Accessed: 27-Mar-2020].