Beats between two tones Open ↗
Code
fs = 2000; tt = 0:1/fs:1;
a = sin(2*pi*40*tt);
b = sin(2*pi*44*tt);
plot(tt, a + b, 'LineWidth', 0.8), hold on
plot(tt, 2*abs(cos(2*pi*2*tt)), 'r--', 'LineWidth', 1.5)
plot(tt, -2*abs(cos(2*pi*2*tt)), 'r--', 'LineWidth', 1.5)
hold off
title('40 Hz + 44 Hz → a 4 Hz beat')
xlabel('time (s)'), legend('sum', 'envelope')
% hear it: 440 Hz + 444 Hz wobbles 4 times a second
fs2 = 22050; ts = 0:1/fs2:3;
soundsc(sin(2*pi*440*ts) + sin(2*pi*444*ts), fs2)