Write a function called playfreq. This function should accept a frequency f
in Hz, synthesize a sound wave using the formula we saw in class:
Pt = A * sin(2*pi*f*t). (For this exercise you can set A = 1.0.) Finally,
your function should play the sound.
To generate values for t, you can use the linspace function. The following
will generate 10000 samples over one second:
t = linspace(0,1,10000);
Plugging this into the formula will yield one second of audio sampled at
10 kHz. You can play this audio back using the sound function:
sound(Pt, 10000);
To avoid repeating code, create a symbolic constant at the top of your
function:
FS = 10000;
and use FS instead of 10000 in the rest of your function. For really clean
code, use a symoblic constant T instead of 1 for the number of seconds in
linspace, and a symbolic constant A for the amplitude.
The lowest frequency that you can hear really means the lowest that you can
hear as a coherent sound, instead of a rapid sequence of blips. You can use
a form of binary search to find this lowest frequency. Start at a
reasonable power of 2, like 128, which is about the frequency (pitch) of
a man's voice. Keep dividing this frequency by 2 until the sound
becomes too low-pitched to hear.