9-1 �@�������k

©Ò¿×¡u¤@ºû¤º´¡¡v¡]1-D Interpolation¡^¡A´N¬O®Ú¾Ú¤@²Õ¤wª¾ªº¸ê®ÆÂI¡]¥]§t¿é¤J¤Î¿é¥X¡A¨ä¤¤¿é¤J¬O¤@ºû¸ê®Æ¡A¿é¥X¤]¬O¤@ºû¸ê®Æ¡^¡A¨Ó«Ø¥ß¤@­Ó³sÄòªº¨ç¼Æ¡A¥H«K­pºâ¥ô·N¿é¤J¸ê®ÆÂI©Ò¹ïÀ³ªº¿é¥X­È¡C¤@ºû¤º´¡ªº¤èªk«Ü¦h¡AMATLAB ´£¨Ñ¤F¨âºØ°ò¥»¤èªk¡G

¥»¸`±N¹ï³o¨âºØ¤èªk¨Ó¶i¦æ»¡©ú¡C

MATLAB ³Ì±`¥Îªº¤@ºû¤º´¡«ü¥O¬O interp1¡A¨ä­ì²z¬O§Q¥Î¦h¶µ¦¡¨Ó¶i¦æ¤º´¡¹Bºâ¡Cinterp1 ªº¨Ï¥Î»yªk¬°

yi = interp1(x, y, xi, method)

¨ä¤¤¦V¶q x ¬O¸ê®ÆÂIªº x ®y¼Ð¡]¿é¤J­È¡^¡A¦V¶q y ¬O¸ê®ÆÂIªº y ®y¼Ð¡]¿é¥X­È¡^¡A¦V¶q xi ¬O¤º´¡ÂI¡]¿é¤J­È¡A¥¼ª¾¨ä¹ïÀ³¿é¥X­È¡^¡A¦r¦ê method «h«ü©w¨Ï¥Îªº¤º´¡¤èªk¡A¦@¦³¤»ºØ¡G

¦b¤U¦C½d¨Ò¤¤¡A§Ú­Ì¨Ï¥Î¤W­z¤èªk¤¤ªº«e¥|ºØ¨Ó¹ï¤@ºû¸ê®Æ¶i¦æ¤º´¡¡G

Example 1: 09-¤º´¡ªk/interp101.mx = 0:1:4*pi; y = sin(x).*exp(-x/5); xi = 0:0.1:4*pi; y1 = interp1(x, y, xi, 'nearest'); y2 = interp1(x, y, xi, 'linear'); y3 = interp1(x, y, xi, 'pchip'); y4 = interp1(x, y, xi, 'spline'); plot(x, y, 'o', xi, y1, xi, y2, xi, y3, xi, y4); legend('Original', 'Nearest', 'Linear', 'Pchip', 'Spline');

¥Ñ¤W¹Ï¥i¬Ý¥X¡ASpline ©M Cubic ©Ò²£¥Íªº¦±½u¸û¥­·Æ¡A¦ý¥¦­Ì©Ò»Ýªº­pºâ®É¶¡¤]¸û¤[¡C¥H¤W³o¥|ºØ¤º´¡ªkªº¤ñ¸ûªí¦p¤U¡G

  Nearest Linear Cubic Cubic Spline
°õ¦æ®É¶¡ 1¡]µu¡^ 2 3 4¡]ªø¡^
¦±½u¥­·Æ«× 1¡]®t¡^ 2 3 4¡]¦n¡^
°O¾ÐÅé¨Ï¥Î¶q 1¡]¤Ö¡^ 2 4¡]¦h¡^ 3

¦b¨Ï¥Î interp1 ®É¡A¦V¶q x ¥²¶·¬OÄY®æ»¼¼W©Î»¼´î¡A¦ý¤¸¯À¤§¶¡¤£¥²¬Oµ¥¶¡¹j¡C¦¹¥~¡Axi ªº½d³ò¤]¥²¶·¸¨¦b x ªº½d³ò¤§¤º¡A¤~¯à¶i¦æ¤º´¡ªº¹Bºâ¡C

Hint
¦pªG xi ªº½d³ò¦b x ªº½d³ò¤§¥~¡A¨º»ò§Ú­Ì¥i¥H¨Ï¥Î yi = interp1(x, y, xi, method, ¡¥extrap¡¦) ªº¤è¦¡¨Ó¶i¦æ¥~´¡¡]Extrapolation¡^¡A¥H¨D±o¦b½d³ò¥~ªº xi ¤¸¯À©Ò¹ïÀ³ªº yi ­È¡C

¦b¤W­z½d¨Òªº¹Ï§Î¡A¥i¯à¤£®e©ö¬Ý¥X¨C¤@ºØ¤èªkªº®ÄªG¡Aµ§ªÌ¯S§O¥t¥~¼g¤F¤@­Óµ{¦¡¡A¥i¥HÅý¨Ï¥ÎªÌ©ì©ñ¨ú¼ËÂI¡A¤º´¡¦±½u´N·|¸òµÛ§ïÅÜ¡AÀɮצWºÙ¬O interpAnim01.m¡A°õ¦æ«áªº¹Ï§Î¦p¤U¡G

¨Ï¥ÎªÌ¥i¥H¦b¤W­z¹Ï§Îµøµ¡¤¤¡A©ì©ñ¨C¤@­Ó¨ú¼ËÂI¡A´N¥i¥H¥ß¨è¬Ý¨ì¤º´¡¦±½uªºÅܤơA¤]¦P®É¥i¥Hª¾¹D¦UºØ¤º´¡¤èªkªº¯S©Ê¡C

°£¤F interp1 ¤§¥~¡A¥t¤@­Ó¸û¤Ö¥Îªº MATLAB ªº«ü¥O interpft ¥i¶i¦æ°ò©ó FFT¡]Fast Fourier Transform¡A§Ö³t³Å¥ß¸­Âà´«¡^ªº¤º´¡ªk¡C¦¹¤èªk¥ý­pºâ¸ê®ÆÂIªº³Å¥ß¸­Âà´«¡A¦A¥Î§ó±K¶°ªº¤º´¡ÂI¨Ó¶i¦æ¤Ï³Å¥ß¸­Âà´«¡Cinterft ªº¨Ï¥Î»yªk¬°

y = interpft(yi, n)

¨ä¤¤¦V¶q yi ¬O¤@­Ó¸g¥Ñµ¥¶Z¨úÂIªº¨ç¼Æ­È¡An «h¬Oµ¥¶Z¨úÂIªº¤º´¡ÂI¼Æ¡C¨Ò¦p¡G

Example 2: 09-¤º´¡ªk/interpft01.mn = 11; % Number of the original data points factor = 4; % Increase the data by this factor x = linspace(0, 2*pi, n); y = sin(x).*exp(-x/5); xi = (0:factor*n-1)*(x(2)-x(1))/factor; yi = interpft(y, factor*n); plot(x, y, 'ro', xi, yi, '.-'); legend('Original', 'Curve by interpft');

Hint
¤@¯ë¦Ó¨¥¡A¤º´¡¦±½u¥²¶·³q¹L¨C¤@­Ó¤wª¾ªº¨ú¼ËÂI¡A¦Ó°jÂk¦±½u«h¤£»Ý­n³q¹L¨ú¼ËÂI¡C¦]¦¹¡A¤º´¡ªk¾A¥Î©óÂø°T«Ü¤Öªº¨ú¼Ë¸ê®Æ¡C¡]¦³Ãö¦±½uÀÀ¦X©Î°jÂk¤ÀªR¡A½Ð°Ñ¾\¥»®Ñ¡u¦±½uÀÀ¦X»P°jÂk¤ÀªR¡vªº¬ÛÃö³¹¸`¡C¡^

¦pªG§Ú­Ì­n®Ú¾Ú¥­­±¤Wªº¦³­­¸ê®ÆÂI¡A¨Ó´yøªì¤@­Óª«Å骺¥~«¬¡A¤]¥i¥H¨Ï¥Î¤@ºû¤º´¡¡A¦ý¬O¦¹®É¤º´¡¸ê®ÆÂI·|Åܦ¨¨â²Õ¡A¤À§O¬O

¦b¤U¦C½d¨Ò¤¤¡A§Ú­Ì¦@¦³¤C­Ó¸ê®ÆÂI¡A´²§G¦b¤G«×ªÅ¶¡¡A§Ú­Ì¥i¥H¨Ï¥Î interp1 ªº spline ¤èªk¡A¨Óµe¥X³sÄò¥­·Æªº¹Ï§Î¡A¦p¤U¡G

Example 3: 09-¤º´¡ªk/interp102.mx = [0 2 4 3 1 2 1]; y = [4 1 2 4 5 2 0]; index = 1:length(x); index2 = linspace(1, length(x), 101); x2 = interp1(index, x, index2, 'spline'); y2 = interp1(index, y, index2, 'spline'); plot(x, y, 'o', x2, y2, '-'); legend('Origianl data', 'Interpolated data');

¦b¤W­z½d¨Ò¤¤¡A­ì¦³ªº¸ê®Æ¥u¦³¤CÂI¡A¦ý¬O¨Ï¥Î¤@ºû¤º´¡¡A§Ú­Ì´N¥i¥H²£¥Í¥­·Æ³sÄòªº¹Ï§Î¡A³o¤]¬O¦b¹q¸£¹Ï¾Ç¡]Computer Graphics¡^³Ì±`¨£ªº°µªk¡A¤]´N¬O¥H¤Ö¼Æ±±¨îÂI¡]Control Points¡^¨Ó¥Nªí¤@­Óª«¥ó¡AµM«á¦A¨Ï¥Î¤º´¡¨Ó²£¥Í¾ã­Óª«¥óªº²Ó½o¹Ï§Î¡C

·íµM¡A¦pªG§Ú­Ì¿ï¥Î¤£¦Pªº¤èªk¡A±o¨ìªº¥­·Æ®ÄªG¤]·|¤£¦P¡A¤U¦C½d¨Ò¨Ï¥Î interp1 ªº¥|ºØ¤èªk¡A¨Ó¹ï¤W¤@­Ó½d¨Òªº¸ê®ÆÂI¶i¦æ¤º´¡¡A¦p¤U¡G

Example 4: 09-¤º´¡ªk/interp103.mx = [0 2 4 3 1 2 1]; y = [4 1 2 4 5 2 0]; index = 1:length(x); index2 = linspace(1, length(x), 101); x2 = interp1(index, x, index2, 'nearest'); y2 = interp1(index, y, index2, 'nearest'); x3 = interp1(index, x, index2, 'linear'); y3 = interp1(index, y, index2, 'linear'); x4 = interp1(index, x, index2, 'pchip'); y4 = interp1(index, y, index2, 'pchip'); x5 = interp1(index, x, index2, 'spline'); y5 = interp1(index, y, index2, 'spline'); plot(x, y, 'o', x2, y2, '-'); plot(x, y , 'o', x2 ,y2, x3 ,y3 ,x4 ,y4, x5, y5); legend('Original', 'Nearest', 'Linear', 'Pchip', 'Spline');

¦P¼Ë¦a¡A¦b¤W­z½d¨Òªº¹Ï§Î¡A¥i¯à¤£®e©ö¬Ý¥X¨C¤@ºØ¤èªkªº®ÄªG¡Aµ§ªÌ¯S§O¥t¥~¼g¤F¤@­Óµ{¦¡¡A¥i¥HÅý¨Ï¥ÎªÌ©ì©ñ¨ú¼ËÂI¡A¤º´¡¦±½u´N·|¸òµÛ§ïÅÜ¡AÀɮצWºÙ¬O interpAnim02.m¡A°õ¦æ«áªº¹Ï§Î¦p¤U¡G

³o­Ó®i¥Üµ{¦¡«Ü¦³½ì¡A½ÐŪªÌ°È¥²¦Û¤v¸Õ¬Ý¬Ý¡A©ì©ñ´X­Ó±±¨îÂI¡A¬Ý¬Ý·|²£¥Í¤°»ò¤£¦P®ÄªGªº¤º´¡¦±½u¡C


MATLABµ{¦¡³]­p¡G¶i¶¥½g