Skip to content

Commit

Permalink
Added additional return type, added example.
Browse files Browse the repository at this point in the history
  • Loading branch information
tamaskis committed Oct 9, 2021
1 parent ad95113 commit 3937339
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
Binary file modified EXAMPLES.mlx
Binary file not shown.
30 changes: 25 additions & 5 deletions c2d_euler.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
% See also c2d.
%
% Copyright © 2021 Tamas Kis
% Last Update: 2021-08-27
% Last Update: 2021-10-09
% Website: https://tamaskis.github.io
% Contact: [email protected]
%
Expand All @@ -27,17 +27,31 @@
% ------
% INPUT:
% ------
% Hs - (tf) continous transfer function
% Hs - (1×1 tf or zpk) continous transfer function
% T - (1×1 double) sampling period
% type - (char) 'forward' or 'backward'
% output - (OPTIONAL) (char) specifies output type ('tf' or 'zpk')
%
% -------
% OUTPUT:
% -------
% Hz - (tf) discrete transfer function
% Hz - (1×1 tf or zpk) discrete transfer function
%
%==========================================================================
function Hz = c2d_euler(Hs,T,type)
function Hz = c2d_euler(Hs,T,type,output)

% ----------------------------------------------------
% Sets unspecified parameters to their default values.
% ----------------------------------------------------

% defaults "output" to 'tf'
if (nargin < 4) || isempty(output)
output = 'tf';
end

% --------------------------------------
% Continuous-to-discrete transformation.
% --------------------------------------

% symbolic variable for z;
z = sym('z');
Expand All @@ -62,7 +76,13 @@
num = sym2poly(sym_num);
den = sym2poly(sym_den);

% creates discrete transfer function object
% creates discrete transfer function model
Hz = tf(num,den,T);

% converts discrete transfer function model to discrete zero-pole-gain
% model if specified
if strcmpi(output,'zpk')
Hz = zpk(Hz);
end

end

0 comments on commit 3937339

Please sign in to comment.