% Script to plot the suspension thermal noise of the ITMs
%
% Sean Leavey
% November 2015

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%% Change Log %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    %%%%% 09 Feb 2016, JSH
    % Added path to SSM design sensitivity data from design Paper
    % Added SSM design sensitivity to plot routine
    % Increased resolution of frequency vector (1000 -> 10000)

%% Paths
clear all;
% this script's directory
directory = fileparts(mfilename('fullpath'));

% parameter set
addpath(genpath([directory, '/../../IfoSimulations/Libs/SpeedMeterLib/']));

% design sensitivity (desgin paper)
addpath(genpath([directory, '/../reference_plots/ssm_design_paper/data/']));

%% Parameters

% frequency vector
f = logspace(-1, 5, 10000);

% parameters
par = SsmParameters('ideal');

% number of violin modes to calculate
nViolin = 100;

% beam offset
beamOffset = 0;

% vertical to horizontal coupling
vertToHorCoupling = 0.002;

% list of mirrors
mirrors = {'ETTm'};

%% Calculate noise

noises = zeros(length(mirrors), length(f) );

for i = 1 : length(mirrors)
    mirror = mirrors{i};
    
    noises(i, :) = calcSusThermNoise(...
        f, par, mirror, beamOffset, vertToHorCoupling, nViolin ...
    );
end

%% Load design sensitivity

load('fig2_SSM_data.mat');

%% Plot

figure;

% legend strings
legendText = cell(1, length(mirrors));

% plot each noise
for i = 1 : length(mirrors)
    % plot noise
    loglog(f, noises(i, :)*2/1e4);
    
    % set legend text
    legendText{i} = sprintf('%s', mirrors{i});
    
    % hold log scale
    hold on;
end

loglog(n_sag.Freq,sqrt(abs(n_sag.Total)),'black');

legendText{3} = sprintf('SSM design paper');

title('Test mass suspension thermal noise');
xlabel('Frequency (Hz)');
ylabel('Displacement noise (m / sqrt(Hz))');

% set legend
legend(legendText,  'Location', 'NorthEast');

grid on;
hold off;