Skip to content

Commit 17aa35b

Browse files
authored
Add files via upload
1 parent f59826e commit 17aa35b

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

DOCUMENTATION.pdf

188 KB
Binary file not shown.

EXAMPLES.m

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
%% Copyright (c) 2021 Tamas Kis
2+
3+
% Examples for using the c2d_euler function.
4+
5+
6+
7+
%% SCRIPT SETUP
8+
9+
% clears variables and command window, closes all figures
10+
clear;
11+
clc;
12+
close all;
13+
14+
15+
16+
%% EXAMPLES
17+
18+
% continuous transfer function
19+
s = tf('s');
20+
Hs = (s+1)/(0.1*s+1);
21+
22+
% sampling period
23+
T = 0.25;
24+
25+
% discrete transfer function obtained via Euler transformations
26+
Hz_forward = c2d_euler(Hs,T,'forward')
27+
Hz_backward = c2d_euler(Hs,T,'backward')

c2d_euler.m

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
% c2d_euler Transforms a continuous transfer function to a discrete
2+
% transfer function using the forward and backward Euler methods.
3+
%
4+
% Hz = c2d_euler(Hs,T,'forward') returns the discrete transfer function
5+
% "Hz" obtained by applying the forward Euler (i.e. forward difference)
6+
% transformation to a continuous transfer function "Hs", where "T" is the
7+
% sampling period.
8+
%
9+
% Hz = c2d_euler(Hs,T,'backward') returns the discrete transfer function
10+
% "Hz" obtained by applying the backward Euler (i.e. backward difference)
11+
% transformation to a continuous transfer function "Hs", where "T" is the
12+
% sampling period.
13+
%
14+
% See also c2d
15+
%
16+
% MATLAB Central File Exchange:
17+
% GitHub: https://github.com/tamaskis/c2d_euler-MATLAB
18+
%
19+
% See "DOCUMENTATION.pdf" for additional documentation and examples.
20+
% Examples can also be found in EXAMPLES.m. Both of these files are
21+
% included with the download.
22+
%
23+
% Copyright (c) 2021 Tamas Kis
24+
% Last Update: 2021-04-10
25+
26+
27+
28+
%% FUNCTION
29+
30+
% INPUT: Hs - continuous transfer function
31+
% T - sampling period
32+
% type - 'forward' or 'backward'
33+
% OUTPUT: Hz - discrete transfer function
34+
function Hz = c2d_euler(Hs,T,type)
35+
36+
% symbolic variable for z;
37+
z = sym('z');
38+
39+
% specified Euler approximation of s
40+
if strcmp(type,'backward')
41+
s = (z-1)/(T*z);
42+
else
43+
s = (z-1)/T;
44+
end
45+
46+
% converts transfer function object to symbolic function object
47+
[num,den] = tfdata(Hs);
48+
Hz = poly2sym(cell2mat(num),z)/poly2sym(cell2mat(den),z);
49+
50+
% performs Euler transformation
51+
Hz = simplify(subs(Hz,s));
52+
53+
% obtains numerator and denominator of symbolic expression in MATLAB's
54+
% "polynomial form"
55+
[sym_num,sym_den] = numden(Hz);
56+
num = sym2poly(sym_num);
57+
den = sym2poly(sym_den);
58+
59+
% creates discrete transfer function object
60+
Hz = tf(num,den,T);
61+
62+
end

0 commit comments

Comments
 (0)