Main Content

Use Update and Output for Nondirect Feedthrough

Implement nondirect feedthrough for a System object™ by using the updateImpl, outputImpl, and isInputDirectFeedthroughImpl methods. In nondirect feedthrough, the 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. These methods enable you to use the object in a feedback loop and prevent algebraic loops.

Subclass from the matlab.System Class

To use the updateImpl, outputImpl, and isInputDirectFeedthroughImpl methods, you must subclass from the matlab.System.

 classdef IntegerDelaySysObj < matlab.System 

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 
   % 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 > 0 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

Functions

Related Topics