% Plot the ambiguity function of a simple pulse or LFM waveform for 
% different parameter values.
%
% Daniel Sjoberg, 2018-02-13

PlotLFM = 0;
Plot3D = 1;

if PlotLFM == 0
    Nt = 101;
    Nf = 100;
    t_vec = linspace(-1, 1, Nt);
    fd_vec = linspace(-5, 5, Nf);

    [t, fd] = meshgrid(t_vec, fd_vec);
    A = abs((1 - abs(t)).*sin(pi*fd.*(1 - abs(t)))./(pi*fd.*(1 - abs(t))));
    if Plot3D == 1
        surf(t, fd, A);
        shading interp;
        xlabel('Normalized delay $t/\tau$', 'Interpreter', 'latex', 'Fontsize', 16)
        ylabel('Normalized Doppler shift $f_{\mathrm{d}}\tau$', 'Interpreter', 'latex', 'Fontsize', 16)
        zlabel('Ambiguity function simple pulse', 'Interpreter', 'latex', 'Fontsize', 16)
    else
        contourf(t, fd, A);
        xlabel('Normalized delay $t/\tau$', 'Interpreter', 'latex', 'Fontsize', 16)
        ylabel('Normalized Doppler shift $f_{\mathrm{d}}\tau$', 'Interpreter', 'latex', 'Fontsize', 16)
        title('Ambiguity function simple pulse', 'Interpreter', 'latex', 'Fontsize', 16)
    end
else
    tauB = 20;
    Nt = 101;
    Nf = 100;
    t_vec = linspace(-1, 1, Nt);
    fd_vec = linspace(-1, 1, Nf);

    [t, fd] = meshgrid(t_vec, fd_vec);
    A = abs((1 - abs(t)).*sin(pi*tauB*(1 - abs(t)).*(fd + t))./(pi*tauB*(1 - abs(t)).*(fd + t)));
    if Plot3D == 1
        surf(t, fd, A);
        shading interp;
        xlabel('Normalized delay $t/\tau$', 'Interpreter', 'latex', 'Fontsize', 16)
        ylabel('Normalized Doppler shift $f_{\mathrm{d}}/B$', 'Interpreter', 'latex', 'Fontsize', 16)
        zlabel(sprintf('Ambiguity function, $\\tau B=%g$', tauB), 'Interpreter', 'latex', 'Fontsize', 16)
    else
        contourf(t, fd, A);
        xlabel('Normalized delay $t/\tau$', 'Interpreter', 'latex', 'Fontsize', 16)
        ylabel('Normalized Doppler shift $f_{\mathrm{d}}/B$', 'Interpreter', 'latex', 'Fontsize', 16)
        title(sprintf('Ambiguity function, $\\tau B=%g$', tauB), 'Interpreter', 'latex', 'Fontsize', 16)
    end
end