Plots, Curve-Fitting, and Data Modeling using Microsoft Excel (How to Plot Data)

  • Upload
    tim-foo

  • View
    227

  • Download
    1

Embed Size (px)

Citation preview

  • 7/27/2019 Plots, Curve-Fitting, and Data Modeling using Microsoft Excel (How to Plot Data)

    1/11

    NGEE ANN POLYTECHNIC

    School of Engineering

    (Electronic & Computer Engineering Division)

    BME Project Design (BPD)Plots, Curve-Fitting, and Data Modelling in

    Microsoft Excel

    Table of ContentsIntroduction.......... ..................................................................... .................................................................... .................... 1

    1.1 Simple X-Y Plots .................................................................. .................................................................. .......... 21.2 Changing the Plot Appearance...................................................................... .................................................... 31.3 Log Scales ............................................................. ........................................................................ .................... 5

    2 Curve-Fitting, or Trend lines ........................................................... ...................................................................... 62.1 Preparing Multiple Data Series for Ploting........................................................................ ............................... 72.2 Ploting Multiple Data Series ................................................................... ........................................................ 10

    3 Concluding Remarks............ ................................................................ ................................................................... 11

    Introduction

    This handout offers some tips on making nice plots from data collected like those in your project,as well as instruction on how to use the built-in curve-fitting routines in Microsoft Excel. Excel is agood utility program for data recording and plotting, and is actually used a lot by practicingengineers in industry. The main reason for its popularity is simply cost and convenience (most

    people have it on their computers) making information sharing very easy.It is also easy to learn and use. With a little extra effort you can write your own computationalroutines using the built-in VBA (Visual Basic) compiler. If you already know how to create a

    This copy Belongs to:

    Team Nbr:

  • 7/27/2019 Plots, Curve-Fitting, and Data Modeling using Microsoft Excel (How to Plot Data)

    2/11

    Ngee Ann Polytechnic ECE

    BPD fwj16/06/20122

    basic X-Y plot on Excel, then skip ahead to page 5 and go straight to section 1.2 Changing thePlot Appearance..

    1.1 Simple X-Y Plots

    Table 1 includes measured data on the current-voltage relationship of a diode that we can usefor demonstration of the plotting and curve-fitting features of Excel.

    Start by entering the data in two columns asshown in the figure below.Select the two columns (hold down the Left

    Mouse Button and Drag out a rectangular box )and then from menu: Insert > Chart (or

    just click on the Chart icon from the toolbar if itis visible). You will then see a dialog box likethat shown in the figure below. Select the XY(Scatter) chart type as shown. In this case thereare some options (sub-types) that control whethereach data point is highlighted by a marker ofsome kind, and whether a smoothed (or straight)line is shown connecting these data points. Thatisnt really important at this stage because one

    can always change the appearance later, but letsstart by choosing the smoothed-lines with datamarkers (highlighted selection in the figure).

    Now select Next and you will see the SourceData dialog box. Click on the SeriesTab andyou will see something like this:

    This gives a snapshot of what the graph will looklike so far, and the source of data. It will look alittle strange for a diode characteristic because itgenerally do not conform to the way the theory

    was taught in the textbooks. Excel has assumed the first column represents the horizontalcoordinate, so we need to switch the X and Y data range around.

    Table 1 Sample Diode I-V Data

    (Note: these are actual

    data recorded from acertain diode. In thisstudy an exponentialdependence wasexpected. So a list ofdiode currents thatwould yield a nice

    plot was used andthose diode voltagesthat produced thosecurrents was

    recorded.

    I V

    [mA] [Volt]0 0

    0.001 0.240.005 0.340.01 0.360.02 0.390.05 0.430.1 0.460.2 0.490.5 0.531.0 0.572.0 0.605 0.65

    10 0.6814 0.69

    Step 1, enter datathenselect the columns

    Step 2, frommenuInsert > Chartor use toolbar

  • 7/27/2019 Plots, Curve-Fitting, and Data Modeling using Microsoft Excel (How to Plot Data)

    3/11

    Ngee Ann Polytechnic ECE

    BPD fwj16/06/20123

    This is easy, just interchange the dataranges for the X and Y values. It is alsouseful to give the data series a name likeData (or Measurements) which willappear in the legend.

    Now select Next and you will see the

    Chart Options dialog box below. Hereyou can add labels for the x- and y-axesby keying in the Value (X) axis andValue (X) axis as shown:

    At this point click Finish and the plotappears in the worksheet.

    1.2 Changing the Plot Appearance

    The plot shown is the default Excel format for plots, which looks OK on a computer screen but notgreat in a printed document or presentation. If you right-click anywhere within the xy axis, youwill see a list of options for changing the plot appearance.

    First, to change the plot area background colour from gray to no colour (or white); right-click in

    the plot and select:Format plot area > area >none.To add major gridlines on the x-axis, right-click inside the charts Plot Area and select ChartOptions.After the major gridlines are added for both axis, these grid lines can be reformatted (to changeStyle and Weight) to be dashed lines. Similarly the title and legend can also be moved and besuitably modified:

  • 7/27/2019 Plots, Curve-Fitting, and Data Modeling using Microsoft Excel (How to Plot Data)

    4/11

    Ngee Ann Polytechnic ECE

    BPD fwj16/06/20124

    In the example, the legend was moved inside the chart (just drag it in there), the plot was resized,and the border was eliminated around the chart area.

    That is starting to look like a nicely formatted plot, but there is still changes that are generallystrongly recommended, and that is increasing the: weight of the connecting line

    Format Data Series > Line> Weight , the size of the markers and the fonts used in Title Label.

    Do this by double-clicking on one of the data points to launch the following dialog box.You edit the font size of the axis labels and legend by double-clicking on those labels and makingthe appropriate change. After doing this you should get the following:

    Measurement of Diode V-I Characteristics

    0

    2

    4

    6

    8

    10

    12

    1416

    0 0.2 0.4 0.6 0.8Diode Voltage V, Volt s

    CurrentI,mA

    Data

    This is a suitably formatted plot for a professional looking report or power-point presentation.

    Measurement of Diode V-I Characteristics

    0

    2

    4

    6

    8

    10

    12

    14

    16

    0 0.2 0.4 0.6 0.8

    Diode Voltage V, Volts

    Curre

    ntI,mA

    Data

  • 7/27/2019 Plots, Curve-Fitting, and Data Modeling using Microsoft Excel (How to Plot Data)

    5/11

    Ngee Ann Polytechnic ECE

    BPD fwj16/06/20125

    1.3 Log Scales

    Since many of the diode data pointsinvolve small currents, they appear closeto zero on the linear scale shown above. Alogarithmic scale is sometimes used to

    effectively expand the scale for smallcurrents. This is done in Excel by double-clicking on the appropriate axis (Y axis inthis case)Format Axis > Scale >Logarithmicscale ; click this and press OKThe data seems to fall on a straight line,which is what wed expect for anexponential dependence. Minorformatting issues can be addressed here;note that the x-axis intersects the y-axis at

    1 mA; on a log plot like this wed preferto have the x-axis and labels lie along the

    bottom of the chart. This can be done bygoing back to the Format axis dialog box (by double-clicking on the y-axis) and typing in theappropriate intercept value for the x-axis inside the Value (X) axis crosses at: box. In this casethe appropriate value is 0.001. Now your plot should look something like this:

    Diode V-I Character istics

    0.001

    0.01

    0.1

    1

    10

    100

    0 0.2 0.4 0.6 0.8

    Diode Voltage V, Volts

    CurrentI,mA

    Data

    Measurement of Diode V-I Characteristics

    0.001

    0.01

    0.1

    1

    10

    100

    0 0.2 0.4 0.6 0.8

    Diode Voltage V, Volt s

    CurrentI,m

    A

    Data

    Here a shorter title was used and theline connecting the data points wasremoved in preparation for the nextstep, which is to add a second Modelcurve to compare the data (measuredvalues of V-I) against our diode model.Just double-click on one of the data

    points and

    Format Data Series > Patterns>Line >None

    Note that the limits of the vertical scalecan be adjusted, but in this example

    Excel has automatically chosenappropriate values. So we now havesomething that looks like:

  • 7/27/2019 Plots, Curve-Fitting, and Data Modeling using Microsoft Excel (How to Plot Data)

    6/11

    Ngee Ann Polytechnic ECE

    BPD fwj16/06/20126

    Diode V-I Character istics

    0.0001

    0.001

    0.01

    0.1

    1

    10

    100

    0 0.2 0.4 0.6 0.8

    Diode Voltage V, Volts

    CurrentI,mA

    Data

    Expon. (Data)

    2 Curve-Fitting, or Trend linesSemiconductor diodes are usually modelled by a relationship of the form:

    I=Is[eqV/nkT

    1 ] (eq 1)where n is the ideality factor,Is is the reverse saturation current, and kT/q 0.026 Vat roomtemperature. How can we use the measured data to determine appropriate parameters for thesaturation current and ideality factor for this diode? There is an easy way to do this using theTrendline feature in Microsoft Excel.Click on the data series to which you want to add a trendline. Right click on the data series in thechart toAdd Trendline.; you will then see a new dialog box appear as shown below:

    You can see that there are a few different options for curve-fitting the data, but if you do not grabthe corner of the data seris and remove the 0,0 entry the one important type (Exponential) will begrayed out.Do you know why?

    The reason is that our data setincludes an I (0) = 0 data point,which theoretically can neverhave a simple exponentialmodel!The trick here is to remove that(0,0) data point from the plot;the easiest way to do this is to

    just grab one of the top cornersof the boxes enclosing the data

    and adjust the series-data rangeto exclude this point. Do thatfor both the current and voltagecolumns, and now you should

    Grab thiscornerwith thecursor

    and drag itdownone row toremove theI=0data point

  • 7/27/2019 Plots, Curve-Fitting, and Data Modeling using Microsoft Excel (How to Plot Data)

    7/11

    Ngee Ann Polytechnic ECE

    BPD fwj16/06/20127

    see all of the available curve-fitting options when you select Add Trendline again:

    Now select the exponential model and hit OK. Excel will find the best fit of the data to a modelof the form

    I=AeVand plot this on the chart as shown:A pretty good fit in this case. But wed really like toknow what the curve-fit parameters are, right?Double-click on the trendline and select the optionstab to get the following:Here we want to select Display equation on chart.You can also change the name of the trendline toModel. With a few additional but minor formattingchanges

    The last step is to simply compute the parameters wewant from the information Excel has provided. In this

    case Excel has told us thatI=AeV

    is a pretty goodfit to the data when

    A = 5 106 and = 21.557 21.6

    Note that our vertical scale isin milliamps, so the fitting

    parameterA also has theseunits; in other words,

    A = 5 nA .Now, going back to our diode

    model in (eq 1), we see that forIs

  • 7/27/2019 Plots, Curve-Fitting, and Data Modeling using Microsoft Excel (How to Plot Data)

    8/11

    Ngee Ann Polytechnic ECE

    BPD fwj16/06/20128

    0

    3

    0

    0

    11exp)(

    TTk

    qE

    T

    TTITI

    g

    SS (eq 4)

    In the spreadsheet some room was made so that columns F-G-H will describe the predictedcurrents at the three different temperatures entered into cells F9, G9, and H9.

    The fitting constants for the diode saturation currentIs, ideality factorn, and the measurement

    temperature T0 are included in cells F4:F7 as shown.To define the voltages at which well compute the currents, enter the first two points in the series(starting value and the next value orincrement) and then drag downward to let Excelautomatically edit>fill>series in the rest of the cells as shown. The range of 0.00 to 0.75 Voltsshould be sufficient.

    Now we can enter the equation for the diode current in the appropriate boxes. There is a simpleway to do this in Excel such that we only need to enter the formula once.Start with the temperature-dependent saturation current.First click on the cell F10 and enter the formula from (eq 4) as shown in the spreadsheet below(formulas are always preceded by an = sign inside the cell).

    Note that the temperature is referenced as F$9; this tells Excel that no matter which cell thisformula ends up in when we drag it around, we always want to keep the 9th row as constant

    reference. Similarly, the measured diode saturation current at T0 is referenced as $F$5, which tellsExcel to keep both the column and row reference (as an absolute reference) position when theformula moves to another cell. Without the $ in front of a row or column reference, the reference

    will be interpreted as a relative position and changes according to the relative position of the cell inthe spreadsheet. The constant qEg/k is taken to be 13109.

    Constants found by trendline fitting dataat room temperature

    Temperature (in K) at which we computethe diode current in col F-H

    Enter the first two points anddrag down to fill the rest

  • 7/27/2019 Plots, Curve-Fitting, and Data Modeling using Microsoft Excel (How to Plot Data)

    9/11

    Ngee Ann Polytechnic ECE

    BPD fwj16/06/20129

    The equation for cell F11 is as shown:

    Now grab the corner of the box surrounding cell F11 and drag it down to F26, to fill (orpopulate) up to the last cell in that column; you should now see the following:

    Once the formula isentered you cangrab one corner ofthe box around cell

    F10 and drag it toH10 to fill in thesaturation currentfor the othertemperatures.

    Next we enter theequation for the fulldiode current from(eq 1) in cell F11 asshown below.

    Note that this timewe reference thevoltage as $E11,

    because we want thevoltage to changeas we drag theformula down, butwe dont want it tochange when wedrag it sideways.

  • 7/27/2019 Plots, Curve-Fitting, and Data Modeling using Microsoft Excel (How to Plot Data)

    10/11

    Ngee Ann Polytechnic ECE

    BPD fwj16/06/201210

    Now, each cell should compute the diode current for the voltage in the particular row, and for thetemperature at the top of the particular column that the cell appears in. If you then click in any ofthese boxes, you can see how the references to the voltage and temperature change as you movefrom cell to cell.

    2.2 Ploting Multiple Data Series

    To plot all three of these curves together we could use the same procedure as before and select therange of data to plot(cell E11 : H26) and then insert a

    new chart (orplot). However,doing it that way means wed haveto go through all of the formatting

    business again. A somewhateasier alternative is to copy and

    paste a previously formatted graph(like the one we made for ourmeasured data) and then justchange the references for the sourcedata relating to the plot.

    To do this, right click somewhereinside the area of the new chart andselect Source Data.

    1. Click here to add anew line to the plot

    2. Name the new line

    3. Click on thesesymbols to define thelocation of theX and Y values

    Saturation currents ateach temperature

    Last step: grab the corner ofbox around cell F11 anddrag down to F26. Drag toH26 to fill in all the cellswithin this column.

    Equation in cell F11for computing the I-Vcurve at 290K

  • 7/27/2019 Plots, Curve-Fitting, and Data Modeling using Microsoft Excel (How to Plot Data)

    11/11

    Ngee Ann Polytechnic ECE

    BPD fwj16/06/201211

    1. Click on the Series tab in the dialog box to add a new data series, then click the Addbutton. 2. after doing this, enter a new Name: Model at T=290K we can get the following as a3 step sequence:

    The next step is to define where the X-Y data for this new series is located. The easiest way is toclick on the little spreadsheet symbols as shown above, and then use the cursor to select theappropriate cells in the spreadsheet. Note that if you do it this way, you have to first delete the={1} entry in the Y-values: box, otherwise you will get an error message. Now do this for theother two data sets forModel at 300K and Model at 310K.

    3 Concluding RemarksBy now all of the required data should

    be on the spreadsheet for the plot and wejust need to do some (additional)formatting to polish it up.

    The plot shown is what can be done on alog scale:

    Note the use of different line styles sothat the chart will still look good andserve its purpose if and when the chart is

    printed in B/W. Note that Excel doesntby default make very intelligent choicesof colors and line styles and widths forthe plots.

    For good quality reports and presentations you need to choose bold, dark colors (good contrastand) thicker line widths than the Excel defaults, as was done here. Also note that the data pointmarker symbols (dark blue diamonds) appear on top of the orange-red curve to Model at 300K; tomake this happen you need to double click on one of the markers to launch the Format DataSeries dialog box, and then select the Series Order tab to define the order in which the plot linesare drawn.

    As a last note, most people do notrealize that Excel, like many of theMS Office products, includessimilar drawing features that

    appears in PowerPoint. To accessthe drawing tools you just selectView >Toolbars>Drawing.This allows you to add graphics orcomments to the plots very easily.

    For example, here the plot can bereformatted for a linear scale, thescales can be adjusted a bit, and aload line added by drawing in astraight line through the appropriate

    intercepts. Depending on the objective of the presentation, the use of Cut & Pasted on schematicfor the load line into the Excel chart from a PowerPoint drawing will enhance the quality of the

    presentation.

    Diode V-I Characteristics

    0

    5

    10

    15

    20

    0 0.2 0.4 0.6 0.8 1

    Diode Voltage V, Volts

    CurrentI,

    mA

    Data

    Model at 290K

    Model at 300K

    Model at 310K

    Load Line

    Diode V-I Characterist ics

    0.00001

    0.0001

    0.001

    0.01

    0.1

    1

    10

    100

    1000

    0 0.2 0.4 0.6 0.8

    Diode Voltage V, Volts

    CurrentI,m

    A

    Data

    Model at 290K

    Model at 300K

    Model at 310K