>> size(output_data(1:L-1,:))
ans =
3359 1
>> size(U1)
ans =
1000 1
>>
>> output_data(1:L-1,:) * U1;
Error using *
Inner matrix dimensions must agree.
% Load experimental input-output data
load('data.mat');
input_data = input;
output_data = Output2;
% Define the number of inputs and outputs
num_inputs = 1;
num_outputs = 1;
% Define the order of the model
n = 2; % number of states
m = 1; % number of inputs
p = 1; % number of outputs
% Construct the Hankel matrix
L = 1000; % number of rows in the Hankel matrix
H = hankel(input_data(1:L), input_data(L:end));
% Apply the least squares method to estimate the model parameters
[U,S,V] = svd(H, 'econ');
U1 = U(:, 1:n);
U2 = U(:, n+1:end);
S1 = S(1:n, 1:n);
S2 = S(n+1:end, n+1:end);
V1 = V(:, 1:n);
V2 = V(:, n+1:end);
Ahat = U2 * pinv(S2) * V2' * output_data(1:L-1,:) * U1;
% compute Ahat
Ahat = U2 * pinv(S2) * V2' * output_data(1:L-1,:) * U1';
%Ahat = U2*S2^(-1/2)*V2'*U1'*output_data(1:L-1)';
Bhat = U2*S2^(1/2)*V2(1:num_inputs, :)';
Chat = output_data(1:p)*Bhat*S2^(-1/2)*V2(:, 1:p)';
Dhat = output_data(1:p)*Bhat*S2^(1/2)*V2(1:num_inputs, 1:p);