function [A,B,C,D] = build_sistema_meccanico_3gdl(M1_stimato)


param_sistema_meccanico_3gdl;

if exist('M1_stimato')==1
  M1 = M1_stimato;
end

A=[-C1/M1    C1/M1        0       -K1/M1     K1/M1         0       ;    ...
    C1/M2 -(C1+C2)/M2   C2/M2      K1/M2  -(K1+K2)/M2    K2/M2     ;    ...
      0      C2/M3    -(C2+C3)/M3    0       K2/M3    -(K2+K3)/M3  ;    ...
      1        0          0          0         0           0       ;    ...
      0        1          0          0         0           0       ;    ...
      0        0          1          0         0           0       ];

config_attuatori = 1;
switch config_attuatori
  case 1, Bf = [1/M1; 0; 0];
  case 2, Bf = [0; 1/M1; 0];
  case 3, Bf = [0; 0; 1/M1];
end

% Caso con 1 ingresso esterno:
B=[Bf(1)  K1*delta_xg/M1;  ...
   Bf(2)  (K2*delta_xb-K1*delta_xg)/M2; ...
   Bf(3)  (K3*delta_xs-K2*delta_xb)/M3; ...
   0    0; ...
   0    0; ...
   0    0];

% Caso con 2 ingressi esterni:
%B=[1  0  K1*delta_xg/M1;  ...
%   0  1  (K2*delta_xb-K1*delta_xg)/M2; ...
%   0  0  (K3*delta_xs-K2*delta_xb)/M3; ...
%   0  0  0; ...
%   0  0  0; ...
%   0  0  0];
  
% scelgo la configurazione dei sensori
config_sensori = 4;
switch config_sensori
  case 1,   C=[0  0  0  1  0  0;  0  0  0  0  1  0;  0  0  0  0  0  1];   D=[0 0; 0 0; 0 0];
  case 2,   C=[0  0  0  1  0  0;  0  0  0  0  1  0];  D=[0 0; 0 0];
  case 3,   C=[0  0  0  1  0  -1;  0  0  0  0  1  -1];  D=[0 0; 0 0];
  case 4,   C=[0  0  0  1  0  0];  D=[0 0];
  case 5,   C=[0  0  0  0  1  0];  D=[0 0];
  case 6,   C=[0  0  0  0  0  1];  D=[0 0];
end;
  
  

