Example: stock market

ECE 1010 ECE Problem Solving I Interpolation and 6 Curve ...

ECE 1010 ECE Problem Solving IChapter 6: Overview6 1 Interpolation and Curve FittingOverviewGiven a set of data that results from an experiment (simulationbased or otherwise), or perhaps taken from a real-life physicalscenario, we assume there is some function that passesthrough the data points and perfectly represents the quantity ofinterest at all non- data points. With Interpolation we seek a func-tion that allows us to approximate such that functional val-ues between the original data set values may be determined(estimated). The interpolating function typically passes throughthe 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 theoriginal 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 shownin the following figure The data set is a set of 10 random numbers generated using10*rand(1,10) Note that the spline Interpolation passes through the datapoints while the Curve fit does notfx()fx()6 ECE 1010 ECE Problem Solving IChapter 6: Interpolation6 2 A higher degree polynomial would presumably give a bet-ter fitInterpolation The simplest type of int

ECE 1010 ECE Problem Solving I Chapter 6: Overview 6–1 Interpolation and Curve Fitting Overview Given a set of data that results from an experiment (simulation

Tags:

  Data, Problem, Fitting, Solving, Of data, Interpolation, Ece problem solving i interpolation and

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of ECE 1010 ECE Problem Solving I Interpolation and 6 Curve ...

1 ECE 1010 ECE Problem Solving IChapter 6: Overview6 1 Interpolation and Curve FittingOverviewGiven a set of data that results from an experiment (simulationbased or otherwise), or perhaps taken from a real-life physicalscenario, we assume there is some function that passesthrough the data points and perfectly represents the quantity ofinterest at all non- data points. With Interpolation we seek a func-tion that allows us to approximate such that functional val-ues between the original data set values may be determined(estimated). The interpolating function typically passes throughthe 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 theoriginal 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 shownin the following figure The data set is a set of 10 random numbers generated using10*rand(1,10) Note that the spline Interpolation passes through the datapoints while the Curve fit does notfx()fx()6 ECE 1010 ECE Problem Solving IChapter 6: Interpolation6 2 A higher degree polynomial would presumably give a bet-ter fitInterpolation 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 firstdegree, , a straight line012345678910024681012 Interpolation and Curve fitting to Random NumbersxData Points Cubic Spline InterpolationLeast-Squares Poly Fit 5th DegreePolynomialECE 1010 ECE Problem Solving IChapter 6.

2 Interpolation6 3 A more exotic Interpolation scheme is to connect the datapoints using third degree or cubic polynomialsLinear Interpolation Given data points and , where We wish to estimate where using linear inter-polation The linear Interpolation function for functional valuesbetween a and c can be found using similar triangles or bysolving of system of two equations for two unknowns The slope intercept form for a line is( ) As boundary conditions we have that this line must passthrough the point pairs and fc()fa()ca>fb()bac,[] xyacfa()fc()LinearInterpolationFunctionb fb()y x +=yfx() x +==xac,[] ,afa(),()cfc(),()ECE 1010 ECE Problem Solving IChapter 6: Interpolation6 4 Thus we can write( )( ) Now we solve for and by using ( ) to solve for andsubstituting this expression into ( )soor( ) With known we now solve for ( ) In summary, the linear Interpolation formula is to obtain for ( ) Note: With some algebraic manipulation we can get the equa-tion in the text which isfa() a +=fc() c += fc() c =fa() afc() c += fc()fa() ca -------------------------= fc()fc()fa() ca -------------------------c =fb()abc fb()fc()fa() ca -------------------------bfc()fc()fa() ca -------------------------c +=fb()fa()ba ca ------------fc()fa() []+=ECE 1010 ECE Problem Solving IChapter 6.

3 Interpolation6 5 Given a data set, we can perform linear Interpolation betweeneach pair of data points to any desired resolution using theMATLAB function interp1 Understanding how linear Interpolation works is still veryimportant if you are writing a custom algorithm or want tocheck the results of a MATLAB calculation The functiony_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 omittedinterp1 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 pointscan 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 theoriginal y vector values at the corresponding x valuesExample: Suppose we have the following velocity versus timedata (a car accelerating from a rest position)Table : Car velocity dataTime, sVelocity, 1010 ECE Problem Solving IChapter 6: Interpolation6 6 Use MATLAB s interp1 function to estimate vehicle veloci-ties on the interval [0,5] seconds with resolution of sec-onds x = 0:5; y = [0 10 25 36 52 59]; x_new = 0.

4 01:5; y_new = interp1(x,y,x_new,'linear'); plot(x,y,'d') holdCurrent 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 , thatis the vehicle velocity at seconds Using ( ) we enter the data point values for one and twoseconds225336452559 Table : Car velocity data (Continued)Time, sVelocity, ()ECE 1010 ECE Problem Solving IChapter 6: Interpolation6 7 Does MATLAB agree? y_new = interp1(x,y, ,'linear')y_new = %%% YES! If the y vector is composed of columns of data , all corre-sponding to a single x vector of data , the interp1 functionwill output a row vector for each value in the x_new ()2510 21 21 ------------------2 + versus TimeMiles per HourTime, secondsData Points Linear InterpolationECE 1010 ECE Problem Solving IChapter 6.

5 Interpolation6 8 Cubic-Spline Interpolation As we can see from the previous example, linear interpola-tion produces a rather jagged result if the data points are notclosely spaced and don t lie in a straight line An improved Interpolation procedure is to replace the straightline connecting the data points with a third degree polyno-mial The third degree polynomial is of the form As with linear Interpolation a new set of coefficients mustbe 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 asmooth transition as we pass from one point and the next This smooth behavior is accomplished by computing thepolynomial coefficients for each interval using more thanjust the adjacent data points (recall linear interpolationuses just the interval end points to determine and ) The MATLAB function interp1 implements cubic splineinterpolation by simply changing the fourth argument from linear to spline Example: Repeat the vehicle velocity example, except now usecubic spline interpolationyfx() 3x3 +2x2 1x ++== ECE 1010 ECE Problem Solving IChapter 6: Interpolation6 9 x = 0:5; y = [0 10 25 36 52 59]; x_new = 0.

6 01:5; y_new = interp1(x,y,x_new,'spline'); plot(x,y,'d') legend off holdCurrent 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 ') versus TimeMiles per HourTime, secondsData Points Cubic Spline InterpolationECE 1010 ECE Problem Solving IChapter 6: Interpolation6 10 The interp1 function provides several other interpolationmodes 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: 'nearest' - nearest neighbor Interpolation 'linear' - linear Interpolation 'spline' - cubic spline Interpolation 'cubic' - cubic Interpolation All the Interpolation methods require that X be monotonic. Variable spacing is handled by mapping the given values in X,Y, and XI to an equally spaced domain before interpolating.

7 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 allowingfor an arbitrary resolution to be specified on the x-axis It is perfectly ok to interchange the roles of x and y toallow x-axis values to be interpolated by allowing for anarbitrary resolution to be specified on the y-axis (part 3) In part 2 of Practice p. 170, also hand calculate the linearinterpolation of the temperature at secondsECE 1010 ECE Problem Solving IChapter 6: Problem Solving Applied: Rise-Time and Fall-Time Determination6 11 Problem Solving Applied: Rise-Time and Fall-Time DeterminationIn the design of electronic devices/circuits/systems that processpulse type signals, we are often interested in a performance char-acterization known as rise- and Fall-Time Definitions For an amplifier the rise-time is typically defined as the timerequired for the output of the amplifier to change from a lowoutput level (say an at rest value of zero volts) to some highoutput level, in response to a step input signal The concept of rise-time also applies to digital logic gatesand flip-flops when one defines the switching time for logicalzero-one or one-zero transitions Traditionally the rise-time, , is the time it takes the outputto transition from 10% of the final value to 90% of the finalvalue The fall-time, , is the 10% to 90% transition time going inthe opposite direction.

8 In general they are different r fSystemUnderTestPulse Input10%90% f rOutputECE 1010 ECE Problem Solving IChapter 6: Problem Solving Applied: Rise-Time and Fall-Time Determination6 12 Using Interpolation to find and Interpolation can help us solve for the rise-time and fall-timeif the resolution of the experimental data is limited A system model is created in MATLAB Simulink r Response to a Pulse InputTime - secondsUse the firstfive data pointsto determine therise-timeUse thesefive data pointsto determine thefall-timeECE 1010 ECE Problem Solving IChapter 6: Problem Solving Applied: Rise-Time and Fall-Time Determination6 13 The data points are stored in vectors tout and simout [tout, simout]ans = 0 0 %% % % Use these points for rise-time % %% %% % % Use these points for fall-time % %% To obtain the rise-time and fall-time more precisely we willinterpolate on the time axis (x and y axis roles reversed) We have to be very careful to make sure that the y-axisinput data is strictly increasing or strictly decreasing on theinterval of interestECE 1010 ECE Problem Solving IChapter 6: Problem Solving Applied: Rise-Time and Fall-Time Determination6 14 t2 = interp1(simout(1:5),tout(1:5), ,'spline')t2 = t1 = interp1(simout(1:5),tout(1.))

9 5), ,'spline')t1 = tr = t2 - t1tr = %% Rise-time in seconds t2 = interp1(simout(11:15),tout(11:15), ,'spline')t2 = t1 = interp1(simout(11:15),tout(11:15), ,'spline')t1 = tr = t2 - t1tr = %% Fall-time in seconds We could have automated the above sequence of commandsinto an m-fileECE 1010 ECE Problem Solving IChapter 6: Problem Solving Applied: Robot Arm Manipulators6 15 Problem Solving Applied: Robot Arm Manip-ulatorsA control system application involving Interpolation is in settingup a safe trajectory for a robot arm to move through in threedimensions. To simplify the Problem , here we only considermotion in a plane (two dimensions). The robot arm must passthrough a specified set of points (like data points in an interpola-tion Problem ). For the Problem of interest the robot arm starts at a homeposition; has various intermediate positions; has a locationwhere it must grasp an object; has a location where it mustrelease the object.

10 Returns to the home position, perhaps viaintermediate positions A data file which contains the required x-y coordinate datapoints, is saved with a third column of numbers which corre-sponds to the type of point it is, ,Table : Third column coding of robot arm 2D of Point0 Home position1 Intermediate positions2 Location of object to grasp3 Location to release objectECE 1010 ECE Problem Solving IChapter 6: Problem Solving Applied: Robot Arm Manipulators6 16 Problem StatementDesign a smooth Curve using cubic-spline Interpolation to guidethe robot manipulator through a complete cycle of leaving thehome location, grasping an object, moving the object to a releaselocation, and returning to the home DescriptionHand CalculationConsider the data set shown : Sample manipulator arm path nodesxyCodeInterpretation000 Home position241 Intermediate position641 Intermediate position762 Grasp object1271 Intermediate position1513 Release CurveRobotTrajectoryECE 1010 ECE Problem Solving IChapter 6: Problem Solving Applied: Robot Arm Manipulators6 17 Load the points into MATLAB to parse them and then plotthe points (connect the dots) load ; x = m0_points(:,1); y = m0_points(:,2); code = m0_points(:,3).


Related search queries