%
%
%
% Optical Imaging and Spectroscopy
%
% David J. Brady
% Duke University
% www.opticalimaging.org
%
% Figure 9.15 and 9.16
%
%
%
% Ring pattern for a Fabry-Perot Spectrograph
%
%
%
%
% plot parameters
%
figure(1);set(gcf,'color','white');
figure(2);set(gcf,'color','white');
figure(3);set(gcf,'color','white');
figure(4);set(gcf,'color','white');
N=1024; % samples per axis
%
% etalon parameters
%
for F=10:10:40 %finesse
    C=4*F^2/pi^2; % coefficient of finesse
    umin=10;
    umax=12;
    %
    %
    % uniform sampling in u nu
    %
    nurange=linspace(.8,1.2,N);
    urange=linspace(umin,umax,N);
    [u,nu]=meshgrid(urange,nurange);
    hringnu=1./(1+C*sin(pi*nu.*u).^2);
    figure(1);
    subplot(2,2,F/10);
    imagesc(urange,nurange,hringnu);colormap gray;
    xlabel('u \nu_o');ylabel('\nu/\nu_o');axis square;
    title(['F= ' num2str(F)]);
    %
    %
    % svd of measurements
    %
    hp=hringnu*hringnu';
    %[u,L,v]=svd(hp);
    %L=L*[eye(256),zeros(256,N-256);zeros(N-256,N)];
    %hp=u*L*v';
    hp=pinv(hp)*hp;
    figure(2);
    subplot(2,2,F/10);
    imagesc(nurange,nurange,hp); colormap gray;
    title(['F= ' num2str(F)]);
    %figure(3);set(gcf,'color','white');
    %L=diag(L);L=L/max(L);
    %plot(L(1:150));
    %figure(4);set(gcf,'color','white');
    %plot(hp(N/2,:));
    % testV=0.01*zeros(N,1);testV(N/2,1)=1;
    % reV=hp*testV;
    figure(3);
    subplot(2,2,F/10);
    plot(nurange((N/2-40):(N/2+40)),hp((N/2-40):(N/2+40),N/2),'-k');
    axis([0.98 1.02 -.2,1]);  title(['F= ' num2str(F)]);
    figure(4);
    subplot(2,2,F/10);
    plot(nurange,hp(:,N/2),'-k');
     axis([0.8 1.2 -.2,.85]); title(['F= ' num2str(F)]);
end


