Main Content

複合 System object の定義

この例では、他の System object を含む System object の定義方法を示します。バンドパス フィルターの System object™ を、別のハイパス フィルターおよびローパス フィルターの System object から定義します。

プロパティへの System object の格納

他の System object から System object を定義するには、基になる他のオブジェクトをクラス定義ファイルにプロパティとして格納します。この例では、ハイパスおよびローパス フィルターはそれぞれのクラス定義ファイルで定義された、独立した System object です。

properties (Access = private)% Properties that hold filter System objectspLowpass pHighpassend

バンドパス フィルター複合 System object の完全なクラス定義ファイル

classdefBandpassFIRFilter < matlab.System% Implements a bandpass filter using a cascade of eighth-order lowpass% and eighth-order highpass FIR filters.properties(Access = private)% Properties that hold filter System objectspLowpass pHighpassendmethods(Access = protected)functionsetupImpl(obj)% Setup composite object from constituent objectsobj.pLowpass = LowpassFIRFilter; obj.pHighpass = HighpassFIRFilter;endfunctionyHigh = stepImpl(obj,u) yLow = obj.pLowpass(u); yHigh = obj.pHighpass(yLow);endfunctionresetImpl(obj) reset(obj.pLowpass); reset(obj.pHighpass);endendend

バンドパス フィルターのローパス FIR コンポーネントのクラス定義ファイル

classdefLowpassFIRFilter < matlab.System% Implements eighth-order lowpass FIR filter with 0.6pi cutoffproperties(Nontunable)% Filter coefficientsNumerator = [0.006,-0.0133,-0.05,0.26,0.6,0.26,-0.05,-0.0133,0.006];endproperties(DiscreteState) Stateendmethods(Access = protected)functionsetupImpl(obj) obj.State = zeros(length(obj.Numerator)-1,1);endfunctiony = stepImpl(obj,u) [y,obj.State] = filter(obj.Numerator,1,u,obj.State);endfunctionresetImpl(obj) obj.State = zeros(length(obj.Numerator)-1,1);endendend

バンドパス フィルターのハイパス FIR コンポーネントのクラス定義ファイル

classdefHighpassFIRFilter < matlab.System% Implements eighth-order highpass FIR filter with 0.4pi cutoffproperties(Nontunable)% Filter coefficientsNumerator = [0.006,0.0133,-0.05,-0.26,0.6,-0.26,-0.05,0.0133,0.006];endproperties(DiscreteState) Stateendmethods(Access = protected)functionsetupImpl(obj) obj.State = zeros(length(obj.Numerator)-1,1);endfunctiony = stepImpl(obj,u) [y,obj.State] = filter(obj.Numerator,1,u,obj.State);endfunctionresetImpl(obj) obj.State = zeros(length(obj.Numerator)-1,1);endendend

参考