복합 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 objects pLowpass pHighpass end
대역통과 필터를 구현하는 복합 System object의 완전한 클래스 정의 파일
classdef BandpassFIRFilter < 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 objects pLowpass pHighpass end methods (Access = protected) function setupImpl(obj) % Setup composite object from constituent objects obj.pLowpass = LowpassFIRFilter; obj.pHighpass = HighpassFIRFilter; end function yHigh = stepImpl(obj,u) yLow = obj.pLowpass(u); yHigh = obj.pHighpass(yLow); end function resetImpl(obj) reset(obj.pLowpass); reset(obj.pHighpass); end end end
대역통과 필터의 저역통과 FIR 컴포넌트에 대한 클래스 정의 파일
classdef LowpassFIRFilter < matlab.System % Implements eighth-order lowpass FIR filter with 0.6pi cutoff properties (Nontunable) % Filter coefficients Numerator = [0.006,-0.0133,-0.05,0.26,0.6,0.26,-0.05,-0.0133,0.006]; end properties (DiscreteState) State end methods (Access = protected) function setupImpl(obj) obj.State = zeros(length(obj.Numerator)-1,1); end function y = stepImpl(obj,u) [y,obj.State] = filter(obj.Numerator,1,u,obj.State); end function resetImpl(obj) obj.State = zeros(length(obj.Numerator)-1,1); end end end
대역통과 필터의 고역통과 FIR 컴포넌트에 대한 클래스 정의 파일
classdef HighpassFIRFilter < matlab.System % Implements eighth-order highpass FIR filter with 0.4pi cutoff properties (Nontunable) % Filter coefficients Numerator = [0.006,0.0133,-0.05,-0.26,0.6,-0.26,-0.05,0.0133,0.006]; end properties (DiscreteState) State end methods (Access = protected) function setupImpl(obj) obj.State = zeros(length(obj.Numerator)-1,1); end function y = stepImpl(obj,u) [y,obj.State] = filter(obj.Numerator,1,u,obj.State); end function resetImpl(obj) obj.State = zeros(length(obj.Numerator)-1,1); end end end