You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: MagnetoShield_LQ_Simulation.m
    path of file: ./repos/AutomationShield/matlab/examples/MagnetoShield
    
    the code of the file until where you have to start completion: %   MAGNETOSHIELD LQ GAIN CALCULATION AND SIMULATION EXAMPLE
%
%   This example reads the linearized model of the MagnetoShield device,
%   then expands it with an integrator and then computes the LQ gain. This
%   LQ gain is used to create a simulation run for the trajectory tracking
%   of 
    
function
    Y(1,2) = x3;
    
%State estimation based on user option   
if strcmp(filter,'Kalman')
       [xhat, yhat] = estimateKalmanState(U(k), Y', A, B, modeld.c, Q_Kalman, R_Kalman, xICWhole); 
elseif strcmp(filter,'model')
       xhat = [x1; x2; x3];
elseif strcmp(filter,'difference')
       x2 = (x1 - x1p)/Ts;
       x1p=x1; 
       xhat = [x1; x2; x3];
end