How does c2d(...,method) compute the matrices Ad and Bd for both 'zoh' and 'foh' as method?

14 visualizzazioni (ultimi 30 giorni)
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
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
Md = 5×5
1.2193 0.3476 0.2742 0.1780 -0.0296 -0.0208 0.7957 -0.0433 -0.0368 -0.1408 -0.4311 -0.5133 0.5139 -0.0270 0.0438 0 0 0 1.0000 0 0 0 0 0 1.0000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

Accedi per commentare.

Risposte (2)

Pascal Gahinet
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.

Simon
Simon il 29 Gen 2025
Btw, I seem to have found out what c2d() does, yet, I'm not sure why it does what it does, at least in the 'foh' case.
First things first: 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, Cd, and Dd work for both 'zoh' and 'foh' as method?
This can be answered as follows:
In general, the input vector u is part of the input vector space U and the output vector y is part of the output vector space Y:
'zoh':
'foh':
This was verified by comparing the results of c2d() and of the formulas above. This was done by computing their results and their difference in MATLAB, which indeed was exactly 0.
Now the tricky part where there are still some open questions:
How did I find out (again, I was looking for formulas and not for code, as the code concerned derives from formulas and not the other way round):
I consulted the documentation of c2d() and its discretization methods.
First, the 'zoh' case: The documentation doesn't include any information on what exact procedure is used in this case. Thanks to Paul's comments, I found this explanation (p.31-34). I guess you could argue to not include this in the documentation as this is trivial when working in and familiar with this field, however, I wouldn't suggest such claim/assumption.
Second, the 'foh' case: The documentation refers to a book that can be found online here. However, it refers to the wrong page, and when you eventually find the right one, the listed formulas describe a SISO (Single Input Single Output) instead of a more general MIMO (Multiple Input Multiple Output) case and/or are faulty, e.g. there are 0s where there should be 1s. This makes me wonder whether the referenced source really is the best one to explain the discretization approach taken. After all, assuming that the chosen discretization approach is valid, there likely exist multiple sources to refer to, that are correct throughout and explain it well.
To conclude, I have not yet understood entirely where the 'foh' discretization approach is coming from, including that I am missing an intuitve explanation why Dd wouldn't match D, especially when D was 0. I still hope for the clarification of the situation.
  12 Commenti
Simon
Simon il 4 Feb 2025
The general solution is
where .
I agree that
together with the FOH input
results
.
This resembles
.
(The book gets the sign in front of Gamma1 wrong, as it is not coherent with (6.45).)
This yields the results for v and w as shown in the book. However, shouldn't we get the same results when integrating wdot, as is the case for v? I would understand the book's deduction if it only was for the opposite sign, yet, I don't understand the time shift that's happening, as again, they define and I would define , at least from the integration.
Paul
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);
Use ode45 to integrate over the 10 discrete intervals with this FOH assumption
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.').';
Use lsim to simulate the system. Explicitly specify the FOH approximation
[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.

Accedi per commentare.

Categorie

Scopri di più su Time and Frequency Domain Analysis in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by