Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

EEEE2055: Modelling Methods and Tools

Coursework 2 – Spring 2022

Numerical Integration and Techniques

Coursework 2 is on the analysis of an RC circuit with LTSpice and Numerical Integration techniques. It accounts for 75% ofthe total mark.

Presentation and formatting of your report accounts for 25% ofthe total mark. Appendices A-C include hints and help.

Prerequisites

LTSpice simulation software. Please download and install from the developer’s website

directly:https://www.analog.com/en/design-center/design-tools-and-calculators/ltspice- simulator.html#

Presentation and report formatting

The report should have a logical structure throughout, a title/cover page, pagination, table of contents, sections and appendixes clearly labelled.

Written explanations should be relevant, clear, easy to understand without spelling mistakes.

Figures, plots and tables should be enumerated and must have captions. They should be appropriate, of high quality, clean, embedded text should be of large font size.

Plots should be fully annotated. Appropriate waveform and axis labels should be included when plots are presented.

Include an explanation (minimum of 1 paragraph) ofwhat is shown in each figure/plot    included. Cross references should be used consistently when commenting or referring to figures, plots or tables.

Where external sources are used, correct referencing and citation should be conducted using an appropriate referencing style (e.g. IEEE referencing style).

Do not rely on the standard LTSpice annotation capability, nor on default colours used – they are inappropriate for inclusion in a report as shown on your screen! Instead, annotate further   where needed and change the colours used to make your report look professional and the        plots read friendly.  The text size and colours should be chosen to ensure readability and         professional look.

Help and hints are given in Appendix A.

Task: Analysis of an RC circuit with LTSpice and Numerical Integration techniques

An RC circuit consists of an uncharged ideal capacitor = in series with an ideal       resistor = . The voltage source is ideal and can generate pulses of voltage.       The initial voltage across the capacitor is 0V. At time t=0 a voltage step = is given by the voltage source.

Hints on the operation of the circuit:

•    Initially the capacitor voltage is zero and all the voltage supplied appears across the resistor.

•    The initial (peak) current in the circuit is = .

•    As time passes and the capacitor charges, the voltage across the capacitor increases exponentially from an initial value of 0V to the asymptote of voltage .

•     Simultaneously the current falls exponentially from the peak value of to the asymptote ofzero amperes.

•    The equation of the current () as a function of time is () = / , where = .

Fig. 1 RC circuit to be modelled in LTSpice

1. Initial Simulation in LT Spice

1.1. Build the circuit ofFig.  1in LTSpice. Set the simulation Stop time to 60ms and  the Maximum Timestep to 10ns. Include a good quality image ofthe LTSpice    model and images showing your stop time and maximum timestep in your report.

Run the simulation and plot the following quantities. Add grid, mark datapoints and include a good quality plot in your report.

(a) the current through the capacitor (),

(b) the voltage across the capacitor (),

(c) the voltage across the resistor ().

(d) the instantaneous capacitor power ().

Hint: () is equal to the product ofthe current and voltage waveforms i.e.

() = () ()

(e) the instantaneous resistor power () = () ()

2. Comparison of results with varying timesteps

Re-run the simulation with the following Maximum Timesteps: 100ns, 1μs, 10μs, and 10ms. Record the duration of each simulation to create a plot of Simulation time vs Maximum timestep. Include all plots in your report and use them explain qualitatively   and quantitatively the impact oftime step in the accuracy and duration ofthe simulation.

3. Analytic calculation: Energy dissipation in the resistor and capacitor

The energy dissipated in the resistor, (), and the energy stored in the capacitor, (), can be derived by integrating the resistor power () and the capacitor power ()        from 0 to . The equations are given below and the derivation in Appendix B.

= (1 − ), = ( 1 − )

Using the equations given, calculate the energy dissipated in the resistor and the energy stored in the capacitor within the first 0.5ms, 5ms, 10ms, 30ms and 60ms after the        voltage step has been applied.

4. Estimation of Energy at Specified Time Intervals using LT Spice

4.1. Look within the control panel of LTSpice to identify the integration method used in LTSpice, write it in your report and give a short explanation on how it works.

4.2. With the use of the LTSpice integration functionality, find the energy stored in the    capacitor and the energy dissipated in the resistor during the first 0.5ms, 5ms, 10ms, 30ms and 60ms ofthe voltage step when the maximum step size is set to 10ms and 100ns.

4.3. Compare the value predicted by LTSpice with that from the analytic calculation by calculating the error in %. State whether they are an over estimation or an under      estimation ofthe correct value.

5. Analysis of LTSpice data points and Dataset preparation using MATLAB

Re-run the simulation for 60ms with the maximum time step set to 10ms and to 100ns.


5.1. Extract both LTSpice datasets in a text file and include the first 10 lines ofthe             exported text file in the body of your report. Submit the text file containing the full     contents ofthe exported data as a separate file named e.g. “dataset1.txt” . Clearly state the file name in your report.

5.2. Observe the spacing between data points and comment on whether the spacing from  your exported data points is uniform or not. Discuss their appropriateness to use with the Trapezoidal rule and Simpson’s rule.

From this point onwards use the exported data with maximum time step set to 100ns. See Appendix C for hints and help but also for complete MATLAB scripts and commands.

5.3. Use MATLAB (or any other method of your choice) to prepare datasets which can be used to calculate the resistor and capacitor energy with Simpson’s rule of 10, 100,       1000 and 10,000 intervals.

5.4. Explain your method (e.g. scripts in Appendix C or otherwise), include the first 10 data points in the body of your report and submit the full datasets as separate files  named e.g. “dataset2.txt”. Clearly state the file names in your report.

6. Calculation of Energy using Simpson’s Rule and Trapezoidal Rule in Matlab

6.1. Adjust the MATLAB scripts given in Appendix C (or build your own scripts) to calculate the resistor and capacitor energy during the first 10ms and 60ms ofthe simulation by using Simpson’s rule of 10, 100, 1000 and 10,000 intervals.

Report the method you used (e.g. scripts from Appendix C, own scripts etc) in the     body of your report, explain any changes you might have done and include the script in an appendix.

6.2. Develop a MATLAB script to calculate the resistor and capacitor energy during the first 10ms and 60ms of the simulation by using Trapezoidal rule of 10, 100, 1000 and 10,000 intervals. Discuss/explain the script/method you developed.

The MATLAB scripts given in Appendix C can be used as the basis of your own built MATLAB script for Trapezoidal rule. Do NOT use the trapz MATLAB command.

7. Error of Numerical Integration Techniques

7.1.  Calculate the error (in %) from Matlab scripts in 6 and compare the results with

those from the LTSpice in 4. and the analytical calculations in 3. Consider presenting your results using tables.

7.2.  The MATLAB commands tic and toc give how long it takes for the scripts to run.   See the related help entry here:https://uk.mathworks.com/help/matlab/ref/tic.html .

Plot the error vs time and the error vs intervals for Trapezoidal rule and for  Simpson’s rule. For a more representative reading, consider running the codes multiple times, and then average to find the time for a single run.

7.3.  By making use of your results and plots, discuss the accuracy ofthe numerical

integration.  Consider referring to the theory of error in numerical integration when analysing and commenting on your results.

Appendix A: Hints and help with LTSpice

1.   To set the simulation Stop time and also the Maximum Timestep you can edit the

simulation command. This can be found by clicking “Simulate” and then “Edit Simulation Cmd” as shown inFig.  2.

Fig. 2 Setting the simulation timestep and stop time

2.   Examples of good quality waveforms and figures from LTSpice are given inFig.  3and Fig.  4. These can be improved further by annotating them in Word or PowerPoint.

Fig. 3 RC circuit in LTSpice

Fig. 4 Plot exportedfrom LTSpice. Further annotation needed to make it "Report Ready".

3.   The voltage source can be defined as a source ofvoltage pulse. One long pulse is needed, so the voltage pulse can set up as: PULSE(0 300 0 0 0 1 2m).

4.   To plot the voltage across a component or the voltage difference between two nodes,  click on the left side of the component (cursor will be a red probe before, then turning

gray), drag over the component to the right (cursor will be a black probe), then release the mouse button. The graph will show something like V(N002,N003) which is the voltage     between those nodes.

5.   To add a new waveform (trace) based on a mathematical expression, after running the      simulation, right click somewhere inside the plot pane and select the "Add Traces"           option. A menu will appear that includes all available data sources for the simulation and a text box to enter a trace expression or expressions in to.  For power, the expression

should be the multiplication ofthe voltage difference across a component with the current

through it. This is shown inFig.  5.

Fig. 5 Adding traces to an LTSpice plot based on a mathematical expression

6.   LTSpice Integration functionality: The LTspice waveform viewer can integrate a trace to   produce the average or RMS value over a given region. To integrate a trace in the               waveform viewer: (a) Zoom in to the region of interest. (b) Hold down the control key       and click the label of the trace you want to integrate. Based on the physical units ofthe       data trace, LTspice IV displays a meaningful average for that type of data. For example, if the units are a voltage or current, LTspice IV displays the average and the RMS values.      Otherwise, LTspice IV displays the average and integral ofthe data displayed in the           waveform viewer.

Appendix B: Derivation of resistor and capacitor energy functions

The initial (peak) current through is = . As time passes and the capacitor charges, the

voltage across the capacitor increases exponentially from an initial value of 0V to the               asymptote ofvoltage V. Simultaneously the current falls exponentially from the peak value of to the asymptote of zero amperes.

The equation of the current () as a function of time is () = / , where = .

The instantaneous power dissipated in the resistor is given by () = 2() = −2/

To calculate the energy dissipated in the resistor, , we need to integrate () from = 0 to .

= ∫

= [

() = ∫ 2 ()

|         − |=0

=

] = −

2

2

[ − 1]

If we substitute = and = :

1                           2

= 2 (1 − )

To calculate the total energy dissipated in the resistor, , we need to integrate () from = 0 to = ∞ . So =

The instantaneous power of a capacitor is the product of its instantaneous voltage and

instantaneous current () = () (). We also know that () = () and () = ()

()  ⇒ () = ()()

() = 1 (())2

We know that () = () = / and = so: () = (1 − /)2



Appendix C: Data manipulation and Numerical Integration with MATLAB

This appendix contains useful information and MATLAB scripts on how to manipulate data and apply numerical integration.

When you extract the data required from LTSpice, it will create a .txt (e.g. data.txt)               containing the information you have selected to export. I hereby include exemplary contents of a data.txt file containing the exported time, resistor power (Pres) and capacitor power       (Pcap).  The file is tab separated and I have manually changed the first row to obtain better   represented column titles.