梁曉雷
摘要:分段線性插值算法是一種技術(shù)比較成熟、實(shí)現(xiàn)比較簡(jiǎn)單的低次多項(xiàng)式插值算法,其曲線逼近程度即插值函數(shù)與原函數(shù)誤差基本滿足一般的工業(yè)控制場(chǎng)合需要。該算法占用系統(tǒng)資源少,在數(shù)據(jù)采集和數(shù)據(jù)處理等工業(yè)控制領(lǐng)域,往往使用單片機(jī)或嵌入式系統(tǒng)等資源受限處理器,通過分段線性插值算法簡(jiǎn)化原函數(shù),減少計(jì)算量,對(duì)于提高系統(tǒng)整體性能具有顯著的現(xiàn)實(shí)意義。
關(guān)鍵詞:分段線性插值;曲線逼近;函數(shù);工業(yè)控制;單片機(jī)
中圖分類號(hào):TP301文獻(xiàn)標(biāo)識(shí)碼:A文章編號(hào):1009-3044(2012)21-5236-02
The Implementation of Piecewise Linear Interpolation Algorithm Based on MCS
LIANG Xiao-lei
(UNIT 69046, Urumqi 830001,China)
Abstract: Piecewise linear interpolation algorithm is a relatively mature technology and a relatively simple low-order polynomial interpola? tion algorithm, the curve approximation degree of the interpolation function and the original function basically meet general industrial con? trol applications need. The algorithm occupies less system resources in industrial control field such as data acquisition and data processing, es? pecially in the system based on a microcontroller or embedded system and so on. Using piecewise linear interpolation algorithm to simplify the original function and to reduce the computation, it has significant practical significance for improving the overall performance of the sys? tem.
Key words: piecewise linear interpolation;curve approximation; function; industrial control;MCS
程序主要部分包括兩部分:?jiǎn)螀^(qū)間線性計(jì)算和全程線性插值計(jì)算。部分代碼如下所示。單區(qū)間線性計(jì)算:
Char liner_seg_x8_y8(char xn,char x1,char x2,char y1,char y2)
{int yn;
Char tmp;
If(xn {yn=y1} Else if(xn>x2) {yn=y2} Else { If(y1 {yn=y2-y1;tmp=xn-x1;yn=yn*tmp;tmp=x2-x1;yn=yn+(tmp/2);yn=yn/tmp;yn=y1+yn;} //實(shí)現(xiàn)yn=y1+(y2-y1)*(xn-x1)/(x2-x1); Else {yn=y1-y2;tmp=xn-x1;yn=yn*tmp;tmp=x2-x1;yn=yn+tmp/2;yn=yn/tmp;yn=y1-yn;} //實(shí)現(xiàn)yn=y1-(y1-y2)*(xn-x1)/(x2-x1);} return((char)yn);} 全程線性插值計(jì)算: Char line_all_x8_y8(char xn,char QUEUE_x[],char QUEUE_y[],char n) {Char I; Char yn; For(i=1;i<(n-1);i++) {If(xn<=QUEUE_x[i]) break;} Yn=liner_seg_x8_y8(xn,QUEUE_x[i-1], QUEUE_x[i],QUEUE_y[i-1],QUEUE_y[i]); Retrun(yn);} 插值算法在單片機(jī)上應(yīng)用,必須簡(jiǎn)化,使算法實(shí)現(xiàn)盡量少占用系統(tǒng)資源。通過使用分段線性插值簡(jiǎn)化插值算法,在單片機(jī)上得以實(shí)現(xiàn),能夠基本滿足單片機(jī)系統(tǒng)使用要求,并且不影響單片機(jī)控制系統(tǒng)的整體性能。 分段線性插值算法是一種在節(jié)點(diǎn)處具有不光滑性缺點(diǎn)的插值方法,在某些要求精度比較高的工程技術(shù)場(chǎng)合可能無法滿足要求。 參考文獻(xiàn): [1]張俊.匠人手記:一個(gè)單片機(jī)工作者的實(shí)踐與思考[M].北京.北京航空航天大學(xué)出版社,2008:137-139. [2]肖紅,曹茂,李盼池,等.基于分段線性插值的過程神經(jīng)網(wǎng)絡(luò)訓(xùn)練[J].計(jì)算機(jī)工程,2011(20):211-212. [3]王亞姣,馬豐杰.基于PLC的線性插值模糊控制器的設(shè)計(jì)[J].電子設(shè)計(jì)工程,2011(8):86-88. [4]張?zhí)炝?姚慶梅,許夫明,等.基于分段線性插值法的高精度測(cè)溫研究[J].信息技術(shù)與信息化,2012 (1):70-72.