% Generate a chirp signal animation
% To combine frames into an animated .gif file use:
% convert -delay 50 output/*.png chirp_animation.gif
N=513;
freqs=200;
t = linspace (-0.5, 0.5, N);
n=0;
lw = 2;
fs = 10;
fw = 'bold';
for dispersion = linspace (-0.001, 0.001, 11)
sig = zeros (freqs, N);
for f = 1:freqs
sig(f,:) = cos (f * pi * (t - dispersion * f));
end
subplot (2, 1, 1);
plot (t, sum (sig, 1), 'r', 'linewidth', lw);
axis([-0.5, 0.5, -100, 200]);
set(gca, 'fontsize', fs);
set(gca, 'FontWeight', fw);
set(gca, 'linewidth', lw)
set(gca, 'XTick', linspace (-0.5, 0.5, 5));
grid;
subplot (2, 1, 2);
hold off;
plot (t, sig(1,:), 'linewidth', lw);
hold on;
plot (t, sig(4,:) + 3, 'linewidth', lw);
plot (t, sig(16,:) + 6, 'linewidth', lw);
plot (t, sig(64,:) + 9, 'linewidth', lw);
plot ([1,1]*dispersion*1, [-1.2,1.2], 'r', 'linewidth', 6);
plot ([1,1]*dispersion*4, [1.8,4.2], 'r', 'linewidth', 6);
plot ([1,1]*dispersion*16, [4.8,7.2], 'r', 'linewidth', 6);
plot ([1,1]*dispersion*64, [7.8,10.2], 'r', 'linewidth', 6);
axis([-0.5, 0.5, -1.5, 10.5], 'labelx', 'tickx');
set(gca, 'fontsize', fs);
set(gca, 'FontWeight', fw);
set(gca, 'linewidth', lw)
set(gca, 'XTick', linspace (-0.5, 0.5, 5));
grid;
pause(0.5);
n = n+1;
filename=sprintf('output/%05d.png',n);
print(filename, '-S640,480');
end