Use Update and Output for Nondirect Feedthrough

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. This enables you to use that object in a feedback loop and prevent algebraic loops.

Subclass from the Nondirect Mixin Class

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 Updates to the Object

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 Outputs from Object

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 Whether Input Is Direct Feedthrough

Implement an isInputDirectFeedthroughImpl method to indicate that the input is nondirect feedthrough.

methods (Access = protected)
   function flag = isInputDirectFeedthroughImpl(~,~)
      flag = false;
   end
end

Complete Class Definition File with Update and Output

classdef intDelaySysObj < matlab.System &...
     matlab.system.mixin.Nondirect &...
     matlab.system.mixin.CustomIcon
   % 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 

See Also

| | |

More About

Was this topic helpful?