MATLAB: Is the sound() working properly

durationfunctionsnote;soundtick

Hi again,
I've been meddling with functions to create sounds. For example;
% This is the frequency of A4
f0 = 1*440; % 2*440 would be A5, 4*440 A6 etc...
% t starts from 0 with an interval of 0.0001 and goes up to 0.01
t = 0:0.0001:0.01;
% x1 is the array which uses this function/sinusoid
x1 = sin(2*pi.*f0*t);
sound(x1);
plays a note, according to the variables changing. What I want to know is; t covers all the time between 0 and 3 seconds within an interval of 0.0001 seconds. However, all I hear from the sound function is one tick of the note produced. Is it playing normal, or should I hear a continuous note for the 3 seconds duration? If I wanted to hear the note being played for 3 seconds what should I do differently?

Best Answer

From, the documentation:
sound(y) sends audio signal y to the speaker at the default sample rate of 8192 hertz.
So the duration of your sine wave is 0.01/8192 or about 1 microsecond.
Try this instead:
f0 = 1*440;
Fs = 8192;
t = linspace(0, 8192, 8192)/Fs;
x1 = sin(2*pi.*f0*t);
sound(x1);
Also, you can set the sampling frequency of the sound function to be other values.