greyBoxRC.m 1.01 KB
Newer Older
hazrmard's avatar
hazrmard committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
% Estimates parameters of an RC circuit. Produces an
% `idgrey` instance called `sys` representing the 
% learned system parameters.
%
% See: https://www.mathworks.com/help/ident/ug/estimating-linear-grey-box-models.html
%
% Initial estimates of circuit parameters.
% The number of parameters should match the order
% of the system. That is, 2 parameters for a first
% order system cannot be solved.
par = {'resistance',500; 'capacitance', 1e-3};
% A grey box system with identifiable parameters.
sys_init = idgrey(@ssRC, par, 'c');
sys_init.Structure.Parameters(2).Free = false;

rcdat = load('resRC_comb.mat');
t = rcdat.data(:,1);    % timestamps
u = rcdat.data(:,2);    % input
y = rcdat.data(:,3);    % output
data = iddata(y, u, rcdat.resolution);
% Run a grey box estimate of the system using data
sys = greyest(data, sys_init);

fprintf('Parasysmeter value: %.5f\n', getpvec(sys));

% state-space representation of RC circuit
function [A, B, C, D] = ssRC(R, c, ~)
    A = [-1/(R*c)];
    B = [1/R];
    C = A;
    D = B;
end