function [f,g,h,names,values]=dloudA_lit
% Symbolic model of a loudspeaker
%
% [F,G,H,NAMES,VALUES]=DLOUDA_LIT defines the literal symbolic linear-analytic
% state-space model x'= f(x) + g(x)u, y=hx of a loudspeaker.
% NAMES is a cell containing parameter names, used later to access a 
% structure of numerical parameter values.
% VALUES is a structure with default parameter values

% Based on:
%
% Passive Parametric Modeling of Dynamic Loudspeakers, Dietrich Fränken,
% Klaus Meerkötter, and Joachim Waßmuth, IEEE -TSAP 11/2001
%
% Observer-based feedback linearization of dynamic loudspeakers with Ac amplifiers,
% Dietrich Fränken,Klaus Meerkötter, and Joachim Waßmuth, IEEE -TSAP 03/2005
%

%   CBVK Toolbox
%   JHMG, PMSB 2016


% The L (nonlinear inductance) is approximated by the analytic function:
L = sym('b0+b1*atan(w*x01+phi)');
Lp = diff(L,'x01');

% Rest of the model:
k = sym('k0+k1*(x01-Xk)^2');
A = sym('a0/(1+a1*(x01-Xa)^2)');

% State-space equations
% x' = f(x) + g(x)*u

f1 = sym('x02');
f2 = sym('(1/M)*(-k*x01-G*x02+A*x03+.5*(x03)^2*Lp)');
f3 = sym('(-1/L)*(R*x03+Lp*x02*x03+A*x02)');

% Substitute L, Lp, k and A
%f2 = subs(f2);   This would use the global workspace
%f3 = subs(f3);

f2=subs(f2,'Lp',Lp);
f2=subs(f2,'k',k);
f2=subs(f2,'A',A);

f3=subs(f3,'Lp',Lp);
f3=subs(f3,'L',L);
f3=subs(f3,'A',A);

f = [f1;f2;f3];

g = [sym(0);sym(0);subs(sym('(1/L)'))];

h=[1 0 0];

names={'G','M','R','a0','a1','b0','b1','k0','k1','phi','w','Xa','Xk'};
values=struct('G',0.8319,'M',0.003,'R',4.6254,'a0',2.6607,'a1',92000,...
    'b0',2.423e-5,'b1',-1.303e-5,'k0',675.30,'k1',67500000,'phi',0.4089,'w',419.2,...
    'Xa',-3.463e-4,'Xk',7.618e-4);


