% file:      	beats.m, (c) Matthew Roughan, Wed Jul 23 2008
N = 10;
x = (0:0.01:N);
f1 = 7;              % frequency 1 = 7 Hz
f2 = 8;              % frequency 2 = 8 Hz
y = sin(2*pi*f1 * x + pi) + sin(2*pi*f2 * x);

figure(2);
subplot(2,1,1)
hold off
plot(x, y, 'linewidth', 3);
set(gca,'xlim', [0 max(x)]);
set(gca,'linewidth', 3, 'fontsize', 18);
xlabel('time (seconds)');

z = abs(fft(y));
subplot(2,1,2)
hold off
stem((0:99)/N, z(1:100).^2, 'linewidth', 3);
set(gca,'linewidth', 3, 'fontsize', 18, 'xtick', [0:10]);
xlabel('frequency (Hz)');

set(gcf, 'PaperUnits', 'centimeters')
set(gcf, 'PaperPosition', [0 0 20 11.5])
print('-depsc', 'Plots/beats.eps');





% % smooth the beats
% figure(2);
% subplot(2,1,1)
% hold on
% plot(x, sqrt(conv2(y.^2, ones(1, 25)/25, 'same')), 'r');
