FigDir = ['../../fig'];

FlagExp0 = 0;
FlagExp1 = 1;
FlagExp2 = 1;
FlagExp3 = 1;
curdir        = pwd;

Cfile   = mfilename('fullpath');
Cfile   = [Cfile '.m'];
copyfile(Cfile,FigDir);

PaperSize = [12, 5];
PaperSizeME = [12 8];
FONTS      = 20;
fcaxis          = [1.48,5];

velfile = {'/scratch/slim/zfang/Model/BG2D/BG450kmTrue.mat', ...
    '/scratch/slim/zfang/Model/BG2D/Ini_Vel.mat'};

strfile = {'BG_TrueModel', ...
    'BG_InitialModel'};

strtitle = {'True Model', ...
    'Initial Model'};


for i = 1:length(velfile)
    [A n d o] = ReadAllData(velfile{i});
    [z ,x]    = odn2grid(o,d,n);
    figure; set(gca,'fontsize',FONTS);imagesc(x,z,A);
    xlabel('Lateral [m]'); ylabel('Depth [m]');
    set(gca,'fontsize',FONTS);hc=colorbar; set(hc,'fontsize',FONTS);title(hc,'km/s');
    %; title(strtitle{i})
    caxis(fcaxis);fidx=gcf;
    PrintFigure(fidx,PaperSize,[FigDir '/' strfile{i}]);
end

if FlagExp0 > 0;
        Velfile = {'/scratch/slim/zfang/Model/SimpleLayer/SimpleLayerkm.mat', ...
                           '/scratch/slim/zfang/Model/SimpleLayer/Ini_Vel.mat', ...
                           '/scratch/slim/zfang/Result/WRI_SRCEST/PaperForJournal/Layer_WrongSrc_15Hz/m_2.mat', ...
                           '/scratch/slim/zfang/Result/WRI_SRCEST/PaperForJournal/Layer_TrueSrc2_15Hz/m_2.mat' };
                           
        str = {'Ture', 'Ini', 'Wrong', 'Correct'};
        
        for i = 1:length(Velfile);
                [A ns ds os] = ReadAllData(Velfile{i});
                [zz,xx]     = odn2grid(os,ds,ns);
                figure;imagesc(xx,zz,A);caxis([1,3]);set(gca,'fontsize',FONTS);
                 xlabel('Lateral [m]'); ylabel('Depth [m]');
                set(gca,'fontsize',FONTS);hc=colorbar; set(hc,'fontsize',FONTS);title(hc,'km/s');
                fidx=gcf;
                PrintFigure(fidx,PaperSize,[FigDir '/Layer_V' str{i} ]);
                         
        end
        
        f    = 15;
        t0t = 0.3;
        t0w = 0.32;
        fw    = 14;
        dt    = 0.004;
        nt    = 501;
        
        wt   = getrick(f,t0t,dt,nt);
        ww   = getrick(fw,t0w,dt,nt);
        [tt]  = odn2grid(0,dt,nt);
        figure; plot(tt,[wt(:)],'linewidth',2,'linestyle','-.');hold on;plot(tt(:),ww(:),'linewidth',2,'linestyle','--')
        set(gca,'fontsize',FONTS);legend('Correct Source','Wrong Source');
        xlabel('Time [s]'); set(gca,'fontsize',FONTS);xlim([0,2]);
        fidx=gcf;
        PrintFigure(fidx,PaperSize,[FigDir '/Layer_SrcCmp'  ]);



end



if FlagExp1 > 0;
    
    RstTrueSrcDir = '/scratch/slim/zfang/Result/WRI_SRCEST/PaperForJournal/WithSrcEstFreq_TrueSrc_20Hz';
    RstEstSrcDir     = '/scratch/slim/zfang/Result/WRI_SRCEST/PaperForJournal/WithSrcEstFreq_EstSrc_20Hz';
    
    ves_file = '/scratch/slim/zfang/Result/WRI_SRCEST/PaperForJournal/WithSrcEstFreq_TrueSrc_20Hz/m_11.mat';
    vts_file  = '/scratch/slim/zfang/Result/WRI_SRCEST/PaperForJournal/WithSrcEstFreq_EstSrc_20Hz/m_11.mat';
    vesP_file = '/scratch/slim/zfang/Result/WRI_SRCEST/PaperForJournal/WithSrcEstFreq_EstSrc_20Hz_Pratt/m_11.mat';
    est_src  = ReadAllData('/scratch/slim/zfang/Result/WRI_SRCEST/PaperForJournal/WithSrcEstFreq_EstSrc_20Hz/EstSrcWave.mat');
    est_srcP = ReadAllData('/scratch/slim/zfang/Result/WRI_SRCEST/PaperForJournal/WithSrcEstFreq_EstSrc_20Hz_Pratt/EstSrcWave.mat');
    
    ves          = ReadAllData(ves_file);
    vts           = ReadAllData(vts_file);
    vesP       = ReadAllData(vesP_file);
    
    freq        = [2:0.5:29.5];
    f0             = 20;
    t0             = 0.5;
    flagErr   = 0;
    flagModel = 1;
    flagGradient = 0;
    
    if flagGradient > 0
        gt_file = '/scratch/slim/zfang/Result/WRI_SRCEST/PaperForJournal/WithSrcEstFreq_EstSrc_20Hz/G_t.mat';
        gw_file = '/scratch/slim/zfang/Result/WRI_SRCEST/PaperForJournal/WithSrcEstFreq_EstSrc_20Hz/G_w.mat';
        ge_file = '/scratch/slim/zfang/Result/WRI_SRCEST/PaperForJournal/WithSrcEstFreq_EstSrc_20Hz/G_e.mat';
        [gt, n, d, o] = ReadAllData(gt_file);
        [gw, n, d, o] = ReadAllData(gw_file);
        [ge, n, d, o] = ReadAllData(ge_file);
        
        figure; set(gca,'fontsize',FONTS);imagesc(x,z,gt);
        xlabel('Lateral [m]'); ylabel('Depth [m]');
        set(gca,'fontsize',FONTS);hc=colorbar; set(hc,'fontsize',FONTS);caxis([-2,2]*1e4);
        %; title(strtitle{i})
        fidx=gcf;
        PrintFigure(fidx,PaperSize,[FigDir '/G_truesrc' ]);
        
        figure; set(gca,'fontsize',FONTS);imagesc(x,z,gw);
        xlabel('Lateral [m]'); ylabel('Depth [m]');
        set(gca,'fontsize',FONTS);hc=colorbar; set(hc,'fontsize',FONTS);caxis([-2,2]*1e4);
        %; title(strtitle{i})
        fidx=gcf;
        PrintFigure(fidx,PaperSize,[FigDir '/G_wrongsrc' ]);
        
        figure; set(gca,'fontsize',FONTS);imagesc(x,z,ge);
        xlabel('Lateral [m]'); ylabel('Depth [m]');
        set(gca,'fontsize',FONTS);hc=colorbar; set(hc,'fontsize',FONTS);caxis([-2,2]*1e4);
        %; title(strtitle{i})
        fidx=gcf;
        PrintFigure(fidx,PaperSize,[FigDir '/G_estsrc' ]);
        
    
    end 
    
    
    if flagModel > 0
    
    src_true = fwi_wavelet(freq,t0,f0);
    
    bb  = norm(est_src(1,:)) / norm(est_srcP);
    est_srcP = est_srcP*bb;
    
    
    
    figure;set(gca,'fontsize',20);plot(freq(:), abs([src_true(:)]), '--+','linewidth',2); hold on;
    plot(freq(:), abs(vec(est_src(1,:))),'o', 'linewidth',2);
    plot(freq(:), abs([est_srcP(:)]), ':x','linewidth',2,'color','black');
    h = legend('True source','Estimated source by VP', 'Estimated source by Initial model','Location','SouthEast');
    set(h,'fontsize',12);
    xlabel('Frequency [Hz]','fontsize',20);
    ylabel('Amplitude','fontsize',20);
    str = [FigDir '/Freq_SrcCmp_Amp_all'];
    set(gca,'fontsize',20);xlim([0 32])
    PrintFigure(gcf,[7,5],str);
    
    figure;set(gca,'fontsize',20);plot(freq(:), abs([src_true(:)]), '--+','linewidth',2); hold on;
    plot(freq(:), abs(vec(est_src(1,:))),'o', 'linewidth',2);
    h = legend('True source','Estimated source by VP','Location','SouthEast');
    set(h,'fontsize',12);
    xlabel('Frequency [Hz]','fontsize',20);
    ylabel('Amplitude','fontsize',20);
    str = [FigDir '/Freq_SrcCmp_Amp'];
    set(gca,'fontsize',20);xlim([0 32])
    PrintFigure(gcf,[7,5],str);
    
    aa = angle(vec(est_src(1,:)));
    ii   =find(aa>2);
    aa(ii) = aa(ii) - 2*pi;
    figure;set(gca,'fontsize',20);
    freq1         = [2:0.1:31];
    src_true1 = fwi_wavelet(freq1,t0,f0);
 %   plot(freq1(:), angle([src_true1(:)]), '--','linewidth',2,'color','red');hold on
    aa = angle([src_true(:)]);
    ii   =find(aa>2);
    aa(ii) = aa(ii) - 2*pi;
    bb = angle(est_srcP);
    id = find(bb >2); 
    bb(id) = bb(id)-2*pi;
    plot(freq(:), aa, '+','linewidth',2);hold on;
    plot(freq(:), aa,'o', 'linewidth',2,'color','red');
    plot(freq(:), bb, 'x','linewidth',2,'color','black');
    h = legend('True source','Estimated source by VP',  'Estimated source by initial model');
    set(h,'fontsize',12);
    xlabel('Frequency [Hz]','fontsize',20);
    ylabel('Phase','fontsize',20);
    str = [FigDir '/Freq_SrcCmp_Phase_all'];
    set(gca,'fontsize',20);xlim([0 32]);ylim([-4 4])
    PrintFigure(gcf,[7,5],str);
    
    figure;set(gca,'fontsize',20);
    plot(freq(:), aa, '+','linewidth',2);hold on;
    plot(freq(:), aa,'o', 'linewidth',2,'color','red');
    h = legend('True source','Estimated source by VP');
    set(h,'fontsize',12);
    xlabel('Frequency [Hz]','fontsize',20);
    ylabel('Phase','fontsize',20);
    str = [FigDir '/Freq_SrcCmp_Phase'];
    set(gca,'fontsize',20);xlim([0 32]);ylim([-4 4])
    PrintFigure(gcf,[7,5],str);
    
    figure; set(gca,'fontsize',FONTS);imagesc(x,z,ves);
    xlabel('Lateral [m]'); ylabel('Depth [m]');
    set(gca,'fontsize',FONTS);hc=colorbar; set(hc,'fontsize',FONTS);title(hc,'km/s');
    %; title(strtitle{i})
    caxis(fcaxis);fidx=gcf;
    PrintFigure(fidx,PaperSize,[FigDir '/vel_freq_estsrc' ]);
    
    figure; set(gca,'fontsize',FONTS);imagesc(x,z,vts); caxis(fcaxis);fidx=gcf;
    xlabel('Lateral [m]'); ylabel('Depth [m]');
    set(gca,'fontsize',FONTS);hc=colorbar; set(hc,'fontsize',FONTS);title(hc,'km/s');
    PrintFigure(fidx,PaperSize,[FigDir '/vel_freq_truesrc' ]);
    
    figure; set(gca,'fontsize',FONTS);imagesc(x,z,vesP); caxis(fcaxis);fidx=gcf;
    xlabel('Lateral [m]'); ylabel('Depth [m]');
    set(gca,'fontsize',FONTS);hc=colorbar; set(hc,'fontsize',FONTS);title(hc,'km/s');
    PrintFigure(fidx,PaperSize,[FigDir '/vel_freq_estsrcP' ]);
    
    figure; set(gca,'fontsize',FONTS);imagesc(x,z,abs(ves-vts)./vts);
    xlabel('Lateral [m]'); ylabel('Depth [m]');fidx=gcf;
    set(gca,'fontsize',FONTS);hc=colorbar; set(hc,'fontsize',FONTS);title(hc,'km/s');colormap redblue
    PrintFigure(fidx,PaperSize,[FigDir '/reldiff_freq_truesrc' ]);
    
    end
    
    if flagErr > 0
        vt = ReadAllData('/scratch/slim/zfang/Model/BG2D/BG450kmTrue.mat');
        vi = ReadAllData('/scratch/slim/zfang/Model/BG2D/Ini_Vel.mat');
        cd(RstTrueSrcDir);
        k = 1;
        for i = 1:11
            cd(['xm' num2str(i)]);
            for j = 1:21
                xx         = load(['x_' num2str(j) '.dat']);
                METrue(k) = norm(1./sqrt(xx)-vt(:));
                k         = k+1;
            end
            cd('../')
        end
        
        cd(RstEstSrcDir);
        k = 1;
        for i = 1:11
            cd(['xm' num2str(i)]);
            for j = 1:21
                xx         = load(['x_' num2str(j) '.dat']);
                MEEst(k)  = norm(1./sqrt(xx)-vt(:));
                k         = k+1;
            end
            cd('../')
        end
        cd(curdir)
        
        METrue = METrue / norm(vi-vt);
        MEEst = MEEst / norm(vi-vt);
        
        figure;set(gca,'fontsize',20);plot([METrue(:) MEEst(:)],'linewidth',3);xlabel('Iteration');ylabel('Relative Model Error');legend('Ture Source Wavelet', 'Estimated Source Wavelet');set(gca,'fontsize',FONTS)
        fidx = gcf;PrintFigure(fidx, PaperSizeME, [FigDir '/ModelErrorComp'])
        
    end
        
end


if FlagExp2 > 0;
    
    RstTrueSrcDir = '/scratch/slim/zfang/Result/WRI_SRCEST/PaperForJournal/TrueSrc';
    RstEstSrcDir     = '/scratch/slim/zfang/Result/WRI_SRCEST/PaperForJournal/WithSrcEst';
    
    ves_file = '/scratch/slim/zfang/Result/WRI_SRCEST/PaperForJournal/WithSrcEst_TimeData_50pml/m_11.mat';
    vts_file  = '/scratch/slim/zfang/Result/WRI_SRCEST/PaperForJournal/TrueSrc/m_11.mat';
    vesP_file = '/scratch/slim/zfang/Result/WRI_SRCEST/PaperForJournal/WithSrcEstFreq_EstSrc_20Hz_Pratt_Time/m_11.mat';
    est_src  = ReadAllData('/scratch/slim/zfang/Result/WRI_SRCEST/PaperForJournal/WithSrcEst_TimeData_50pml/EstSrcWave.mat');
    est_srcP = ReadAllData('/scratch/slim/zfang/Result/WRI_SRCEST/PaperForJournal/WithSrcEstFreq_EstSrc_20Hz_Pratt_Time/EstSrcWave.mat');
    
    ves          = ReadAllData(ves_file);
    vesP       = ReadAllData(vesP_file);
%    vts           = ReadAllData(vts_file);
    
    freq        = [2:0.5:29.5];
    f0             = 20;
    t0             = 0.5;
    flagErr   = 0;
    
    src_true = -fwi_wavelet(freq,t0,f0);
    est_src   = est_src(1,1:56);
    
    
    aa                = norm(vec(est_src)) / norm(src_true);
    
    figure;set(gca,'fontsize',20);plot(freq(:), abs([aa*src_true(:)]), '--+','linewidth',2);hold on;
    plot(freq(:), abs(vec(est_src(1,:))),'o', 'linewidth',2);    
    h = legend('True source', 'Estimated source by VP' ,'Location','SouthEast');
    set(h,'fontsize',12);
    xlabel('Frequency [Hz]','fontsize',20);
    ylabel('Amplitude','fontsize',20);
    str = [FigDir '/Time_SrcCmp_Amp'];
    set(gca,'fontsize',20);xlim([0 32])
    PrintFigure(gcf,[7,5],str);
   
   
    bb = norm(est_src)/norm(est_srcP);
    est_srcP = est_srcP*bb;
    figure;set(gca,'fontsize',20);plot(freq(:), abs(aa*[src_true(:)]), '--+','linewidth',2); hold on;
    plot(freq(:), abs(vec(est_src(1,:))),'o', 'linewidth',2);
    plot(freq(:), abs([est_srcP(:)]), ':x','linewidth',2,'color','black');
    h = legend('True source','Estimated source by VP', 'Estimated source by Initial model','Location','SouthEast');
    set(h,'fontsize',12);
    xlabel('Frequency [Hz]','fontsize',20);
    ylabel('Amplitude','fontsize',20);
    str = [FigDir '/Time_SrcCmp_Amp_all'];
    set(gca,'fontsize',20);xlim([0 32])
    PrintFigure(gcf,[7,5],str);
    
    a_est_src =  angle(vec(est_src(1,:)));
    a_est_src(1) = a_est_src(1) - 2*pi;
    a_true_src     = angle(src_true);
    a_true_src(49) = a_true_src(49) - 2*pi;
    figure;set(gca,'fontsize',20);
    freq1         = [2:0.1:31];
    src_true1 = fwi_wavelet(freq1,t0,f0);
 %   plot(freq1(:), angle([src_true1(:)]), '--','linewidth',2,'color','red');hold on
    plot(freq(:), [a_true_src(:)], '+','linewidth',2);hold on
    plot(freq(:),a_est_src,'o', 'linewidth',2,'color','red');
    h = legend('True source', 'Estimated source by VP');
    set(h,'fontsize',12);
    xlabel('Frequency [Hz]','fontsize',20);
    ylabel('Phase','fontsize',20);
    str = [FigDir '/Time_SrcCmp_Phase'];
    set(gca,'fontsize',20);xlim([0 32]);ylim([-4 4])
    PrintFigure(gcf,[7,5],str);
    
    aa = angle(vec(est_src(1,:)));
    ii   =find(aa>2);
    aa(ii) = aa(ii) - 2*pi;
    figure;set(gca,'fontsize',20);
    freq1         = [2:0.1:31];
    src_true1 = fwi_wavelet(freq1,t0,f0);
 %   plot(freq1(:), angle([src_true1(:)]), '--','linewidth',2,'color','red');hold on
    aa = angle([src_true(:)]);
    ii   =find(aa>2);
    aa(ii) = aa(ii) - 2*pi;
    bb = angle(est_srcP);
    id = find(bb >2); 
    bb(id) = bb(id)-2*pi;
    plot(freq(:), aa, '+','linewidth',2);hold on;
    plot(freq(:), aa,'o', 'linewidth',2,'color','red');
    plot(freq(:), bb, 'x','linewidth',2,'color','black');
    h = legend('True source','Estimated source by VP',  'Estimated source by initial model');
    set(h,'fontsize',12);
    xlabel('Frequency [Hz]','fontsize',20);
    ylabel('Phase','fontsize',20);
    str = [FigDir '/Time_SrcCmp_Phase_all'];
    set(gca,'fontsize',20);xlim([0 32]);ylim([-4 4])
    PrintFigure(gcf,[7,5],str);
    
    
    
    figure; set(gca,'fontsize',FONTS);imagesc(x,z,ves);
    xlabel('Lateral [m]'); ylabel('Depth [m]');
    set(gca,'fontsize',FONTS);hc=colorbar; set(hc,'fontsize',FONTS);title(hc,'km/s');
    %; title(strtitle{i})
    caxis(fcaxis);fidx=gcf;
    PrintFigure(fidx,PaperSize,[FigDir '/vel_time_estsrc' ]);
    
    figure; set(gca,'fontsize',FONTS);imagesc(x,z,vesP);
    xlabel('Lateral [m]'); ylabel('Depth [m]');
    set(gca,'fontsize',FONTS);hc=colorbar; set(hc,'fontsize',FONTS);title(hc,'km/s');
    %; title(strtitle{i})
    caxis(fcaxis);fidx=gcf;
    PrintFigure(fidx,PaperSize,[FigDir '/vel_time_estsrc_P' ]);
           
end

if FlagExp3 > 0;
    
    RstTrueSrcDir = '/scratch/slim/zfang/Result/WRI_SRCEST/PaperForJournal/TrueSrc';
    RstEstSrcDir     = '/scratch/slim/zfang/Result/WRI_SRCEST/PaperForJournal/WithSrcEst';
    
    ves_file = '/scratch/slim/zfang/Result/WRI_SRCEST/PaperForJournal/WithSrcEst_TimeDataNoise1e0New4/Noise1e1/m_11.mat';
    vts_file  = '/scratch/slim/zfang/Result/WRI_SRCEST/PaperForJournal/TrueSrc/m_11.mat';
    vesP_file = '/scratch/slim/zfang/Result/WRI_SRCEST/PaperForJournal/WithSrcEstFreq_EstSrc_20Hz_PrattNoise/m_11.mat';
    est_src  = ReadAllData('/scratch/slim/zfang/Result/WRI_SRCEST/PaperForJournal/WithSrcEst_TimeDataNoise1e0New4/Noise1e1/EstSrcWave.mat');
    estP_src = ReadAllData('/scratch/slim/zfang/Result/WRI_SRCEST/PaperForJournal/WithSrcEstFreq_EstSrc_20Hz_PrattNoise/EstSrcWave.mat');
    
    ves          = ReadAllData(ves_file);
    vesP       = ReadAllData(vesP_file);
%    vts           = ReadAllData(vts_file);
    
    freq        = [2:0.5:29.5];
    f0             = 20;
    t0             = 0.5;
    flagErr   = 0;
    
    est_src   = est_src(1,1:56);
    
    src_true = -fwi_wavelet(freq,t0,f0);
    
    
    aa                = norm(vec(est_src)) / norm(src_true);
    bb                = norm(est_src)/norm(estP_src);
    est_srcP    = bb * estP_src;
    
    figure;set(gca,'fontsize',20);plot(freq(:), abs([aa*src_true(:)]), '--+','linewidth',2);hold on
    plot(freq(:), abs(vec(est_src(1,:))),'o', 'linewidth',2);
    h = legend('True source', 'Estimated source','Location','SouthEast');
    set(h,'fontsize',12);
    xlabel('Frequency [Hz]','fontsize',20);
    ylabel('Amplitude','fontsize',20);
    str = [FigDir '/Time_SrcCmp_Amp_Noise'];
    set(gca,'fontsize',20);xlim([0 32]);ylim([0 800])
    PrintFigure(gcf,[7,5],str);
    
    figure;set(gca,'fontsize',20);plot(freq(:), abs(aa*[src_true(:)]), '--+','linewidth',2); hold on;
    plot(freq(:), abs(vec(est_src(1,:))),'o', 'linewidth',2);
    plot(freq(:), abs([est_srcP(:)]), ':x','linewidth',2,'color','black');
    h = legend('True source','Estimated source by VP', 'Estimated source by Initial model','Location','SouthEast');
    set(h,'fontsize',12);
    xlabel('Frequency [Hz]','fontsize',20);
    ylabel('Amplitude','fontsize',20);
    str = [FigDir '/Time_SrcCmp_Amp_Noise_all'];
    set(gca,'fontsize',20);xlim([0 32])
    PrintFigure(gcf,[7,5],str);
    
    a_est_src =  angle(vec(est_src(1,:)));
    aa               = find(a_est_src > 2);
    a_est_src(aa) = a_est_src(aa) - 2*pi;   
    a_true_src       = angle(src_true);
    aa                        = find(a_true_src > 2);
    a_true_src(aa) = a_true_src(aa) - 2*pi;   

    figure;set(gca,'fontsize',20);
    freq1         = [2:0.5:29.5];
    src_true1 = fwi_wavelet(freq1,t0,f0);
 %   plot(freq1(:), angle([src_true1(:)]), '--','linewidth',2,'color','red');hold on
    plot(freq(:), [a_true_src(:)], '+','linewidth',2);;hold on
    plot(freq(:),a_est_src,'o', 'linewidth',2,'color','red')
    h = legend('True source', 'Estimated source' );
    set(h,'fontsize',12);
    xlabel('Frequency [Hz]','fontsize',20);
    ylabel('Phase','fontsize',20);
    str = [FigDir '/Time_SrcCmp_Phase_Noise'];
    set(gca,'fontsize',20);xlim([0 32]);ylim([-4 4])
    PrintFigure(gcf,[7,5],str);
    
     figure;set(gca,'fontsize',20);
    freq1         = [2:0.1:31];
    src_true1 = fwi_wavelet(freq1,t0,f0);
 %   plot(freq1(:), angle([src_true1(:)]), '--','linewidth',2,'color','red');hold on
    aa = angle([src_true(:)]);
    ii   =find(aa>2);
    aa(ii) = aa(ii) - 2*pi;
    bb = angle(est_srcP);
    id = find(bb >2); 
    bb(id) = bb(id)-2*pi;
    plot(freq(:), aa, '+','linewidth',2);hold on;
    plot(freq(:), aa,'o', 'linewidth',2,'color','red');
    plot(freq(:), bb, 'x','linewidth',2,'color','black');
    h = legend('True source','Estimated source by VP',  'Estimated source by initial model');
    set(h,'fontsize',12);
    xlabel('Frequency [Hz]','fontsize',20);
    ylabel('Phase','fontsize',20);
    str = [FigDir '/Time_SrcCmp_Phase_Noise_all'];
    set(gca,'fontsize',20);xlim([0 32]);ylim([-4 4])
    PrintFigure(gcf,[7,5],str);
    
    figure; set(gca,'fontsize',FONTS);imagesc(x,z,ves);
    xlabel('Lateral [m]'); ylabel('Depth [m]');
    set(gca,'fontsize',FONTS);hc=colorbar; set(hc,'fontsize',FONTS);title(hc,'km/s');
    %; title(strtitle{i})
    caxis(fcaxis);fidx=gcf;
    PrintFigure(fidx,PaperSize,[FigDir '/vel_time_estsrc_noise' ]);
    
    figure; set(gca,'fontsize',FONTS);imagesc(x,z,vesP);
    xlabel('Lateral [m]'); ylabel('Depth [m]');
    set(gca,'fontsize',FONTS);hc=colorbar; set(hc,'fontsize',FONTS);title(hc,'km/s');
    %; title(strtitle{i})
    caxis(fcaxis);fidx=gcf;
    PrintFigure(fidx,PaperSize,[FigDir '/vel_time_estsrc_P_noise' ]);
           
end



