Non linear greybox modelling: iddata - input arguments

12 views (last 30 days)
Warning and error: SIP Warning: There are more output channels in the data object than samples. Check if the output data matrix should be transposed. > In warning at 26 In @iddata\private\datachk at 35 In iddata.iddata at 192 In SIP at 10 Warning: There are more output channels in the data object than samples. Check if the output data matrix should be transposed. > In warning at 26 In @iddata\private\datachk at 35 In iddata.pvset at 138 In iddata.set at 143 In iddata.iddata at 227 In SIP at 10 ipfd Error using iddata (line 229) The number of elements in the "OutputUnit" property value must be equal to the number of output channels. Use a cell array of 1000000 string(s).
Error in SIP (line 10) sway = iddata(O, [], 0.001, 'Name', 'Sway', 'OutputUnit', 'rad');
Error using ipfd (line 34) Not enough input arguments.
%%An inverted pendulum model directly applied to normal human gait
%Model predicts values of ground reaction forces and velocity of human gait.
%An inverted pendulum is defined basing on the average center-of-pressure
%to the instantaneous center-of-mass and equations of motion during single
%support that allowed a telescoping action were derived.
%%Data
load('O');
sway = iddata(O, [], 0.001, 'Name', 'Sway', 'OutputUnit', 'rad');
set(sway, 'Tstart', 0, 'TimeUnit', 's');
load('r');
leg = iddata(r, [], 0.001, 'Name', 'Leg length', 'OutputUnit', 'm');
set(leg, 'Tstart', 0, 'TimeUnit', 's');
stab = load('stab');
%stab = [g, w0, dt, m]
g = stab(1);
set(g, 'OutputName', 'Gravity constant');
set(g, 'OutputUnit', 'm/s^2');
w0 = stab(2);
set(w0, 'OutputName', 'Initial angular velocity');
set(w0, 'OutputUnit', 'rad/s');
dt = stab(3);
set(dt, 'OutputName', 'Integration step');
set(dt, 'OutputUnit', 's');
m = stab(4);
set(m, 'OutputName', 'Weight');
set(m, 'OutputUnit', 'kg');
%%Pendulum Modeling
% This paragraph presents a model structure for the pendulum system.
% The forward and inverse dynamics of it was studied by the same authors
%before. The structure is as follows:
%
%a(i) = (-g*cos(O(i))/r
%w(i+1) = w(i) + a(i)*dt
%O(i+1) = O(i) + w(i)*dt + 1/2*a(i)*dt^2
%Fh = m*[r''-r*w^2)*cos(O) - (r*a+2*r'*w)*sin(O))]
%Fv = m*[r''-r*w^2)*sin(O) - (r*a+2*r'*w)*cos(O))] + m*g
%v = w*r*sin(O)
%
% having parameters (or constants):
% a - angular acceleration [rad/s^2]
% g - the gravity constant [m/s^2]
% O - sway [rad]
% r - the length of the leg [m]
% w - angular velocity [rad/s]
% dt - integration steps [s]
% m - the weight [kg]
% Fh - horizontal ground reaction force [
% Fv - vertical ground reaction force
% v - velocity
%We enter this information into the MATLAB file ipfd.m.
The next step is to create a generic IDNLGREY object for describing the pendulum. We also enter information about the names and the units of the inputs, states, outputs and parameters. Owing to the physical reality all model parameters must be positive and this is imposed by setting the 'Minimum' property of all parameters to the smallest recognizable positive value in MATLAB®, eps(0).
FileName = 'ipfd'; % File describing the model structure.
Order = [1 0 2]; % Model orders [ny nu nx]. ???
Parameters = [g; w0; d; m]; % Initial parameters.
InitialStates = [1; 0]; % Initial states.
Ts = 0; % Time-continuous system.
nlgr = idnlgrey(FileName, Order, Parameters, InitialStates, Ts);
%Output [Fx, Fy, v, x, y]
set(nlgr, 'OutputName', {'Horizontal ground reaction force' 'Vertical ground reaction force' 'velocity' 'Horizontal position' 'Vertical position'}, ...
'OutputUnit', {'N' 'N' 'm/s' 'm' 'm'}, ...
'TimeUnit', 's'); %output
nlgr = setinit(nlgr, 'Name', {'Sway' 'Leg length'});
nlgr = setinit(nlgr, 'Unit', {'rad' 'm'});
nlgr = setpar(nlgr, 'Name', {'Gravity constant' 'Integration step' ...
'Initial angular velocity' 'Mass'}); %parameters
nlgr = setpar(nlgr, 'Unit', {'m/s^2' 's' 'rad/s' 'kg'}); %units
nlgr = setpar(nlgr, 'Minimum', {eps(0) eps(0) eps(0) eps(0)}); % All parameters > 0.
%%Performance of Pendulum Model
% Before trying to estimate any parameter we simulate the system with the
% guessed parameter values. The solver used is Runge-Kutta 45 with adaptive
%step length(ode45). The Runge-Kutta 45 (ode45) solver often returns high
%quality results relatively fast, and is therefore chosen as the default
%differential equation solver in IDNLGREY.
% C. Model computed with adaptive Runge-Kutta 45 ODE solver.
nlgrrk45 = nlgr;
nlgrrk45.Algorithm.SimulationOptions.Solver = 'ode45'; % Runge-Kutta 45.
%%Parameter Estimation
%Some parameters fixed, other not for simulation
nlgrrk45 = setpar(nlgrrk45, 'Fixed', {true true false true});
trk45 = clock;
nlgrrk45 = pem(z, nlgrrk45, 'Display', 'Full'); % Perform parameter estimation.
trk45 = etime(clock, trk45);
disp(' Estimation time Estimated value');
fprintf(' ode45: %3.1f %1.3f\n', trk45, nlgrrk45.Parameters(3).Value);
%the Final Prediction Error (FPE) criterion
fpe(nlgrrk45);
figure
t = linspace(0, 1000, 1000000);
subplot(3,1,1);
plot(t,Fh)
subplot(3,1,2);
plot(t,Fv)
subplot(3,1,3);
plot(t,v)
  1 Comment
Walter Roberson
Walter Roberson on 3 Jun 2015
This code makes use of material from the paper,
Performance of an inverted pendulum model directly applied to normal human gait. Buczek FL, Cooney KM, Walker MR, Rainbow MJ, Concha MC, Sanders JO. Performance of an inverted pendulum model directly applied to normal human gait. Clin Biomech (Bristol, Avon). 2006 Mar; 21(3):288-96.
There does not appear to a free version of the paper available.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 25 May 2015
Each of the places you have a single OutputUnit, such as
sway = iddata(O, [], 0.001, 'Name', 'Sway', 'OutputUnit', 'rad');
change that to be a cell array containing the string:
sway = iddata(O, [], 0.001, 'Name', 'Sway', 'OutputUnit', {'rad'});
It appears that the content of O is a row vector. You need to pass in a column vector instead of a row vector.
sway = iddata(O.', [], 0.001, 'Name', 'Sway', 'OutputUnit', {'rad'});
You might encounter the same difficulty in the other datasets. If you know that they are each vectors but you do not know the orientation, then you can force column vector by
sway = iddata(O(:), [], 0.001, 'Name', 'Sway', 'OutputUnit', {'rad'})
  45 Comments
Walter Roberson
Walter Roberson on 3 Jun 2015
Sway as input version.
function [dx, Y] = ipfd(t, x, u, p1, p2, p3, varargin)
%A pendulum system
%Model:
%a(i) = (-g*cos(O(i))/r
%w(i+1) = w(i) + a(i)*dt
%O(i+1) = O(i) + w(i)*dt + 1/2*a(i)*dt^2
%Fh = m*[r''-r*w^2)*cos(O) - (r*a+2*r'*w)*sin(O))]
%Fv = m*[r''-r*w^2)*sin(O) - (r*a+2*r'*w)*cos(O))] + m*g
%v = w*r*sin(O)
%states
wi = x(1);
old_r = x(2); %previous r
old_dr = x(3); %previous r'
%inputs
r = u(1);
Oi = x(2);
%parameters
g = p1;
dt = p2;
m = p3;
%State equations
a = (-g .* cos(Oi)) ./ r; %angular acceleration, not output
w = wi + a .* dt; %Angular velocity
O = Oi + wi .* dt + 1/2 .* a .* (dt.^2);
dr = (r - old_r) ./ dt;
ddr = (dr - old_dr) ./ dt;
%Output equations
mrr = (ddr - r .* w.^2);
rarw = (r .* a + 2 .* dr .* w);
Fx = m .* (mrr .* cos(O) - rarw .* sin(O));
Fy = m .* (mrr .* sin(O) - rarw .* cos(O)) + m .* g;
v = w*r*sin(O);
x = r*cos(O);
y = r*sin(O);
dx = [w; r; dr];
Y = [Fx; Fy; v; x; y];
end
Corresponding driver:
%%An inverted pendulum model directly applied to normal human gait
%Model predicts values of ground reaction forces and velocity of human gait.
%An inverted pendulum is defined basing on the average center-of-pressure
%to the instantaneous center-of-mass and equations of motion during single
%support that allowed a telescoping action were derived.
%%Data
load('O');
% O = iddata(O.', [], 0.001, 'Name', 'Loaded O', 'InputName', {'Sway'}, 'InputUnit', {'rad'});
% set(sway, 'Tstart', 0, 'TimeUnit', 's');
load('r');
% leg = iddata([], r.', 0.001, 'Name', 'Loaded r', 'InputName', {'Leg Length'}, 'InputUnit', {'m'});
% set(leg, 'Tstart', 0, 'TimeUnit', 's');
leg_sway = iddata([], [r(:), O(:)], 0.001, 'Name', 'Loaded r O', 'InputName', {'Leg Length', 'Sway'}, 'InputUnit', {'m', 'rad'});
set(leg_sway, 'Tstart', 0, 'TimeUnit', 's');
%%Pendulum Modeling
% This paragraph presents a model structure for the pendulum system.
% The forward and inverse dynamics of it was studied by the same authors
%before. The structure is as follows:
%
%a(i) = (-g*cos(O(i))/r
%w(i+1) = w(i) + a(i)*dt
%O(i+1) = O(i) + w(i)*dt + 1/2*a(i)*dt^2
%Fh = m*[r''-r*w^2)*cos(O) - (r*a+2*r'*w)*sin(O))]
%Fv = m*[r''-r*w^2)*sin(O) - (r*a+2*r'*w)*cos(O))] + m*g
%v = w*r*sin(O)
%
% having parameters (or constants):
% a - angular acceleration [rad/s^2]
% g - the gravity constant [m/s^2]
% O - sway [rad]
% r - the length of the leg [m]
% w - angular velocity [rad/s]
% dt - integration steps [s]
% m - the weight [kg]
% Fh - horizontal ground reaction force [
% Fv - vertical ground reaction force
% v - velocity
%We enter this information into the MATLAB file ipfd.m.
The next step is to create a generic IDNLGREY object for describing the pendulum. We also enter information about the names and the units of the inputs, states, outputs and parameters. Owing to the physical reality all model parameters must be positive and this is imposed by setting the 'Minimum' property of all parameters to the smallest recognizable positive value in MATLAB®, eps(0).
FileName = 'ipfd'; % File describing the model structure.
Order = [5 2 3]; % Model orders [ny nu nx].
%Vector [Ny Nu Nx], specifying the number of model outputs Ny, inputs Nu,
%and states Nx.
w0 = 5.86;
g = 9.81;
dt = 0.001;
m = 39.3;
Parameters = [g; dt; m]; % Initial parameters. %CHANGED
InitialStates = [w0; r(1), 0]; % Initial states.
Ts = 0; % Time-continuous system.
nlgr = idnlgrey(FileName, Order, Parameters, InitialStates, Ts);
%Output [Fx, Fy, v, x, y]
set(nlgr, 'OutputName', {'Horizontal ground reaction force' 'Vertical ground reaction force' 'velocity' 'Horizontal position' 'Vertical position'}, ...
'OutputUnit', {'N' 'N' 'm/s' 'm' 'm'}, ...
'TimeUnit', 's'); %output
nlgr = setinit(nlgr, 'Name', {'Angular Velocity', 'Old r', 'Old dr'});
nlgr = setinit(nlgr, 'Unit', {'rad/s', 'm', 'm/s'});
nlgr = setpar(nlgr, 'Name', {'Gravity constant', 'Integration step', 'Mass'}); %parameters
nlgr = setpar(nlgr, 'Unit', {'m/s^2', 's', 'kg'}); %units
nlgr = setpar(nlgr, 'Minimum', {eps(0) eps(0) eps(0)}); % All parameters > 0.
%%Simulation
%Simulation before estimating parameters
%the output of sim() should be an iddata object with as many
%output channels as there are output parameters. The
%documentation implies that it would have no input channels
%Y = sim(nlgr, leg_sway);
sim(nlgr, leg_sway);
%{
%block commented out
figure
plot(Y(:,1,1)); %plot Fh
title('plot of Fh');
figure
plot(Y(:,1,2)); %plot Fv
title('plot of Fv');
%}
Walter Roberson
Walter Roberson on 3 Jun 2015
I have not figured out plotting. That's why I left it as sim() with no outputs (which causes plotting) and commented out the rest.

Sign in to comment.

More Answers (0)

Categories

Find more on Grey-Box Model Estimation 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!