Is there a typo in the documentation for n4sid?
2 views (last 30 days)
Show older comments
The documentation for n4sid contains the following code snippet. I believe the line u(k-1) = -K*y(k-2) + w(k); should read u(k-2) = -K*y(k-2) + w(k);.
N = 1000;
K = 0.5;
rng('default');
w = randn(N,1);
z = zeros(N,1);
u = zeros(N,1);
y = zeros(N,1);
e = randn(N,1);
v = filter([1 0.5],[1 1.5 0.7],e);
for k = 3:N
u(k-1) = -K*y(k-2) + w(k);
u(k-1) = -K*y(k-1) + w(k);
z(k) = 1.5*z(k-1) - 0.7*z(k-2) + u(k-1) + 0.5*u(k-2);
y(k) = z(k) + 0.8*v(k);
end
dat = iddata(y, u, 1);
0 Comments
Accepted Answer
Anjaneyulu Bairi
on 11 Jan 2025
Hi,
The first line in for loop should not be u(k-1). It should be u(k-2).
Please use below code to generate close loop data.
N = 1000;
K = 0.5;
rng('default');
w = randn(N,1);
z = zeros(N,1);
u = zeros(N,1);
y = zeros(N,1);
e = randn(N,1);
v = filter([1 0.5],[1 1.5 0.7],e);
for k = 3:N
u(k-2) = -K*y(k-2) + w(k-2);
u(k-1) = -K*y(k-1) + w(k-1);
z(k) = 1.5*z(k-1) - 0.7*z(k-2) + u(k-1) + 0.5*u(k-2);
y(k) = z(k) + 0.8*v(k);
end
dat = iddata(y, u, 1);
Hope it helps!
2 Comments
Steven Lord
on 13 Jan 2025
Please contact Technical Support directly using this link rather than simply waiting and hoping it is seen by Technical Support. [Yes, I am a MathWorks staff member. But no, I am not familiar with System Identification Toolbox and so cannot answer the question.]
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!