How does c2d(...,method) compute the matrices Ad and Bd for both 'zoh' and 'foh' as method?
14 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Given a continuousTimeStateSpaceModel comprising the matrices A, B, C, and D (albeit D = 0) and given a sample time Ts, how does discreteTimeStateSpaceModel = c2d(continuousTimeStateSpaceModel,Ts,method) comprising the matrices Ad, Bd, C, and D work for both 'zoh' and 'foh' as method? As stated, I guess, C and D will remain unchanged in both cases, but how are Ad and Bd computed in each case?
i.e.
- 'zoh': Ad = ..., Bd = ...
- 'foh': Ad = ..., Bd = ...
Thanks in advance!
8 Commenti
Paul
il 21 Gen 2025
No, I meant I2. The lower right, or the second (2), partition is an identity matrix (I).
rng(100);
sysc = rss(3,1,2);
Ts = 0.1;
Mc = [sysc.a,sysc.b;zeros(2,3),zeros(2,2)]*Ts;
Md = expm(Mc);
Md
Risposte (2)
Pascal Gahinet
il 29 Gen 2025
Hi Simon
You are on the right track. ZOH and FOH is just analytic integration of the ODE:
dx/dt = A x(t) + B u(t)
under the assumption that u(t) is either piecewise constant (ZOH) or piecewise linear (FOH). In the ZOH case, u(t)=u[k] on the interval [k*Ts,(k+1)*Ts) so we have
d/dt [x;u] = [A B;0 0] * [x;u]
which integrates to
[x[k+1] ; u((k+1)*Ts)] = expm ([A B;0 0] * Ts) * [x[k] ; u[k]] .
We only use the first row since the values of u are given.
Things get more complicated with input and output delays and even more complicated with internal delays, but you got the idea.
0 Commenti
Simon
il 29 Gen 2025
12 Commenti
Paul
il 6 Feb 2025
Modificato: Paul
il 6 Feb 2025
I did not try to rederive all of the equations in 6.3.2, particuarly those for v[k] and w[k].
However, we can show by simulation that the equations in 6.3.2 appear to be correct, though there are several typos in 6.46 and 6.47, in addition to the one you found in the unnumbered equation just below 6.44.
Here we go ....
Define a harmless, second order, continuous-time system
A = diag([-1,-2]); B = [3;4]; C = [5,6]; D = 0;
Define the sample period and a 101-point time vector
Ts = 0.1;
k = 0:100;
tvec = k*Ts;
Define a random sequence of inputs
rng(100);
uvec = rand(size(tvec));
Define a function to evaluate u(t) with linear interpolation between the input sample points. With k*Ts <= t <= (k+1)*Ts, u(t) interpolates linearly between u[k] and u[k+1], i.e., our first-order, non-causal hold
u = @(t) interp1(tvec,uvec,t);
x(1,:) = [0 0];
for ii = 2:numel(k)
[~,xtemp] = ode45(@(t,x) A*x + B*u(t),[tvec(ii-1),tvec(ii)],x(ii-1,:),odeset('MaxStep',Ts/100));
x(ii,:) = xtemp(end,:);
end
y1 = (C*x.').';
[y2,~,x] = lsim(ss(A,B,C,D),uvec,tvec,[0 0],'foh');
Now implement the equations from section 6.3.2. I derived these starting from 6.44 using the stated solution
v[k] = u[k]
and
w[k] = u[k+1] - u[k].
These match equation 6.47 in the text after correcting many typos in 6.46 and 6.47
F = [A,B,zeros(2,1);0,0,0,1/Ts;0,0,0,0];
FT = expm(F*Ts);
Phi = FT(1:2,1:2); Gamma1 = FT(1:2,3); Gamma2 = FT(1:2,4);
Ak = Phi;
Bk = Gamma1 + Phi*Gamma2 - Gamma2;
Ck = C;
Dk = D + C*Gamma2;
Simulate these equations with lsim. It's important to understand that the state vector in these equations is NOT the state vector from the original system. Here, the state vector is z[k] = x[k] - Gamma2*u[k] (where x[k] is the state vector of the original system), so we need to adjust the initial condition in x[k] to the initial condition in z[k].
y3 = lsim(ss(Ak,Bk,Ck,Dk,Ts),uvec,tvec,[0 ; 0] - Gamma2*uvec(1));
Finally, simulate the c2d discretization, again accounting for the initial condition
y4 = lsim(c2d(ss(A,B,C,D),Ts,'foh'),uvec,tvec,[0 ; 0] - Gamma2*uvec(1));
All four results lie on top of each other
figure
plot(tvec,[y1,y2,y3,y4],'-o'),grid
Plot the differences. y2, y3, and y4 match exactly (at least to the precision of the plot), with the ode45 solution different by a very small amount.
figure
plot(tvec,y2-y3,tvec,y2-y4,tvec,y2-y1),grid
So it would appear that all three discrete-time approximations were all derived using w[k] = u[k+1] - u[k] as advertised, and they all very-well-approximate the solution to the continuous-time differential equation.
I did not try to see how these results for y3 would change if we derived the difference equations assuming w[k] = u[k] - u[k-1], but I don't think it will work out too nicely.
Vedere anche
Categorie
Scopri di più su Time and Frequency Domain Analysis in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





