% soundbeats.m % % simple program to demonstrate 'beats' using audio sine waves % Uses MATLAB's "sound" command, which requires numbers between -1 and 1 % Raghu Sept. 29, 2006 / Oct. 7, 2007 clear all close all disp(' '); disp(' '); disp(' '); samplef = 10000; % sampling frequency Hz tmax = 2.0; % total time, seconds t = 0:(1.0/samplef):tmax; f1 = 440.0; % frequency of tone 1, Hz y1 = 0.5*sin(2*pi*f1*t); % oscillation 1 fs = sprintf('Sine wave no. 1: f = %.1f Hz', f1); disp(fs); disp(' Press Enter to hear wave no. 1...'); pause; sound(y1,samplef) f2 = 444.0; % frequency of tone 2, Hz y2 = 0.5*sin(2*pi*f2*t); % oscillation 2 fs = sprintf('Sine wave no. 2: f = %.1f Hz', f2); disp(fs); disp(' Press Enter to hear wave no. 2...'); pause; sound(y2,samplef) fs = sprintf('Sum of waves no. 1 & 2'); disp(fs); disp(' Press Enter to hear the resulting wave...'); pause; sound(y2+y1,samplef)