-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added additional return type, added example.
- Loading branch information
Showing
2 changed files
with
25 additions
and
5 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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] | ||
% | ||
|
@@ -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'); | ||
|
@@ -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 |