fitting procedure labview fitting instruments class of “experimental methods of physics” mikhail...

28
FITTING PROCEDURE FITTING PROCEDURE LABVIEW FITTING LABVIEW FITTING INSTRUMENTS INSTRUMENTS class of class of Experimental Methods of Experimental Methods of Physics” Physics” Mikhail Yurov Mikhail Yurov Kyungpook National Kyungpook National University University March 28 March 28 th th , 2005 , 2005

Upload: abigayle-gibson

Post on 16-Jan-2016

223 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005

FITTING PROCEDUREFITTING PROCEDURELABVIEW FITTING LABVIEW FITTING

INSTRUMENTSINSTRUMENTSclass ofclass of

““Experimental Methods of Experimental Methods of Physics”Physics”

Mikhail YurovMikhail YurovKyungpook National Kyungpook National

UniversityUniversityMarch 28March 28thth, 2005, 2005

Page 2: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005

Contents

1. Curve fitting. Introduction The Least Squares Method Linear Fits. Straight Line Linear Fits when both Variables have Errors Nonlinear Fits

2. LabView. Introduction Programming with LabView LabView fitting instruments Example of fitting program

Page 3: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005

Curve fitting. Introduction

The functional relation between two ore more variables describing a physical process, y=f(x1,x2,…), is investigated by measuring the value of y for various of x1,x2,… . It is then desired to find parameters of a theoretical curve which best describe these points.

For example, to determine the lifetime of a certain radioactive source, measurements of the count rates, N1,N2,…,Nn, at various times, t1,t2,…,tn, could be made and the data fitted to the expression

N(t)=N0exp(-t/τ)

The method most useful for this is the method of least squares.

Page 4: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005

The Least Squares Method

Suppose that measurements at n points, xi, are made of the variable yi with an error σi (i=1,2,…,n), and that is desired to fit a function f(x;a1,a2,…,am) to these data where a1, a2 ,…, am are unknown parameters to be determined.

The method of least squares states that the best values of aj are those for which the sum

2

1

);(

n

i i

jii axfyS

is a minimum.

This is just the sum of the squared deviations of the data points from the curve f(xi) weighted by the respective errors on yi.

Page 5: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005

To find the values of aj, one must solve the system of equations

Depending on the function f(x) this equation may or may not yield on analytical solution. In general, numerical methods requiring a computer must be used to minimize S.

Assuming we have the best values for aj, it is necessary to estimate the errors on the parameters. We form the so-called covariance or error matrixcovariance or error matrix, Vij,

0

jaS

jiij aa

SV

21

~ 2

1

Page 6: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005

Linear Fits. Straight LineConsider the example of fitting a straight line to a set of data points. Thus the function is y=ax+b. According to our formula we have to minimize

2

1

n

i i

ii baxyS

Where the summation extends over all the n data points. After differentiating we obtain

02

2

i

iii xbaxy

a

S

022

i

ii baxy

b

S

xxx

yxxya

**1

**12

xxx

xxyyxb

**1

**2

2

This leads to the solution

where 2

1

i

if

nf

Page 7: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005

The errors on a and b. Forming the inverse error matrix , we then have

2221

12111

AA

AAV

ba

SAA

b

SA

a

SA

2

21122

2

222

2

11 2

1

2

1 ,

2

1where

Inverting the matrix, we find

2122211

222

AAA

Aa

2122211

112

AAA

Aa

2122211

122

AAA

Aa

2212

12112122211

1

AA

AA

AAAV

To complete the process, it is necessary to also have an idea of the quality of the fit.

Do the data, in fact, correspond to the function f(x) we have assumed? A quick and easy test is to form the reduced chi-squarereduced chi-square

mnS

,

2

Which should be close to 1 for a good fit

Page 8: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005

Linear Fits when both Variables have Errors

In previous, the independent variables xi were completely free of errors.

In cases where the errors on both variables are comparable ignoring the errors on x leads to incorrect parameters and an underestimation of their errors.

For these problems the effective variance method may be used.

2i

22

22xyi dx

df

The method consists of simply replacing the variance

Where σx and σy are the errors on x and y respectively. Since the derivative is normally a function of the parameters aj, S is nonlinear and numerical methods must be used to minimize S

Page 9: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005

Nonlinear Fits

Nonlinear fits generally require a numerical procedure for minimizing S.

Number of methods have been developed for this purpose. However, no one method can be said to be applicable to all functions.

Numerical minimization methods are generally iterative in nature – repeated calculations are made while varying the parameters in some way, until the desired minimum is reached.

The criteria for selecting a method are speed and stability against divergence.

The methods can be classified into two board categories: grid searches and gradient methods.

Page 10: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005

The most elementary procedure for grid methods is to form a grid of equally spaced points in the variables of interest and evaluate the function at each of these points.

The size of the grid step, Δx, depends on accuracy desired.

The elementary grid method is intrinsically stable but it is quite inefficient and time consuming.

Gradient methods are techniques which make use of the derivatives of the function to be minimized. One obvious use of the derivatives is to serve as guides pointing in the direction of decreasing F.

The simplex method for function minimization

Page 11: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005

LabView. Introduction

LabVIEW is a graphical programming language that uses icons instead of lines of text to create applications. In contrast to text-based programming languages, where instructions determine program execution, LabVIEW uses dataflow programming, where the flow of data determines execution.

Page 12: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005

LabVIEW programs are called virtual instruments, or VIs, because their appearance and operation imitate physical instruments, such as oscilloscopes and multimeters. LabVIEW contains a comprehensive set of tools for acquiring, analyzing, displaying, and storing data.

Page 13: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005

In LabVIEW, it is possible to build a user interface, or front panel, with controls and indicators. Controls are knobs, push buttons, dials, and other input devices. Indicators are graphs, LEDs, and other displays.

After building the user interface, it is possible to add code using VIs and structures to control the front panel objects. The block diagram contains this code.

Page 14: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005

Programming with LabView

The terminals represent the data type of the control or indicator.

Terminals are entry and exit ports that exchange information between the front panel and block diagram.

Data entered into the front panel controls enter the block diagram through the control terminals. The data then enter the Add and Subtract functions. When the Add and Subtract functions complete their internal calculations, they produce new data values. The data flow to the indicator terminals, where they exit the block diagram, reenter the front panel, and appear in front panel indicators

Page 15: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005

Nodes are objects on the block diagram that have inputs and/or outputs and perform operations when a VI runs. They are analogous to statements, operators, functions, and subroutines in text-based programming languages.

Data are transfer among block diagram objects through wires. Each wire has a single data source, Wires are different colors, styles, and thicknesses, depending on their data types.

Structures are graphical representations of the loops and case statements of text-based programming languages. Structures are use on the block diagram to repeat blocks of code and to execute code conditionally.

Page 16: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005
Page 17: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005

LabVIEW includes VIs and functions to help in building specific applications, such as data acquisition VIs and functions, VIs that access other VIs, and VIs that communicate with other applications.

Page 18: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005

LabView fitting instruments

Curve Fitting is only a part of a big branch of Mathematics in LabView.

Mathematics covers

• Curve Fitting

• Probability and Statistics

• Linear Algebra

• Optimization

• Polynomials

The technique of curve fitting analysis extracts a set of curve parameters or coefficients from a data set to obtain a functional description of the data set. The Curve Fitting VIs automatically set up and solve the Jacobian system and return the set of coefficients that best describes the data set.

Page 19: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005

Figure shows the block diagram of a VI that uses the Linear Fit VI to fit a line to a set of data points.

Page 20: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005

The practical applications of curve fitting include the following applications:

•Removing measurement noise

•Filling in missing data points, such as when one or more measurements are missing or improperly recorded

•Interpolating, which is estimating data between data points, such as if the time between measurements is not small enough

•Extrapolating, which is estimating data beyond data points, such as looking for data values before or after a measurement

•Differentiating digital data, such as finding the derivative of the data points by modeling the discrete data with a polynomial and differentiating the resulting polynomial equation

Page 21: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005

LabView contains a built-in Curve Fitting VIs which make it easier to create fitting program.

For the Curve Fitting VIs, the input sequences Y and X represent the data set y(x).

Some Curve Fitting VIs return only the coefficients for the curve that best describe the input data while other Curve Fitting VIs return the fitted curve.

Using the VIs that return only coefficients allows to further manipulate

the data. The VIs that return the fitted curve also return the coefficients and

the mean squared error (MSE).

Page 22: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005

1.Linear Fit.VI

2. Linear Fit coefficients.VI

3.Exponential.VI

4.Exponential Fit coefficients.VI

5.General Polynomial Fit.VI

6.General LS Linear Fit.VI

7.Non-linear Lev-Mar Fit.VI

8.Levenberg Marquardt.VI

9.Polynomial Interpolation.VI

10.Rational Interpolation.VI

11.Spline Interpolant.VI

12.Spline Interpolation.VI

13.Curve Fitting.VI

LabView Instruments palette for FittingLabView Instruments palette for Fitting

Page 23: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005

Number 13.Curve Fitting.VI is the most general case of fitting Vi

Page 24: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005

Example of fitting programThis Vi’s purpose is to measure the 3He polarization signal during the NMR sweep.

Up to now this VI is uder development

Page 25: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005

The Block Diagram of Extract Polarization VI

Page 26: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005

Examples of test results performed by VI for different parameters

Page 27: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005
Page 28: FITTING PROCEDURE LABVIEW FITTING INSTRUMENTS class of “Experimental Methods of Physics” Mikhail Yurov Kyungpook National University March 28 th, 2005

References

• L.Lyons, “Statistics for nuclear and particle physics”, Cambridge (1985)

• William R.Leo “Techniques for Nuclear and Particle Physics Experiments”, Springer-Verlag Berlin Heidelberg (1987)

• LabView User Manual (www.ni.com)