This example shows how to implement nondirect
feedthrough for a System object™ using the updateImpl
, outputImpl
and isInputDirectFeedthroughImpl
methods.
In nondirect feedthrough, the object's outputs depend only
on the internal states and properties of the object, rather than the
input at that instant in time. You use these methods to separate the
output calculation from the state updates of a System object.
Implementing these two methods overrides the stepImpl
method.
This enables you to use the object in a feedback loop and prevent
algebraic loops.
To use the updateImpl
, outputImpl
,
and isInputDirectFeedthroughImpl
methods, you must
subclass from both the matlab.System
base class and
the Nondirect
mixin class.
classdef IntegerDelaySysObj < matlab.System & ... matlab.system.mixin.Nondirect
Implement an updateImpl
method to update the
object with previous inputs.
methods (Access = protected) function updateImpl(obj,u) obj.PreviousInput = [u obj.PreviousInput(1:end-1)]; end end
Implement an outputImpl
method to output the
previous, not the current input.
methods (Access = protected) function [y] = outputImpl(obj,~) y = obj.PreviousInput(end); end end
Implement an isInputDirectFeedthroughImpl
method
to indicate that the input is nondirect feedthrough.
methods (Access = protected) function flag = isInputDirectFeedthroughImpl(~,~) flag = false; end end
classdef intDelaySysObj < matlab.System &... matlab.system.mixin.Nondirect % intDelaySysObj Delay input by specified number of samples. properties InitialOutput = 0; end properties (Nontunable) NumDelays = 1; end properties (DiscreteState) PreviousInput; end methods (Access = protected) function validatePropertiesImpl(obj) if ((numel(obj.NumDelays)>1) || (obj.NumDelays <= 0)) error('Number of delays must be positive non-zero scalar value.'); end if (numel(obj.InitialOutput)>1) error('Initial Output must be scalar value.'); end end function setupImpl(obj) obj.PreviousInput = ones(1,obj.NumDelays)*obj.InitialOutput; end function resetImpl(obj) obj.PreviousInput = ones(1,obj.NumDelays)*obj.InitialOutput; end function [y] = outputImpl(obj,~) y = obj.PreviousInput(end); end function updateImpl(obj, u) obj.PreviousInput = [u obj.PreviousInput(1:end-1)]; end function flag = isInputDirectFeedthroughImpl(~,~) flag = false; end end end
matlab.system.mixin.Nondirect
| outputImpl
| updateImpl