2014-10-31 56 views
1

我已經實現了一個簡單的腳本,它比較了Butterworth,Chebyshev和Bessel過濾器的一系列過濾順序。代碼運行時會產生預期的結果,但bessel過濾器實現除外。我得到一個錯誤:'mkfilter'命令在MATLAB中設計bessel類型過濾器

Error in FilterComparison (line 75) 
bes_1 = mkfilter(fc, 1, 'bessel'); 

我試過多個東西,但似乎無法刪除此錯誤。我已經包含以下完整代碼:

%Script to compare the responses of various analogue filters 
%including bessel, chebyshev and butterworth. 
%mkfilter command syntax 
%example = mkfilter (cutoff freq, order, 'type'); 

clear all 
close all 

%Cut off frequency 
fc = 2000; 

%Determines whether figures are displayed or not. 
%Silent = 1, no display 
silent = 1; 

%BUTTERWORTH FILTERS 
%1st order butterworth filter 
butter_1 = mkfilter(fc, 1, 'butterw'); 

%2nd order butterworth filter 
butter_2 = mkfilter(fc, 2, 'butterw'); 

%3rd order butterworth filter 
butter_3 = mkfilter(fc, 3, 'butterw'); 

%4th order butterworth filter 
butter_4 = mkfilter(fc, 4, 'butterw'); 

%5th order butterworth filter 
butter_5 = mkfilter(fc, 5, 'butterw'); 

%6th order butterworth filter 
butter_6 = mkfilter(fc, 6, 'butterw'); 

%Bode plot 
if ~silent 
    figure(1) 
    bode(butter_1, 'red',butter_2, 'blue',butter_3, 'green',butter_4, 'cyan',butter_5,  'black',butter_6, 'magenta') 
    legend('n = 1','n = 2','n = 3','n = 4', 'n = 5', 'n = 6') 
end 

%CHEBYSHEV FILTERS 
%1st order chebyshev filter 
cheby_1 = mkfilter(fc, 1, 'Cheby', 2); 

%2nd order chebyshev filter 
cheby_2 = mkfilter(fc, 2, 'Cheby', 2); 

%3rd order chebyshev filter 
cheby_3 = mkfilter(fc, 3, 'Cheby', 2); 

%4th order chebyshev filter 
cheby_4 = mkfilter(fc, 4, 'Cheby', 2); 

%5th order chebyshev filter 
cheby_5 = mkfilter(fc, 5, 'Cheby', 2); 

%6th order chebyshev filter 
cheby_6 = mkfilter(fc, 6, 'Cheby', 2); 

%Bode plot 
if ~silent 
    figure(2) %open figure 2 
    bode(cheby_1, 'red',cheby_2, 'blue',cheby_3, 'green',cheby_4, 'cyan',cheby_5, 'black',cheby_6, 'magenta') 
    legend('n = 1','n = 2','n = 3','n = 4', 'n = 5', 'n = 6') 
end 

%BESSEL FILTERS 
%1st order bessel filter 
bes_1 = mkfilter(fc, 1, 'bessel'); 

%2nd order bessel filter 
bes_2 = mkfilter(fc, 2, 'bessel'); 

%3rd order bessel filter 
bes_3 = mkfilter(fc, 3, 'bessel'); 

%4th order bessel filter 
bes_4 = mkfilter(fc, 4, 'bessel'); 

%5th order bessel filter 
bes_5 = mkfilter(fc, 5, 'bessel'); 

%6th order bessel filter 
bes_6 = mkfilter(fc, 6, 'bessel'); 

%Bode Plot 
figure(3) 
bode(bes_1, 'red',bes_2, 'blue',bes_3, 'green',bes_4, 'cyan',bes_5, 'black',bes_6,   'magenta') 
legend('n = 1','n = 2','n = 3','n = 4', 'n = 5', 'n = 6') 

%Plot 3rd order filters for comparison 
figure (4) 
bode(cheby_3, 'red', bes_3, 'blue', butter_3, 'green') 
legend('Chebyshev', 'Bessel', 'Butterworth') 

在此先感謝。 P.s,我是新來堆棧溢出,所以格式化的道歉。

回答

1

bessel過濾器的mkfilter中有一個錯誤,導致第一和第二階貝賽爾過濾器返回此錯誤。

在第58行開始:: 您可以通過編輯mkfilter(使用edit mkfilter打開文件)修復

if ord == 1, 
    sys = nd2sys(1,b1); 
elseif ord == 2, 
    sys = nd2sys(1,b2); 
... 

更改到這一點:

if ord == 1, 
    sys = tf(1,b1); 
elseif ord == 2, 
    sys = tf(1,b2); 
... 
+0

感謝您的答覆0xMB。如何編輯內置函數?當我在命令窗口輸入'編輯mkfilter'時,它會打開一個只讀版本。有沒有辦法讓我可以寫作? – 2014-11-03 11:20:34

+0

解決此問題的一種方法是將'mkfilter'函數的內容複製到一個新的函數文件中,並將其放置在當前的工作目錄中。然後您可以應用修改。然後MATLAB將使用這個修改後的函數來代替內置函數。您也可以使用'which mkfilter'並更改該文件的權限。 – 0xMB 2014-11-03 12:01:29