201001908 九、發明說明: 【發明所屬之技術領域】 本發明是有關於一種數位濾波器之設計方法,特別是有關於 一種利用一特定演算法以使一數位濾波器滿足事先設定之頻率響 應。 【先前技術】 目刖,數位5孔说處理(Digital Signal Processing,DSP)的技術 已經廣泛地應用在各種不同領域上,例如:語音辨識、語音合成 等一維訊號處理,影像壓縮及或影像處理等二維的訊號處理。在 DSP的研究課題中,如何設計數位濾波器是一個最重要環節。簡 單來說,數位濾波器的主要作用是過濾數位輸入訊號成分中我們 不需要的部分,而保留想要的部分。濾波器依其濾波目的通常可 分成下列幾類,包括:低通(l〇Wpass)、高通(highpass)、帶通(band pass)、帶拒(band stop)以及全通(触band)濾波器等類型。舉例而 言,低通數位濾波器是讓輸入訊號的低頻部分通過,同時阻絕其 他中高頻的成分,帶通濾波器則是讓訊號的中間範圍的頻率通 過,而濾除屬於低頻與高頻的部分。 有限脈衝響應濾波器(Finite ImpUlse Resp〇nse,FIR)係指其系 統的脈衝響應是有限的,啊麟㈣輸出僅受到目前以及過去 的輸入所影響,與縣的輸Α無關。#要滿足某—侧波器的設 计規格時’-般而言,FIR所需要的遽波器階次較使用無限脈衝響 應濾波器(Infinite Impulse Response,IIR)來得多;另一方面, 滤波器有其本身架構上的優點,意即不論紐⑽數如何設定, 5 201001908 FIR濾波器永遠為穩定的系統。 習知技術於設計濾波器時,係依據所給定的濾波器規格 (specification)來選擇適當的視窗函數(wind〇w function),例如:漢 寧(Hanning) ’ 漢明(Hamming),布拉克曼(Blackman)或凱薩(Kaiser) 等不同的函數’此些視窗函數所得到的fir濾波器的頻率響應具 有不同截止頻帶的衰減要求(stop band attenuation requirement^。一 般而言,欲獲得比較陡峭(steeper)的濾波器波形,往往需要較高階 的濾波器才能完成。利用這種視窗函數的FIR設計技巧,再經過 更進一步的數學運算,就可以得出低通、高通、帶通以及帶拒等 常被使用的濾波器。另外,如需要設計出任意形狀的濾波器的話, 一般係使用麥科拉倫-帕克(McClellan_Parks)方法進行設計。 另一習知技術係透過遺傳演算法(;Genetic Algorithm,GA)以 設計濾波器。依GA演算法之數值運算方式可以分為兩類:第一 類係為傳統的一進位編碼的遺傳演算法(binary-c〇ded GA);其中, 遽,器的係數必須先轉換成二_絲示式,才能進行所謂的遺 化迭代最後再還原成實數的型式。第二類是實數編碼遺傳 演算法(real-coded GA) ’它的運算方式是直接以實數型態進行,因 此演化的機制與二進制的GA有些許差異。 然而,、湘上述f知之演算法設計丨來之紐^可能無法真 之演算法可_出滤 頻梓應之局部最佳解(1⑽1 S°論η) ’故遽波器之 S…匕不如預期,而導致需重覆設計濾波器之窘境。 計方法 ’以作為改善上賴點之實财式與依據 人其知縣之各項問題,為了能夠兼顧解決之,本發明 •,於夕年研究開發與諸多實務經驗,提出—紐位濾波器之設 6 201001908 【發明内容】 有鑑於此,本發明之目的就是在提供一種數位濾波器之設計 方法,以解決數位濾波器設計成效不彰之問題。 根據本發明之目的,提出一種數位濾波器之設計方法,其特 徵在於利用一粒子群優演算法以使所設計之數位濾波器之頻率響 • 應可滿足事先設定之規格。其中,上述之數位濾波器係為一有限 脈衝響應濾波器。 粒子群優演算法(Particle Swarm Optimization,PSO)係在 1995 年由甘迺迪(Kenndy)與亞伯哈特(Eberhart)兩位學者所發表的一種 最佳化演算法。此種演算法係從魚群(fish schooling)或者鳥群(bird flocking)等群體組織行為所啟發得到的,藉由群體間彼此經驗的交 流,使得每一個個體都能夠往目標方向移動,此方法能更快速且 有效的搜尋到問題的最佳解。PSO演算法首先會產生一個初始族 群(initial population),族群内包含許多的粒子(particle)或者稱為個 體(individual),對於解最佳化問題而言,這些粒子就是代表系統的 候選解(candidate solution) ’接著依據演算法中的速度(vel〇dty)及 位置(position)更新公式’進而求出問題的最佳解。故使用此種運 算法可更容易跳脫局部最佳解(local solution),進而得到全域的最 佳解(global solution),進而使數位濾波器之頻率響應符合預定之頻 率響應。 茲為使貴審查委員對本發明之技術特徵及所達到之功效有 更進一步之暸解與認識,謹佐以較佳之實施例及配合詳細之說明 如後。 【實施方式】 以下將參照相關圖式’說明依本發明較佳實施例之數位濾波 7 201001908 器之設計方法’為使便於理解,下述實施例中之相同元件係以相 同之符號標示來說明。 請參閱第1圖,其係為本發明之數位濾波器之設計方法之實 施例步驟流程圖,其包含: 步驟S11 :建構一粒子群優演算法; 步驟S12 :決定一數位濾波器之頻率響應範圍及其價值函數; 以及 步驟S13 :執行上述演算法以使數位濾波器達到步驟Sl2決 定之頻率響應範圍。 、 其中,上述决算法係依據上述價值函數(c〇st £^ncti〇n)進行最 佳解之修正,數位濾波器之頻率響應範圍係可為低通濾波、高通 濾波、帶通濾波、帶拒濾波或全通濾波等濾波範圍。 請續參閱第2圖,其係為本發明之數位滤波器之設計方法之 粒子群優演算法步驟流程圖,其包含: 步驟S21 :產生初始粒子之位置及速度; 步驟S22 :計算每一粒子之價值函數; 步驟S23 :更新每-粒子之最佳位置及其群體之最佳位置; 步驟S24 :更新每一粒子之位置及速度;以及 乂驟825 .判疋疋否滿足終止條件,若是,則結束演算法, 否,則回到步驟S22。 、 穴丁,少鄉所便用之迷度更新公式係如下表示. 上式巾,崎赚觀(inertia wdght),~和~為兩個正值的 吊數,Ο和r2為介於[〇 ’ !]之間的隨機亂數,v帶代表粒子的速产, P代表每-鍊子從開始演化至今最佳的位置,Μ表整個族^ 8 201001908 開始演化至今最佳的位置。而h 公式如下:U⑷)咳>)+==)的元素,其位置更新 本毛月所使用之次算法係為粒子群優演算法的触Sw_ Optmnzabn,PS0) ’ 其優點在於: L =子群伽算法係雜群絲礎的麟演算法,在參數 空ΪΓ以各種不同的方向進行全域的搜尋,可避免習知 /秀算法/、找到局部最佳解(l〇cal 的箸境,進而 得到全域的最佳解(global solutior^。 •這種/寅算法在寻找最佳解的過程中係依據所設定的價值 函數(cost function)之大小進行修正,無須用到梯度 (gradient)的數學運算,故當價值函數為非平滑 ^on-smooth)函數時,換言之,不能對價值函數作梯度運 3. 算時,使用PSO演算法可解決此類最佳化問題。 粒子群優演舁法可以彈性地控制全域與局部探索二者之 間的平衡’對於過早(premature)收斂的現象能有效地克 服。201001908 IX. Description of the Invention: [Technical Field] The present invention relates to a method for designing a digital filter, and more particularly to a method for using a specific algorithm to satisfy a predetermined frequency response by a digital filter. [Prior Art] It is seen that the technology of digital signal processing (DSP) has been widely used in various fields, such as speech recognition, speech synthesis, etc., one-dimensional signal processing, image compression and or image processing. Wait for two-dimensional signal processing. In the research topic of DSP, how to design digital filter is the most important link. In short, the main function of the digital filter is to filter the parts of the digital input signal component that we don't need, while preserving the desired part. Filters are generally classified into the following categories for their filtering purposes, including: low pass (lpass), high pass, band pass, band stop, and all pass (touch band) filters. And other types. For example, the low-pass digital filter passes the low-frequency part of the input signal while blocking other mid-high frequency components. The band-pass filter passes the frequency of the middle range of the signal, and filters out the low frequency and high frequency. section. The finite impulse response filter (Finite ImpUlse Resp〇nse, FIR) means that the impulse response of the system is limited. The output of the arion (4) is only affected by the current and past inputs, and has nothing to do with the county's transmission. #To meet the design specifications of a certain waver, 'Generally, the chopper order required by FIR is much more than that of Infinite Impulse Response (IIR); on the other hand, filtering The device has its own architectural advantages, which means that no matter how the number of neon (10) is set, 5 201001908 FIR filter is always a stable system. Conventional techniques are used to design a filter based on a given filter specification to select the appropriate window function (windingw function), for example: Hanning 'Hamming', Braque Different functions such as Blackman or Kaiser' The frequency response of the fir filter obtained by these window functions has different cutoff band attenuation requirements (in general, it is steeper). (steeper) filter waveforms often require higher-order filters to complete. Using the FIR design techniques of this window function, and further mathematical operations, you can get low pass, high pass, band pass and reject Filters that are often used. In addition, if a filter of any shape needs to be designed, it is generally designed using the McClellan-Parks method. Another conventional technique is through genetic algorithm (; Algorithm, GA) to design the filter. According to the GA algorithm, the numerical operation can be divided into two categories: the first type is the traditional one-pass coding genetic performance. Algorithm (binary-c〇ded GA); where 遽, the coefficient of the device must first be converted into a two-line expression, in order to carry out the so-called after-imaging iteration and then restore to the real number. The second type is the real-coded genetic algorithm. The method of real-coded GA is to perform the real type directly, so the evolution mechanism is slightly different from the binary GA. However, the design of the above-mentioned algorithm can not be true. The algorithm can be _ out of the filter frequency 局部 should be the local best solution (1 (10) 1 S ° theory η) 'So the chopper S ... 匕 is not as expected, resulting in the need to repeat the design of the filter environment. In order to improve the real financial style of the upper point and the problems of the people according to their knowledge, in order to be able to solve the problem, the present invention, in the research and development of the eve of the year and many practical experiences, proposed - the design of the button filter 6 201001908 In view of this, the object of the present invention is to provide a digital filter design method to solve the problem that the digital filter design is ineffective. According to the object of the present invention, a digital filter design is proposed. The method is characterized in that a particle swarm optimization algorithm is used to make the frequency response of the designed digital filter meet the preset specifications, wherein the digital filter is a finite impulse response filter. Particle Swarm Optimization (PSO) is an optimization algorithm published in 1995 by two scholars, Kenndy and Eberhart. This algorithm is inspired by group organization behaviors such as fish schooling or bird flocking. By sharing the experience of each other, each individual can move toward the target. This method can Find the best solution to the problem faster and more efficiently. The PSO algorithm first generates an initial population. The population contains many particles or individuals. For the solution optimization problem, these particles are representative solutions of the system (candidate). Solution) 'Follow the speed (vel〇dty) and position (position) in the algorithm to update the formula' to find the best solution to the problem. Therefore, using this algorithm, it is easier to jump off the local solution, and then obtain the global solution, so that the frequency response of the digital filter conforms to the predetermined frequency response. For a better understanding and understanding of the technical features and the efficacies of the present invention, the preferred embodiments and the detailed description are as follows. [Embodiment] Hereinafter, the design method of the digital filter 7 201001908 according to the preferred embodiment of the present invention will be described with reference to the related drawings. For the sake of easy understanding, the same components in the following embodiments are denoted by the same reference numerals. . Please refer to FIG. 1 , which is a flow chart of an embodiment of a method for designing a digital filter according to the present invention. The method includes the following steps: Step S11 : constructing a particle group optimization algorithm; Step S12 : determining a frequency response of a digital filter Range and its value function; and step S13: performing the above algorithm to cause the digital filter to reach the frequency response range determined in step S12. Wherein, the above-mentioned decision algorithm performs the correction of the optimal solution according to the above value function (c〇st £^ncti〇n), and the frequency response range of the digital filter can be low-pass filtering, high-pass filtering, band-pass filtering, and band Filter range such as filter rejection or all-pass filtering. Please refer to FIG. 2, which is a flow chart of the particle group optimization algorithm step of the digital filter design method of the present invention, comprising: Step S21: generating the position and velocity of the initial particles; Step S22: calculating each particle a value function; step S23: updating the optimal position of each particle and its optimal position; step S24: updating the position and velocity of each particle; and step 825. determining whether the termination condition is satisfied, and if so, Then, the algorithm ends, otherwise, the process returns to step S22. , Cave Ding, Shaoxiang used to use the fuzzy update formula is expressed as follows. Top style towel, inertia wdght, ~ and ~ are two positive values of the number, Ο and r2 are between [〇 ' ! Between the random random number, v band represents the rapid production of particles, P represents the best position of each chain from the beginning to the evolution, and the whole family has evolved to the best position since 2010. And h formula is as follows: U (4)) cough >) + ==) element, its position update is used in the second month of the algorithm is the particle swarm optimization algorithm of the touch Sw_ Optmnzabn, PS0) 'The advantages are: L = The sub-group gamma algorithm is a lining algorithm for the heterogeneous group. In the parameter space, the global search is performed in various directions, which can avoid the conventional/show algorithm/, find the local optimal solution (the environment of l〇cal, Then get the global optimal solution (global solutior^. • This / 寅 algorithm in the process of finding the best solution is based on the size of the set cost function (cost function), without the use of gradient (gradient) Mathematical operations, so when the value function is a non-smoothing ^on-smooth) function, in other words, the value function cannot be scaled. 3. When calculating, the PSO algorithm can solve such optimization problems. The method can flexibly control the balance between the global and local explorations' for the phenomenon of premature convergence can be effectively overcome.
4.粒子群優演算法的迭代公式相當簡單,運算時是直接以 浮點數值(floating-pointnumber)為主,因此更易於電腦程 式的撰寫。 ' 故當設計一數位濾波器時,使用粒子群優演算法即可達到最 佳效果。而且此數位濾波器係為一有限脈衝響應濾波器(Finite Impulse Response,fir) ’且其頻率響應係可為低通濾波、高通滤 波、帶通濾波、帶拒濾波或全通濾波等濾波範圍。 上述FIR濾波器可利用以下差分方程式加以表示: y[n]=h[〇]x[n] + h[l]x[n -1] + h[l\c[n-2] + ^ + h[N-l]x[n-(N ^ ή] 9 201001908 (第1式) ' [ 免](第2式)表示之。 八中x疋外界的輸入訊號,少是滤波器的輸出訊號,Tv-ι為 遽波器的階次(〇_,柳,㈣小..u,域波器的單位 脈衝響應(unit impulse response),同時也代表壚波器的係數。設計 FI=滤波H之重點在於如何決定出這—組綱係數柳,傳統的方 法是透過視窗函數(win(jowfuncti〇n)來設計,本發明係使用粒子群 優演算法進行舰H設計,使賊波器賴轉應滿足設計者的 要求。 本發明係在頻域(frequency domain)下做分析與探討,因此對 第2式取z轉換,其如下所示:r[z]=乞, k = 0 進一步移項後,可以獲得到數位濾波器之轉移函數,其如下 所示:, 在此同時’令,其中/7為數位頻率(digital frequency),所 、 以其頻率響應表示式為(第3式),故由第3 k=0 式可推知不同的得到不同的切。 進一步考慮奇數與偶數的7V以及w的對稱性(symmetrical) 與反對稱性(anti-symmetrical)等不同架構,可以獲得四種不同線性 相位(linear phase)的FIR濾波器類型,其如下所示: 類型1及類型2 : 如單位脈衝響應/zA7係屬於對稱型式(symmetrical),換言之, 公式為/^7_/7V-7-尺/,則第3式的頻率響應可以表示為 H(D)=e·卵·1)/2Η*(Ω) 〇 201001908 其中片係為實數函數,故可用下式表示: "nl f b]c〇s(々n), # :奇數(類型 1),4. The iterative formula of particle swarm optimization algorithm is quite simple. The operation is directly based on floating-point number, so it is easier to write in computer program. Therefore, when designing a digital filter, the particle swarm optimization algorithm can achieve the best results. Moreover, the digital filter is a finite impulse response filter (Finite Impulse Response, fir) and its frequency response can be a filter range such as low pass filtering, high pass filtering, band pass filtering, band rejection filtering or all pass filtering. The above FIR filter can be expressed by the following difference equation: y[n]=h[〇]x[n] + h[l]x[n -1] + h[l\c[n-2] + ^ + h[Nl]x[n-(N ^ ή] 9 201001908 (Formula 1) ' [Free] (Form 2). Eight input x 疋 external input signal, less is the output signal of the filter, Tv -ι is the order of the chopper (〇_, Liu, (4) small..u, the unit impulse response of the domain waver, and also represents the coefficient of the chopper. Design FI = the focus of the filter H In the how to determine this - the group coefficient Liu, the traditional method is designed by the window function (win (jowfuncti〇n)), the invention uses the particle group superior performance algorithm for the ship H design, so that the thief wave device should be satisfied The designer's request. The invention is analyzed and discussed in the frequency domain, so the z-conversion of the second formula is as follows: r[z]=乞, k = 0 After further shifting, Obtaining the transfer function to the digital filter, as shown below: At the same time, ', where /7 is the digital frequency, and the frequency response expression is (3rd), so 3 k=0 It can be inferred that different different cuts can be obtained. Further considering the different structures of odd and even 7V and w symmetrical and anti-symmetrical, four different linear phases can be obtained. FIR filter type, which is as follows: Type 1 and Type 2: If the unit impulse response / zA7 is a symmetrical type, in other words, the formula is /^7_/7V-7-foot/, then the third type The frequency response can be expressed as H(D)=e·egg·1)/2Η*(Ω) 〇201001908 where the film system is a real number function, so it can be expressed by the following formula: "nl fb]c〇s(々n), # : odd number (type 1),
乂 ^ ^ 1 N/2 .I.L 偶數(類型2),上式中’ 參數W與有關,兩者的關係式如下:砌卜崎# —1)/2], 以及 Φ:] = < 2办~ 1)/2 - Α:1 Α: = 1,2,…,(H)/2,#:奇數(類型 j), [2h[N/2^k\ ]ς=Λ,2,…,Ν/2, #:偶數(類型 2). ^[〇U[ll...,M(A^l)/2]l· ΛΓ:奇數(類型 i), ΙΨ1Φ1··.,^/2]1 #:偶數 I類型 2). 粒子群優演算法中,向量5就是代表所謂的粒子許多的粒 子就組成—個族群,透過設計參數向量S,進而求岐佳化的慮 波器係數六/^,向量5可設計為下式: Β 類型3及類型4 : 目“田單位脈衝響應W是屬於反對稱型式(anti_symmetrical)時, 則W公式如下: 承 斤1—4 灸二0,1,…,#/2—I 偶數(類型4) 上所述’第3式之頻率響應式可改寫如下: H(Q) = e~MN~l)/2H* (Ω) 其中’ 屯f數函數’ ^⑽之關係式係如下所示: ^Γ(Ω) (f^[A:]sm(A:Q),":奇數(類型 3), 參數从y與w之關係式為: 11 201001908 4 卜1,2,秦1)/2,奇數(類型办 1难/2-4 …,亀,^偶數(類型 向量5之關係式設計如下: Β Γ[ΐΗ2} 奇數(類型3)乂^ ^ 1 N/2 .IL Even number (type 2), where the parameter 'W is related to the above equation, the relationship between the two is as follows: 筑布崎#-1)/2], and Φ:] = < 2 Do ~ 1)/2 - Α:1 Α: = 1,2,...,(H)/2,#: odd (type j), [2h[N/2^k\ ]ς=Λ,2,... , Ν/2, #: even (type 2). ^[〇U[ll...,M(A^l)/2]l· ΛΓ: odd (type i), ΙΨ1Φ1··.,^/2 ]1 #: even I type 2). In the particle swarm optimization algorithm, the vector 5 is a group of particles representing so-called particles, which are composed of a group, through the design parameter vector S, and then the filter coefficients are optimized. Six/^, vector 5 can be designed as follows: Β Type 3 and type 4: When the field unit impulse response W is an anti-symmetric type, the formula is as follows: Φ1–4 moxibustion 2, 1,...,#/2—I Even (Type 4) The frequency response of the '3th equation above can be rewritten as follows: H(Q) = e~MN~l)/2H* (Ω) where ' 屯f The relational function of the number function ' ^(10) is as follows: ^Γ(Ω) (f^[A:]sm(A:Q), ": odd number (type 3), the relationship between parameters y and w is : 11 201001908 4 Bu 1,2,Qin 1)/2 Odd (type 1 is difficult to do / 2-4 ..., Kameido, ^ even (type 5 vector relation of the following design: Β Γ [ΐΗ2} odd (type 3)
__...傘/2]! 偶數、(類型J 粒子群優演算法是屬於演化式計算的—種,故錄有效地解 決各類的最佳化問題,包括韓度、複雜度高以衫個最佳值 (滅___)等問題。再者,粒子群優演算法是依其價值函 數的大小來判斷這個粒子(候)的優劣、,因此在進行設計之前必 辨先定義出祕的價值函數’本發明的價值函數定義如 •[丨乃⑼-邱^而(第4式) 其中’想的頻率響應(ideal frequency _刪) 是滤波ϋ的頻率響應,藉由粒子群優演算法將第4式最小化,以 達成數位濾波器設計的目的。 乂上所述僅為舉例性,*非為限制性者。任何未脫離本發明 之精神與範«,而對其進行之等效修改或變更,均應包含於後附 之申請專利範圍中。 【圖式簡單說明】 ^ 1圖係為本發明之數位濾波器之設計方法之實施例步驟流程 圓;以及 第2圖係為本㈣之數赠n餅綠之粒子群優演算 法步 驟流程圖。 12 201001908 【主要元件符號說明】 S11至S13 :步驟流程;以及 S21至S25 :步驟流程。 13__...Umbrella/2]! Even, (Type J particle swarm optimization algorithm is an evolutionary calculation, the record is effective to solve various types of optimization problems, including Korean, high complexity shirt The best value (off ___) and other issues. Furthermore, the particle swarm optimization algorithm judges the pros and cons of the particle according to the size of its value function, so it must be defined before the design. The value function 'The value function of the present invention is defined as • [丨乃(9)-邱^ and (4th formula) where 'the frequency response (ideal frequency_deletion) is the frequency response of the filter ,, by particle swarm optimization algorithm The fourth formula is minimized to achieve the purpose of the digital filter design. The above description is merely exemplary, and * is not a limitation. Any equivalent without departing from the spirit and scope of the present invention Modifications or changes are to be included in the scope of the appended patent application. [Simple Description of the Drawings] ^ 1 is the step flow circle of the embodiment of the digital filter design method of the present invention; and the second figure is (4) The flow chart of the steps of the particle swarm optimization algorithm of n cake green. 2 201001908 [Explanation of main component symbols] S11 to S13: Step flow; and S21 to S25: Step flow. 13