2-H Relations among Filter Length N, Transition Band, and Accuracy Suppose that we want: passband ripple 1, stopband ripple 2, width of transition band F (expressed by normalized frequency) F = (f1 f2)/fs = (f1 f2)T (fs: sampling frequency, T: sampling interval) Then, the estimated length N of the digital filter is: . When there are two transition bands, F = min(F1, F2) 犧牲 transition band 的 frequency response, 換取較高的 passband and stopband accuracies
[Ref] F. Mintzer and L. Bede, “Practical design rules for optimum FIR bandpass digital filter”, IEEE Trans. ASSP, vol. 27, no. 2, pp. 204-206, Apr. 1979. 問題:假設 1 = 2 = ,N 為固定, 當 F 變為 A 倍時, 變為多少?
N = 17, k+2=10 transition band: 0.24 ~ 0.26 N = 17, boundary of transition band N = 17, transition band: 0.2 ~ 0.3
2-I Relations between Weighting Functions and Accuracy If we treat the passband more important than the stop band W(f) = 1 in the passband, 0 < W(f) < 1 in the stopband If we treat the stop band more important than the pass band 0 < W(f) < 1 in the passband, W(f) = 1 in the stopband
Larger error near the transition band Hd(F) H(F)
2-J FIR Filter in MSE Sense with Weighting Functions 可對照 pages 47~49 F = f / fs n = 0 ~ k when n 問題:
τ = 0 ~ k, n = 0 ~ k 可以表示成 (k+1) (k+1) matrix operation B S = C S = B−1C
思考: Is it possible to apply the transition band to the FIR filter in the MSE sense?
2-K Four Types of FIR Filter h[n] = 0 for n < 0 and n N 點數為 N Type 1 之前的方法只討論到Type 1 h[n1] = h[n2 − n] and N is odd. (even symmetric) k = (N1)/2
Type 1: h[n] = h[N−1− n] (even symmetric) and N is odd. Type 2: h[n] = h[N−1− n] (even symmetric) and N is even. Type 3: h[n] = −h[N−1− n] (odd symmetric) and N is odd. Type 4: h[n] = −h[N−1− n] (odd symmetric) and N is even. k = (N−1)/2
Type 2: When h[n] = h[N−1− n] and N is even: (even symmetric) 令 r[n] = h[n + k], where k = (N1)/2 (注意此時 k 不為整數) (比較 page 41) h[0] h[1] h[k-3/2] h[k-1/2] h[k+1/2] h[k+3/2] h[N-2] h[N-1] r[-k] r[-k+1] r[-3/2] r[-1/2] r[1/2] r[3/2] r[k-1] r[k] s[1]/2 s[2]/2 s[k-1/2]/2 s[k+1/2]/2
當 n = 1, 2, …, k+1/2 設計出 s[n] 之後 r[n] = s[n+1/2]/2, h[n] = r[n − k],
Design Method for Type 2 由於 n 和 n+1 兩項相加可得 所以可以「判斷」 R(F) 能被改寫成 求 s1[n] 和 s[n] 之間的關係
(令 k1 + 1/2 = k) 比較係數可得 for n = 2, 3, …., k−1/2
只需將 pages 52-55 的方法當中,Hd(F) 換成 W(F) 換成 k 換成 k − 1/2 = N/2 − 1 注意s1[n] 和 s[n] 之間的關係即可
Design Method for Type 3 由於 n−1 和 n+1 兩項相減可得 所以「判斷」可將 R(F) 改寫為
令 k1 = k − 1, 比較係數可得 for n = 2, 3, …., k−2
將 page 52-55 的方法當中,Hd(F) 換成 W(F) 換成 k 換成 k − 1 注意s1[n] 和 s[n] 之間的關係即可 思考:Design Method for Type 4
附錄三:Matlab 寫程式需注意的地方 一、各種程式語言寫程式共通的原則 二、Matlab 寫程式特有的技巧 (1) 能夠不在迴圈內做的運算,則移到迴圈外 (2) 寫一部分即測試,不要全部寫完再測試 (縮小範圍比較容易 debug) (3) 先測試簡單的例子,成功後再測試複雜的例子 二、Matlab 寫程式特有的技巧 (1) 迴圈能避免就儘量避免 (2) 儘可能使用 Matrix 及 Vector operation Example: 由 1 加 到100,用 Matlab 一行就可以了 sum([1:100]) 完全不需迴圈
三、一些重要的 Matlab 指令 (1) function: 放在第一行,可以將整個程式函式化 (2) tic, toc: 計算時間 (3) find: 找尋一個 vector 當中不等於 0 的entry 的位置 範例:find([1 0 0 1]) = [1, 4] find(abs([-5:5])<=2) = [4, 5, 6, 7, 8] (因為 abs([-5:5])<=2 = [0 0 0 1 1 1 1 1 0 0 0]) (4) : Hermitian (transpose + conjugation), . : transpose (5) imread: 讀圖, image, imshow, imagesc: 將圖顯示出來, (註: 較老的 Matlab 版本 imread 要和 double 並用 A=double(imread(‘Lena.bmp’)); (6) imwrite: 製做圖檔
(7) xlsread: 由 Excel 檔讀取資料 (8) xlswrite: 將資料寫成 Excel 檔 (9) aviread: 讀取 video 檔 (10) dlmread: 讀取 *.txt 或其他類型檔案的資料 (11) dlmwrite: 將資料寫成 *.txt 或其他類型檔案