% fig_video1.m
% illustrate aliasing with video monitors

dx = 1/10;
xt = [-2:-1 1:2]/dx;
xt = [-2:2]/dx;
umax = 0.8 / 2 / dx;
u = linspace(-1,1,101) * 2.5/dx;

Gaf = @(u) 3 * max(1 - (u/umax).^2, 0);
Ga = Gaf(u);

ir_fontsize text 16
texthc = @(x,y,t) ir_text(x, y, t, 'horizontalalignment', 'center');
xe{3} = '0';
for ii=[1:2 4:5]
	xe{ii} = ''; % empty
end

pl = @(i) subplot(410 + i);

pl(1)
plot(u, Ga, 'b-')
axisy(0, 3.4)
xtick(xt), ytick([0 3])
texthc(0, 1.8, '$G_a(\usym)$')
if 0
	h = gca;
	x = get(h, 'xticklabel')
	x{4} = '$1/\Dx$';
end
set(gca, 'xticklabel', xe)

Gs = Ga;
for k=1:9
	Gs = Gs + Gaf(u - k/dx) + Gaf(u + k/dx);
end

pl(2)
plot(u, Gs, 'b-')
xtick(xt), ytick([0 3])
texthc(0, 1.8, '$G_s(\usym)$')
set(gca, 'xticklabel', xe)
if 1
	set(gca, 'xticklabel', xe)
	texthc(10, -0.5, '$1/\Dx$')
	texthc(20, -0.5, '$2/\Dx$')
end

s = nufft_sinc(u * dx);

pl(3)
plot(u, s, 'b-', u, 0*u, 'k:')
axisy(-0.25, 1.1)
xtick(xt), ytick([0 1])
texthc(0, 0.6, '$\sinc(\usym\Dx)$')
set(gca, 'xticklabel', xe)

Gr = s .* Gs;

pl(4)
plot(u, Gr, 'b-', u, 0*u, 'k:')
xtick(xt), ytick([0 3])
axisy(-0.4, 3.4)
texthc(0, 1.6, '$G_r(\usym)$')
xlabelf '\usym'
if 1
	set(gca, 'xticklabel', xe)
	texthc(10, -0.9, '$1/\Dx$')
	texthc(20, -0.9, '$2/\Dx$')
end

%ir_savefig cw fig_video1
