11 views

Uploaded by engrode

curve

curve

© All Rights Reserved

- Spatial Analysis Techlectures Fall06
- Computing Applications in Mechanical Systems (MATLAB Simulink)
- Double Interpolation
- Study Material for Maths
- Data Fitting
- Radar Data - 2012 Lakshmanan
- Extension-Of-Lagrange-Interpolation.pdf
- AOSIM.pdf
- 1.2 (1)
- graphs from lab
- Algebra 2 Pacing Guide 2010
- Carlson 2011 User s Manual Volume 3-Transfer Ro-23jan-69aa81
- mathsmateglossary-100218004417-phpapp01
- 2017-2018 algebra 1 calendar
- Mws Gen Inp Txt Direct
- Chap07 8up- Interpolation
- Tutorial 2 Numet
- 10th Presentation Eng Coal Mongolia 2012 Rev2 Damian
- Data Analysis and Graphing Jrw
- writing linear equations

You are on page 1of 25

Interpolation and 6

Curve Fitting

Overview

Given a set of data that results from an experiment (simulation

based or otherwise), or perhaps taken from a real-life physical

scenario, we assume there is some function f ( x ) that passes

through the data points and perfectly represents the quantity of

interest at all non-data points. With interpolation we seek a func-

tion that allows us to approximate f ( x ) such that functional val-

ues between the original data set values may be determined

(estimated). The interpolating function typically passes through

the original data set. With curve fitting we simply want a func-

tion that is a good fit (typically a best fit in some sense) to the

original data points. With curve fitting the approximating func-

tion does not have to pass through the original data set.

An example of interpolation using spline functions and least-

squares curve fitting using a fifth degree polynomial is shown

in the following figure

The data set is a set of 10 random numbers generated using

10*rand(1,10)

Note that the spline interpolation passes through the data

points while the curve fit does not

Chapter 6: Overview 61

ECE 1010 ECE Problem Solving I

ter fit

Interpolation and Curve Fitting to Random Numbers

12

Data Points

Cubic Spline Interpolation

10

Least-Squares Poly Fit

6

5th Degree

Polynomial

4

0

0 1 2 3 4 5 6 7 8 9 10

x

Interpolation

The simplest type of interpolation is linear interpolation,

which simply connects each data point with a straight line

The polynomial that links the data points together is of first

degree, e.g., a straight line

Chapter 6: Interpolation 62

ECE 1010 ECE Problem Solving I

points using third degree or cubic polynomials

Linear Interpolation

Given data points f ( c ) and f ( a ) , where c > a

We wish to estimate f ( b ) where b [ a, c ] using linear inter-

polation

y Linear

Interpolation

Function y = x +

f(c)

f(b)

f( a)

x

a b c

The linear interpolation function for functional values

between a and c can be found using similar triangles or by

solving of system of two equations for two unknowns

The slope intercept form for a line is

y = f ( x ) = x + , x [ a, c ] (6.1)

As boundary conditions we have that this line must pass

through the point pairs ( a, f ( a ) ) and ( c, f ( c ) )

Chapter 6: Interpolation 63

ECE 1010 ECE Problem Solving I

f ( a ) = a + (6.2)

f ( c ) = c + (6.3)

Now we solve for and by using (6.3) to solve for and

substituting this expression into (6.2)

= f ( c ) c

so

f ( a ) = a + f ( c ) c

or

( c ) f ( a -)

= f------------------------ (6.4)

ca

With known we now solve for

f( c) f( a)

= f ( c ) ------------------------- c (6.5)

ca

In summary, the linear interpolation formula is to obtain f ( b )

for a b c

f(c) f(a) f( c) f( a)

f ( b ) = ------------------------- b + f ( c ) ------------------------- c (6.6)

ca ca

tion in the text which is

ba

f ( b ) = f ( a ) + ------------ [ f ( c ) f ( a ) ]

ca

Chapter 6: Interpolation 64

ECE 1010 ECE Problem Solving I

each pair of data points to any desired resolution using the

MATLAB function interp1

Understanding how linear interpolation works is still very

important if you are writing a custom algorithm or want to

check the results of a MATLAB calculation

The function

y_new = interp1(x,y,x_new,linear);

returns a vector y_new of the same size as x_new

The vectors x and y contain the raw data

If the fourth function argument, linear, is omitted

interp1 defaults to linear interpolation

It is assumed that the x_new vector has the same mini-

mum and maximum values as x, but in x_new the points

can be spaced to any desired resolution

The vector y_new contains the linearly interpolated val-

ues corresponding to x_new, and of course will match the

original y vector values at the corresponding x values

Example: Suppose we have the following velocity versus time

data (a car accelerating from a rest position)

Table 6.1: Car velocity data

0 0

1 10

Chapter 6: Interpolation 65

ECE 1010 ECE Problem Solving I

2 25

3 36

4 52

5 59

Use MATLABs interp1 function to estimate vehicle veloci-

ties on the interval [0,5] seconds with resolution of 0.01 sec-

onds

x = 0:5;

y = [0 10 25 36 52 59];

x_new = 0:.01:5;

y_new = interp1(x,y,x_new,'linear');

plot(x,y,'d')

hold

Current plot held

plot(x_new,y_new)

title('Velocity versus Time','fontsize',18)

ylabel('Miles per Hour','fontsize',14)

xlabel('Time, seconds','fontsize',14)

legend('Data Points','Linear Interpolation')

To check the calculation suppose we wish to find f ( 1.5 ) , that

is the vehicle velocity at 1.5 seconds

Using (6.6) we enter the data point values for one and two

seconds

Chapter 6: Interpolation 66

ECE 1010 ECE Problem Solving I

25 10 25 10

f ( 1.5 ) = ------------------ 1.5 + 25 ------------------ 2 = 17.5

21 21

Does MATLAB agree?

y_new = interp1(x,y,1.5,'linear')

60

Data Points

Linear Interpolation

50

40

Miles per Hour

30

20

10

0

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

Time, seconds

sponding to a single x vector of data, the interp1 function

will output a row vector for each value in the x_new vector

Chapter 6: Interpolation 67

ECE 1010 ECE Problem Solving I

Cubic-Spline Interpolation

As we can see from the previous example, linear interpola-

tion produces a rather jagged result if the data points are not

closely spaced and dont lie in a straight line

An improved interpolation procedure is to replace the straight

line connecting the data points with a third degree polyno-

mial

The third degree polynomial is of the form

3 2

y = f ( x ) = 3 x + 2 x + 1 x +

As with linear interpolation a new set of coefficients must

be used for each interval between the available data points

This polynomial is known as a cubic spline function

It is very special since the coefficients are chosen to give a

smooth transition as we pass from one point and the next

This smooth behavior is accomplished by computing the

polynomial coefficients for each interval using more than

just the adjacent data points (recall linear interpolation

uses just the interval end points to determine and )

The MATLAB function interp1 implements cubic spline

interpolation by simply changing the fourth argument from

linear to spline

Example: Repeat the vehicle velocity example, except now use

cubic spline interpolation

Chapter 6: Interpolation 68

ECE 1010 ECE Problem Solving I

x = 0:5;

y = [0 10 25 36 52 59];

x_new = 0:.01:5;

y_new = interp1(x,y,x_new,'spline');

plot(x,y,'d')

legend off

hold

Current plot held

plot(x_new,y_new)

title('Velocity versus Time','fontsize',18)

ylabel('Miles per Hour','fontsize',14)

xlabel('Time, seconds','fontsize',14)

legend('Data Points','Cubic Spline Interpolation')

60

Data Points

Cubic Spline Interpolation

50

40

Miles per Hour

30

20

10

0

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

Time, seconds

Chapter 6: Interpolation 69

ECE 1010 ECE Problem Solving I

modes as well

help interp1 % A portion of the on-line help)

YI = INTERP1(X,Y,XI,'method') specifies alternate meth-

ods.

The default is linear interpolation. Available

methods are:

'linear' - linear interpolation

'spline' - cubic spline interpolation

'cubic' - cubic interpolation

monotonic. Variable spacing is handled by mapping the

given values in X,Y, and XI to an equally spaced domain

before interpolating. For faster interpolation when X is

equally spaced and monotonic, use the methods '*linear',

'*cubic', '*nearest', or '*spline'. Faster linear

interpolation when X is non-uniformly spaced see

INTERP1Q.

In the Practice! on p. 170 you explore another aspect of inter-

polation

Thus far we have interpolated y-axis values by allowing

for an arbitrary resolution to be specified on the x-axis

It is perfectly ok to interchange the roles of x and y to

allow x-axis values to be interpolated by allowing for an

arbitrary resolution to be specified on the y-axis (part 3)

In part 2 of Practice p. 170, also hand calculate the linear

interpolation of the temperature at 0.3 seconds

ECE 1010 ECE Problem Solving I

Fall-Time Determination

In the design of electronic devices/circuits/systems that process

pulse type signals, we are often interested in a performance char-

acterization known as rise-time/fall-time.

For an amplifier the rise-time is typically defined as the time

required for the output of the amplifier to change from a low

output level (say an at rest value of zero volts) to some high

output level, in response to a step input signal

The concept of rise-time also applies to digital logic gates

and flip-flops when one defines the switching time for logical

zero-one or one-zero transitions

Traditionally the rise-time, r , is the time it takes the output

to transition from 10% of the final value to 90% of the final

value

The fall-time, f , is the 10% to 90% transition time going in

the opposite direction; in general they are different

Output

Pulse Input

90%

System

Under

Test 10%

r f

ECE 1010 ECE Problem Solving I

Interpolation can help us solve for the rise-time and fall-time

if the resolution of the experimental data is limited

A system model is created in MATLAB Simulink

1.2

0.8

Use these

five data points

0.6 Use the first to determine the

five data points fall-time

0.4

to determine the

rise-time

0.2

-0.2

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2

Time - seconds

ECE 1010 ECE Problem Solving I

[tout, simout]

ans =

0 0 %%

0.1000 0.3000 %

0.2000 0.7340 % Use these points for rise-time

0.3000 1.0002 %

0.4000 1.0844 %%

0.5000 1.0701

0.6000 1.0316

0.7000 1.0041

0.8000 0.9934

0.9000 0.9932

1.0000 0.9964 %%

1.1000 0.6992 %

1.2000 0.2664 % Use these points for fall-time

1.3000 0.0004 %

1.4000 -0.0840 %%

1.5000 -0.0700

1.6000 -0.0317

1.7000 -0.0042

1.8000 0.0065

1.9000 0.0068

2.0000 0.0036

To obtain the rise-time and fall-time more precisely we will

interpolate on the time axis (x and y axis roles reversed)

We have to be very careful to make sure that the y-axis

input data is strictly increasing or strictly decreasing on the

interval of interest

ECE 1010 ECE Problem Solving I

t2 = interp1(simout(1:5),tout(1:5),0.9,'spline')

t2 = 0.2364

t1 = interp1(simout(1:5),tout(1:5),0.1,'spline')

t1 = 0.0351

tr = t2 - t1

t2 = interp1(simout(11:15),tout(11:15),0.1,'spline')

t2 = 1.2368

t1 = interp1(simout(11:15),tout(11:15),0.9,'spline')

t1 = 1.0343

tr = t2 - t1

We could have automated the above sequence of commands

into an m-file

ECE 1010 ECE Problem Solving I

ulators

A control system application involving interpolation is in setting

up a safe trajectory for a robot arm to move through in three

dimensions. To simplify the problem, here we only consider

motion in a plane (two dimensions). The robot arm must pass

through a specified set of points (like data points in an interpola-

tion problem).

For the problem of interest the robot arm starts at a home

position; has various intermediate positions; has a location

where it must grasp an object; has a location where it must

release the object; returns to the home position, perhaps via

intermediate positions

A data file which contains the required x-y coordinate data

points, is saved with a third column of numbers which corre-

sponds to the type of point it is, e.g.,

Table 6.2: Third column coding of robot arm 2D trajectory.

0 Home position

1 Intermediate positions

2 Location of object to grasp

3 Location to release object

ECE 1010 ECE Problem Solving I

Problem Statement

Design a smooth curve using cubic-spline interpolation to guide

the robot manipulator through a complete cycle of leaving the

home location, grasping an object, moving the object to a release

location, and returning to the home location.

Input/Output Description

MATLAB

Smooth Curve

Solution

points.dat Robot

Trajectory

Hand Calculation

Consider the data set shown below.

Table 6.3: Sample manipulator arm path nodes

x y Code Interpretation

0 0 0 Home position

2 4 1 Intermediate position

6 4 1 Intermediate position

7 6 2 Grasp object

12 7 1 Intermediate position

15 1 3 Release object

ECE 1010 ECE Problem Solving I

x y Code Interpretation

8 -1 1 Intermediate position

4 -2 1 Intermediate position

0 0 0 Home position

Load the points into MATLAB to parse them and then plot

the points (connect the dots)

load m0_points.dat;

x = m0_points(:,1);

y = m0_points(:,2);

code = m0_points(:,3);

plot(x,y,'s')

axis([-.5 16 -4 10])

grid

hold

Current plot held

plot(x,y)

axis([-.5 16 -2.5 10])

axis([-.5 16 -2.5 8])

title('Mission Path','fontsize',18)

ylabel('y','fontsize',14)

xlabel('x','fontsize',14)

ECE 1010 ECE Problem Solving I

Mission Path

8

Pat

7

h #2

6

Grasp

#1

5 Path

4

3

y

1 Release

0 Home

-1

#3

-2 Path

0 2 4 6 8 10 12 14 16

x

types

From home to grasp

From grasp to release

From release to home

Before writing the MATLAB code we need to calculate at

least one path by hand, that is manually parsing the data files

and loading the appropriate points into MATLABs

interp1 function

ECE 1010 ECE Problem Solving I

Path #1 runs from row one through row four in the data file

The interpolation step size on the x-axis will be chosen as one

tenth the minimum absolute change in x-coordinate over the

entire data set, i.e., min(abs(x(i+1)-x(i))) as i runs

from 1 to 9 1 ; for the hand calculation we can just observe

this value by scanning the sample data

The minimum x step is 1

t1 = 0:1/10:7; % Interpolated steps along the x-axis

s1 = interp1(x(1:4),y(1:4),t1,'spline');

hold

Current plot released

plot(x,y,'s')

axis([-.5 16 -2.5 8])

hold

Current plot held

plot(t1,s1)

grid

title('Mission Path with Spline #1 Completed',...

'fontsize',18)

ylabel('y','fontsize',14)

xlabel('x','fontsize',14)

ECE 1010 ECE Problem Solving I

8

4

Path #1

3

y

-1

-2

0 2 4 6 8 10 12 14 16

x

MATLAB Solution

Now we write a MATLAB script file that will automatically

parse the data file into the three distinct paths and compute the

corresponding cubic-splines.

For the complete program see the text p. 173

ECE 1010 ECE Problem Solving I

Given a set of data points a best fit to the data set may be a

straight line

A least-squares curve fit can be used to find a straight line

such that the squared distance from each data point to the line

is minimized

It could be that the line will not pass through any data

point

The curve that we fit to the data is not limited to straight lines

In general the curve we fit to the available data may be a

polynomial of any order, an exponential function, trigono-

metric function, etc.

Linear Regression

With linear regression a linear equation, y1 = mx + b , is

chosen that fits the data points such that the sum of the

squared error between the data points and the line is mini-

mized

The squared distance is computed with respect to the y-

axis

Given a set of data points

( x k, y k ), k = 1, , N

the mean squared error (mse) is defined as

ECE 1010 ECE Problem Solving I

N N

1 2 1 2

mse = ---- [ y k y1 k ] = ---- [ y k ( mx k + b ) ]

N N

k=1 k=1

b

Using calculus we compute the derivative of the mse with

respect to both m and b

Since the mse is nonnegative setting the derivative equal to

zero occurs at the minimum mse

The resulting m and b values give us the best straight line

(linear) fit to the data

The equations are rather complex, i.e.,

N N N

N xk yk

x k

y k

m opt k = 1 k = 1 k = 1

= --------------------------------------------------------------------------

N N 2

2

N xk

x k

k=1 k=1

and

N N

xk

1 1

b opt = ---- y k m opt ----

N N

k=1 k=1

dles the linear regression case as well as polynomial regres-

sion

ECE 1010 ECE Problem Solving I

Polynomial Regression

A logical extension to the linear regression curve fit is to use

a higher-order polynomial such as

N N1

y = f ( x ) = a0 x + a1 x + + aN 1 x + aN

A third degree or cubic polynomial fit, different from cubic

splines since here there is only one, is of the form

3 2

y = g ( x ) = a0 x + a1 x + a2 x + a3

Note: First degree polynomial regression is the same as

linear regression

The MATLAB function which performs polynomial regres-

sion is

a = polyfit(x,y,n);

where

a is vector of n+1 coefficients corresponding to decreas-

ing powers of x

x and y are the supplied data points

n is the polynomial degree

For simple linear regression we would use

a = polyfit(x,y,1);

To plot the resulting curve fit we can use the polyval

which was introduced in Chapter 3

ECE 1010 ECE Problem Solving I

Try polynomial regression of orders 1 (linear), 2, 5, and 10

x = 0:5;

y = [0 10 25 36 52 59];

x_ls = 0:0.01:5;

y1 = polyval(polyfit(x,y,1),x_ls);

subplot(221)

plot(x,y,'s')

hold

Current plot held

plot(x_ls,y1)

axis([0 5 0 60]); grid;

title('First-Degree (Linear) Fit','fontsize',16)

ylabel('mph','fontsize',14)

subplot(222)

y2 = polyval(polyfit(x,y,2),x_ls);

plot(x,y,'s')

hold

Current plot held

plot(x_ls,y2)

axis([0 5 0 60]); grid;

title('Second-Degree Fit','fontsize',16)

ylabel('mph','fontsize',14)

subplot(223)

y5 = polyval(polyfit(x,y,5),x_ls);

plot(x,y,'s')

hold

Current plot held

plot(x_ls,y5)

axis([0 5 0 60]); grid;

title('Fifth-Degree Fit','fontsize',16)

ylabel('mph','fontsize',14)

xlabel('Time-Seconds','fontsize',14)

ECE 1010 ECE Problem Solving I

subplot(224)

y10 = polyval(polyfit(x,y,10),x_ls);

plot(x,y,'s')

hold

Current plot held

plot(x_ls,y10)

axis([0 5 0 60]); grid;

title('Tenth-Degree Fit','fontsize',16)

ylabel('mph','fontsize',14)

xlabel('Time-Seconds','fontsize',14)

60 60

50 50

40 40

mph

mph

30 30

20 20

10 10

0 0

0 1 2 3 4 5 0 1 2 3 4 5

60 60

50 50

40 40

mph

mph

30 30

20 20

10 10

0 0

0 1 2 3 4 5 0 1 2 3 4 5

Time-Seconds Time-Seconds

- Spatial Analysis Techlectures Fall06Uploaded byJoshuaHorton
- Computing Applications in Mechanical Systems (MATLAB Simulink)Uploaded bylawlaw
- Double InterpolationUploaded byMatt Harris
- Study Material for MathsUploaded bymicrodotcdm
- Data FittingUploaded byjoesuhre
- Radar Data - 2012 LakshmananUploaded bycamilafuegos
- Extension-Of-Lagrange-Interpolation.pdfUploaded byIJSTR Research Publication
- AOSIM.pdfUploaded byjuddasironn
- 1.2 (1)Uploaded byJhana Kimberly S. Aquino
- graphs from labUploaded byMohammed Elsaadi
- Algebra 2 Pacing Guide 2010Uploaded bygaliotoa
- Carlson 2011 User s Manual Volume 3-Transfer Ro-23jan-69aa81Uploaded byIvan Marian
- mathsmateglossary-100218004417-phpapp01Uploaded byJun Yi Ho
- 2017-2018 algebra 1 calendarUploaded byapi-380737736
- Mws Gen Inp Txt DirectUploaded byHafeed Younis
- Chap07 8up- InterpolationUploaded byagcore
- Tutorial 2 NumetUploaded byAshwin M
- 10th Presentation Eng Coal Mongolia 2012 Rev2 DamianUploaded byREando
- Data Analysis and Graphing JrwUploaded bypranab
- writing linear equationsUploaded byapi-267265141
- fastUploaded bySandilya Kambampati
- domain skills dimension 3- unit and lesson planUploaded byapi-327111644
- week of november 3-7Uploaded byapi-246433429
- mth462 unit lesson 7Uploaded byapi-437363879
- Write_the_Equation_of_a_Line.pdfUploaded byVirgilio Velasco
- Mat 116 Entire CourseUploaded byAdam
- 8th grade ccssUploaded byapi-237059911
- Linear Law 2011Uploaded byzizan_zan_1
- 4Uploaded byapi-331338526
- Production Management FormulasUploaded byAnthony Royupa

- Introduction to Servo Motors & ArduinoUploaded bySherif Eltoukhi
- l03 BackgroundUploaded byDineshNewalkar
- Equations Lines PlanesUploaded byAhmadMoaaz
- copper.pdfUploaded byengrode
- NFI Arduino Labview 6 Months TrainingUploaded byvvipmembers
- Stylus ProbeUploaded byDeepak Sunil
- reverseUploaded byengrode
- arduinoGuideUploaded bySachin Bhat
- AMD30Uploaded byengrode
- fuzzyUploaded byengrode
- Arduino Uno GenUploaded bymanchopper
- 2_XBee.pdfUploaded byRadu Florin Tripon
- lec1Uploaded bypothirajkalyan
- fuzzy 2Uploaded byengrode
- 4 leUploaded byengrode
- Arduino_Servo_Motor_Control_Tutorial.pdfUploaded bypicatilio
- 10.1.1.45.4558.pdfUploaded byengrode
- robot 3Uploaded byengrode
- robot 2Uploaded byengrode
- robotUploaded byengrode
- mesureUploaded byengrode
- measurement 2Uploaded byengrode
- ch33surfaceroughness-141102131237-conversion-gate02 (1).pdfUploaded byengrode
- lectureUploaded byengrode
- robotUploaded byengrode
- fuzzy 3Uploaded byengrode
- L01 IntroductionUploaded byAnkit Balotia

- iMac G5 2005 Users ManualUploaded byfaiztheme
- gfdUploaded byKrishna G
- 1.O.C. & S.C. Tests on Single Phase TransformerUploaded bychandrakanth
- Designing of Cordic Processor in Verilog Using Xilinx Ise SimulatorUploaded byesatjournals
- Indoor Positioning of Workers and Monitoring Climatology in Mines Using FM with RSSIUploaded byEditor IJRITCC
- Well PumpsUploaded byJuan Camilo Tejada Orjuela
- CofC_3RW40_44_E143112_20050405_201509161244191429Uploaded byMarco Antonio Quispe Roque
- Silopilot FMM50Uploaded byandrewfth
- Snug 2014 PaperUploaded bysetu_mohta
- Galaxy Dx959 ModsUploaded byAdam
- TSO PITOTUploaded byElkin Cuevas
- SCC Configuration GuideUploaded byMv Irinel
- Practical Physics Handbook (REVISED)Uploaded byFathin Khairunnisa
- Behringer_UB2222FX-PRO.pdfUploaded bymtlcaqc97 mtlcaqc97
- HPE DL360 Gen10 QuickSpecs v8Uploaded byb1bster
- Distance Protection System in RailwayUploaded bypavan
- Modulation SummaryUploaded byKit Jason Monje
- Module Valeport MiniSVP GeotronixUploaded byGems
- FHPP Positioning Library Step7 EnUploaded byMartin Guzman
- CUK converter using LM2611.pdfUploaded byrijilpoothadi
- Spreader Training - EH5U & EH170UUploaded byDavid Adeola Ogunyemi
- F1618_APC_306-308Uploaded byMathi Alagan
- Earthing & Lightning Protection GuideUploaded bySofyan Shah
- s6e1a1_an710 00001 e 1v0 3 Phase Acim Scalar ControlUploaded byandrei.ciobanasu
- SE NISSAN SENTRA B16Uploaded byAlex Hernandez
- Regular Board Maharashtra XII Physics 20150706161107[2]Uploaded bySourabh
- A9D31610Uploaded byaminullahsharif
- FSD Specs 1Uploaded byAdamshafi Noorbhasha
- Siemens Dms UsaUploaded bynaveedfnd
- l0 Q&A Main-importantUploaded bycddewan