% Simulate atmosphere and lidar signal
cloudlayer

% Pick a reference range
m = floor(0.9*N);
r_m = r(m) % units: km

% Estimate sigma at r_m
sigma_m = 3 % units: 1/km

% Estimate k
k_guess = k

% Invert the exact (noise-free) signal
sigma_ideal = klett_inversion(S_ideal, m, sigma_m, k_guess, dr);

% Invert the realistic, noisy signal
sigma_noised = klett_inversion(S, m, sigma_m, k_guess, dr);

figure(3)
hold off
plot(r, sigma, 'b-',               'linewidth', 2,...
     r, sigma_ideal, 'g-',         'linewidth', 2,...
     r, sigma_noised, 'r-',        'linewidth', 2,...
     [r_m,r_m],[-1,sigma_m],'k-o', 'linewidth',2)
hold on
xlabel('r (km)')
ylabel('\sigma (km^{-1})')
axis([0,rmax,0,1.1*max(sigma)])
legend('true', 'Klett inversion of ideal data',...
   'Klett inversion of noisy data', 'r_m, \sigma_m')

