メインコンテンツ

fdesign を使用したフィルターの設計

以下の 2 つの手順を使用して単純なフィルターを設計します。

  1. フィルター仕様オブジェクトを作成。

  2. フィルターを設計。

例1 2 つの手順によるフィルターの設計

ここではバンドパス フィルターを設計することにします。通常、バンドパス フィルターは下の図に示すように定義されます。

この例では、Fs = 48 kHz のサンプリング周波数が使用されています。このバンドパス フィルターの仕様は、MATLAB® コードを使用すると、以下のように指定されます。

A_stop1 = 60;		% Attenuation in the first stopband = 60 dB
F_stop1 = 8400;		% Edge of the stopband = 8400 Hz
F_pass1 = 10800;	% Edge of the passband = 10800 Hz
F_pass2 = 15600;	% Closing edge of the passband = 15600 Hz
F_stop2 = 18000;	% Edge of the second stopband = 18000 Hz
A_stop2 = 60;		% Attenuation in the second stopband = 60 dB
A_pass = 1;		% Amount of ripple allowed in the passband = 1 dB

以下の 2 つの手順では、これらの仕様が fdesign.bandpass メソッドにパラメーターとして渡されます。

手順 1

フィルター仕様オブジェクトを作成するには、以下のコードを MATLAB プロンプトで実行します。

d = fdesign.bandpass

ここで、既定の Specificationfst1fp1fp2fst2ast1apast2 に対応するフィルター仕様を渡します。この例では fs を最後の入力引数として追加し、サンプリング周波数を 48 kHz に指定します。

>> BandPassSpecObj = ...
   fdesign.bandpass('Fst1,Fp1,Fp2,Fst2,Ast1,Ap,Ast2', ...
		F_stop1, F_pass1, F_pass2, F_stop2, A_stop1, A_pass, ...
		A_stop2, 48000)
      

メモ

ここではフィルターの次数を指定しないため、仕様を実現するためのアルゴリズム設計に自由度がもたらされます。ここでは最小次数の設計となります。

Fstop1 のような仕様パラメーターは、値が与えられないとすべて既定値に設定されます。仕様パラメーターの値はフィルター仕様オブジェクトの作成後に変更できます。たとえば変更が必要な 2 つの値 Fpass2Fstop2 がある場合、set コマンドを使用して、最初にオブジェクトを指定し、次にパラメーターと値のペアを指定します。MATLAB プロンプトで以下のコードを実行します。

>> set(BandPassSpecObj, 'Fpass2', 15800, 'Fstop2', 18400)   
BandPassSpecObj は新しいフィルター仕様オブジェクトで、フィルターのタイプなど、必要なすべての設計パラメーターが含まれています。

また、struct 配列の要素の場合と同様にフィルター仕様オブジェクトにアクセスして、オブジェクトのパラメーター値を変更することもできます。

>> BandPassSpecObj.Fpass2=15800;

手順 2

design コマンドを使用してフィルターを設計します。関数 designmethods を呼び出して、仕様オブジェクトで利用できる設計法にアクセスできます。たとえばこの例では、以下のコマンドを実行できます。

>> designmethods(BandPassSpecObj)


Design Methods for class 
fdesign.bandpass (Fst1,Fp1,Fp2,Fst2,Ast1,Ap,Ast2):


butter
cheby1
cheby2
ellip
equiripple
kaiserwin
使用する設計法を選択した後、MATLAB プロンプトで次のコマンドを実行できます (この例では 'equiripple' が選択されています)。
>> BandPassFilt = design(BandPassSpecObj, 'equiripple')
 
BandPassFilt =
 
     FilterStructure: 'Direct-Form FIR'
          Arithmetic: 'double'         
           Numerator: [1x44 double]    
    PersistentMemory: false            
                      

DSP System Toolbox™ がインストールされている場合は、フィルター System object™ を使ってフィルターを設計することもできます。フィルター System object を同じ仕様のオブジェクト BandPassSpecObj で作成するには、次のコマンドを実行できます。

>> designmethods(BandPassSpecObj,...
'SystemObject',true)


Design Methods that support System objects for class
fdesign.bandpass (Fst1,Fp1,Fp2,Fst2,Ast1,Ap,Ast2):


butter
cheby1
cheby2
ellip
equiripple
kaiserwin 


>> BandPassFiltSysObj = design(BandPassSpecObj,...
'equiripple','SystemObject',true)


  System: dsp.FIRFilter 

  Properties:
               Structure: 'Direct form'
         NumeratorSource: 'Property'   
               Numerator: [1x44 double]
       InitialConditions: 0            
    FrameBasedProcessing: true         
                                       
  Show fixed-point properties
 
フィルター System object に使用できる設計法と設計オプションは、フィルター オブジェクトに使用できるものと必ずしも同じではありません。

メモ

設計法を指定しない場合、既定の方法が使用されます。たとえば、以下のコマンドを実行します。

>> BandPassFilt = design(BandPassSpecObj)
 
BandPassFilt =
 
     FilterStructure: 'Direct-Form FIR'
          Arithmetic: 'double'         
           Numerator: [1x44 double]    
    PersistentMemory: false
この場合、設計法は自動的に選択されることになります。