Presentation is loading. Please wait.

Presentation is loading. Please wait.

©1999 BG Mobasseri 15/24/99 INTERPOLATION AND CURVE FITTING Etter: pp. 164-184 June 16, ‘99.

Similar presentations


Presentation on theme: "©1999 BG Mobasseri 15/24/99 INTERPOLATION AND CURVE FITTING Etter: pp. 164-184 June 16, ‘99."— Presentation transcript:

1 ©1999 BG Mobasseri 15/24/99 INTERPOLATION AND CURVE FITTING Etter: pp. 164-184 June 16, ‘99

2 ©1999 BG Mobasseri 25/24/99 DEFINING INTERPOLATION Interpolation can be used in at least two ways –Subsampling (taking every other sample or more) a dense signal and later filling it in –Generating new data where none was previously available

3 ©1999 BG Mobasseri 35/24/99 SUBSAMPLING Say you have a large sound file taking too long to transmit or too much space to store. One solution is to subsample it, send(store) the sparse data then fill in the gaps later

4 ©1999 BG Mobasseri 45/24/99 EXAMPLE Keep the circles and discard the rest. Later, fill in the gaps

5 ©1999 BG Mobasseri 55/24/99 VIDEO COMPRESSION Video captured at 30 frames/sec. contains a lot of redundancies Keep only a fraction of the frames and interpolate between them later This is implemented in the MPEG standard

6 ©1999 BG Mobasseri 65/24/99 INTERPOLATION METHODS There are 3 major interpolation techniques –linear –cubic-spline( a 3rd degree polynomial) –polynomial fitting (polynomial of arbitrary order)

7 ©1999 BG Mobasseri 75/24/99 LINEAR INTERPOLATION Simplest of its kind, works on the following principle error interpolation

8 ©1999 BG Mobasseri 85/24/99 HOW DOES MATLAB DO IT? The main MATLAB’s routine for 1-D interpolation is interp1 with the following syntax –y i =interp1(x,y,x i,’method’) (x,y) are the original coarse data. x i ’s are the new finer positions to be interpolated, y i is the answer. See next

9 ©1999 BG Mobasseri 95/24/99 Illustrating (x i,y i ) x x i y yiyi

10 ©1999 BG Mobasseri 105/24/99 WORKING WITH interp1 Want to interpolate a sinc function with samples originally located at [-4:1:4] -4-3-201234 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1

11 ©1999 BG Mobasseri 115/24/99 Linear interpolation:Try it! x=[-4:.1:4];%x-values y=[0 0 0 0 1 0 0 0 0];%coarsely sampled data at x=-4,-3,... xfiner=[-4:0.5:4];%inerpolate at -4,-3.5,-3,... yfiner=interp1(x,y,xfiner,’linear’);%interpolate at new grid positions plot(x,y,xfiner,yfiner,'ro',xfiner,yfiner,'r-');

12 ©1999 BG Mobasseri 125/24/99 LINEAR INTERPOLATION OF SINC Interpolated at 0.5 intervals -4-3-201234 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1

13 ©1999 BG Mobasseri 135/24/99 DEFINING CUBIC-SPLINE When data is interpolated by cubic spline, it means we pass a 3rd order polynomial through each pair of points Since a polynomial is passed through a pair of points We can interpolate at arbitrary fine positions Between the two

14 ©1999 BG Mobasseri 145/24/99 Example Let’s say we have passed y=x 2 between (1,1) and (2,2). We can read any intermediate y values by simply plugging in an x value 1 2 1 4

15 ©1999 BG Mobasseri 155/24/99 CUBIC-SPLINE A more accurate interpolation can be achieved by passing 3rd degree polynomials through coarse data 00.511.522.533.544.55 5 6 7 8 9 10

16 ©1999 BG Mobasseri 165/24/99 INTERPOLATING AN AM SIGNAL An amplitude modulated signal is

17 ©1999 BG Mobasseri 175/24/99 Try it! Evaluate the AM signal with f m =2,f c =3 in the range 0<t<1 in increments of.01 Subsample it 20:1. Using the kept data points, perform linear and cubic-spline interpolation Compare your code with mine, next page

18 ©1999 BG Mobasseri 185/24/99 My code

19 ©1999 BG Mobasseri 195/24/99 Output graph original interpolated

20 ©1999 BG Mobasseri 205/24/99 LINEAR VS. CUBIC spline gets closer to the actual curve 00.20.40.60.81 -2 -1.5 -0.5 0 0.5 1 1.5 2 CUBIC-SPLINE vs. LINEAR INTERPOLATION linear original spline

21 ©1999 BG Mobasseri 215/24/99 FINER INTERPOLATION Smoother interpolation via spline 00.20.40.60.81 -2 -1.5 -0.5 0 0.5 1 1.5 2 FINER CUBIC-SPLINT INTERP.

22 ©1999 BG Mobasseri 225/24/99 DIRECT READ-OFF interp1(x,y,2.5,’spline’) returns spline interpolated value of 6.1 at 2.5 x=0:5; y=[5 8 6 7 9 8]; xi=0:.1:5; ylin=interp1(x,y,xi); ys=interp1(x,y,xi,'spline'); point=interp1(x,y,2.5,'spline')

23 ©1999 BG Mobasseri 235/24/99 LEAST SQUARES CURVE FITTING Linear and cubic spline interpolations fit curves constrained to go through the data points A curve fitted using least squares may not pass through any data point but it will be “close” to all of them in the “least squares” sense

24 ©1999 BG Mobasseri 245/24/99 LEAST SQUARES SENSE data Fit a line that on average is closets to all data points

25 ©1999 BG Mobasseri 255/24/99 LEAST SQUARES OBJECTIVE Find a function,e.g. a polynomial of whatever order, that minimizes the mean square error MATLAB does this through polynomial regression

26 ©1999 BG Mobasseri 265/24/99 DIFFERENCES WITH CUBIC SPLINE Both are polynomials but cubic splines are 3rd order polynomials. The big difference is that cubic spline fits separate 3rd degree polynomials per segment Least squares fits a single polynomial through all data points

27 ©1999 BG Mobasseri 275/24/99 DEFINING A POLYNOMIAL Etter: pp. 78-86 An Nth degree polynomial is specified by N+1 coefficients If there are N+1 data points, an Nth degree polynomial will pass through all of them

28 ©1999 BG Mobasseri 285/24/99 Example of polynomials It takes a first degree polynomial, a straight line, to connect two points It takes a 2nd degree polynomial to connect 3 points

29 ©1999 BG Mobasseri 295/24/99 polyfit FUNCTION To fit an nth degree polynomial to (x,y) data use –p=polyfit(x,y,n) polyfit returns a vector p of n+1 coefficients in decreasing powers of x. So if then p=[a o,a 1,a 2,a 3,…,a N ]

30 ©1999 BG Mobasseri 305/24/99 Evaluating and Plotting the Fitted Polynomial:polyval Once polynomial is specified through the vector p, it can be evaluated directly using –y=polyval(p,x) coarse x values vector of polynomial coefficients

31 ©1999 BG Mobasseri 315/24/99 Example using polyfit Let x=[0 1 2 3 4 5] and y= [5 8 6 7 9 8] be the coarse data points. This is how to fit a 4th order polynomial p=polyfit(x,y,4);%p is the coeff. vector now let’s evaluate the polynomial at finer positions given by xfine=[0:0.1:5] yfine=polyval(p,xfine);%plot yfine to see

32 ©1999 BG Mobasseri 325/24/99 RESULT data Fitted polynomial does not pass through any data point

33 ©1999 BG Mobasseri 335/24/99 Comparing Interpolations In the following slides we start with the following data points –x=[0 1 2 3 4 5]; –y=[5 8 6 7 9 8]; We will then interpolate along x in increments of 0.1 using progressively larger order polynomials

34 ©1999 BG Mobasseri 345/24/99 APPLYING polyfit Let’s fit a first degree y=mx+h to data. We’ll get m=0.54,h=5.8 00.511.522.533.544.55 5 6 7 8 9 10

35 ©1999 BG Mobasseri 355/24/99 3RD DEGREE POLYNOMIAL Coefficients are [0.037 -0.349 1.407 5.460] 00.511.522.533.544.55 5 6 7 8 9 10

36 ©1999 BG Mobasseri 365/24/99 4th DEGREE POLYNOMIAL coeff= [-0.2500 2.5370 -8.0278 8.5503 5.0317] 00.511.522.533.544.55 5 5.5 6 6.5 7 7.5 8 8.5 9 9.5 10

37 ©1999 BG Mobasseri 375/24/99 5th DEGREE POLYNOMIAL Expect the polynomial to pass through all the points (why?) 00.511.522.533.544.55 5 5.5 6 6.5 7 7.5 8 8.5 9 9.5

38 ©1999 BG Mobasseri 385/24/99 Homework Take the data on page 33 and interpolate it in increments of 0.1 using –Linear interpolation –Cubic spline –Polynomial of 3rd degree –Superimpose your plots and show how they compare


Download ppt "©1999 BG Mobasseri 15/24/99 INTERPOLATION AND CURVE FITTING Etter: pp. 164-184 June 16, ‘99."

Similar presentations


Ads by Google