% dopptol.m
%
% P. Flandrin

N = 500;
x = linspace(0,1,N);
y = linspace(0,1,N);

td = 100;
tf = 400;

fd = .75;
ff = .25;

dopp = [1 1.05 1.1 1.15 1.2 1.15 1.1 1.05 1 .95 .92 .88 .85 .88 .92 .95 1];

figure(1)
clf

pause

LW = 2;
MS = 25;

t = x(td:tf);
a = (fd-ff)/(t(length(t))-t(1));
f = fd + a*t(1) - a*t;

plot(t,f,'r','LineWidth',LW)
axis('square')
axis([0 1 0 1])
hold on
plot(t(1),f(1),'.r','MarkerSize',MS)
plot(t(length(t)),f(length(t)),'.r','MarkerSize',MS)
hold off
set(gca,'XTick',[],'YTick',[])
xlabel('time','FontSize',16)
ylabel('frequency','FontSize',16)
title('linear chirp','FontSize',16)

pause

M = moviein(3*length(dopp));

for k = 1:length(dopp)
	
	tdopp = t/dopp(k);
    fdopp = (fd + a*t(1) - a*t)*dopp(k);

	plot(t,f,':r','LineWidth',LW)
	axis('square')
	axis([0 1 0 1])
	hold on
	plot(t(1),f(1),'.r','MarkerSize',MS)
	plot(t(length(t)),f(length(t)),'.r','MarkerSize',MS)
	plot(tdopp,fdopp,'r','LineWidth',LW)
	plot(tdopp(1),fdopp(1),'.r','MarkerSize',MS)
	plot(tdopp(length(tdopp)),fdopp(length(tdopp)),'.r','MarkerSize',MS)
	hold off
	set(gca,'XTick',[],'YTick',[])
	xlabel('time','FontSize',16)
	ylabel('frequency','FontSize',16)
	title('linear chirp','FontSize',16)
	text(.4,.7,['Doppler = ',num2str(dopp(k))],'FontSize',16)

	M(:,3*k-1) = getframe;
	M(:,3*k-2) = getframe;
	M(:,3*k) = getframe;
	
end

pause

movie(M,2)

pause

t = x(td:tf);
t0 = (fd*t(1)-ff*t(length(t)))/(fd-ff);
c = (t(1)-t0)*fd;
f = c./(t-t0);

plot(t,f,'r','LineWidth',LW)
axis('square')
axis([0 1 0 1])
hold on
plot(t(1),f(1),'.r','MarkerSize',MS)
plot(t(length(t)),f(length(t)),'.r','MarkerSize',MS)
hold off
set(gca,'XTick',[],'YTick',[])
xlabel('time','FontSize',16)
ylabel('frequency','FontSize',16)
title('hyperbolic chirp','FontSize',16)

pause

M = moviein(3*length(dopp));

for k = 1:length(dopp)
	
	tdopp = (t-t0)/dopp(k);
	fdopp = c./(t-t0)*dopp(k);

	plot(t,f,':r','LineWidth',LW)
	axis('square')
	axis([0 1 0 1])
	hold on
	plot(t(1),f(1),'.r','MarkerSize',MS)
	plot(t(length(t)),f(length(t)),'.r','MarkerSize',MS)
	plot(tdopp+t0,fdopp,'r','LineWidth',LW)
	plot(tdopp(1)+t0,fdopp(1),'.r','MarkerSize',MS)
	plot(tdopp(length(tdopp))+t0,fdopp(length(tdopp)),'.r','MarkerSize',MS)
	hold off
	set(gca,'XTick',[],'YTick',[])
	xlabel('time','FontSize',16)
	ylabel('frequency','FontSize',16)
	title('hyperbolic chirp','FontSize',16)
	text(.4,.7,['Doppler = ',num2str(dopp(k))],'FontSize',16)


	M(:,3*k-1) = getframe;
	M(:,3*k-2) = getframe;
	M(:,3*k) = getframe;

end

pause

movie(M,2)

