You can also use the MATLAB command "wavrecord" to read the audio signals from the microphone directly. The command format is
y = wavrecord(n, fs);where "n" is number of samples to be recorded, and "fs" is the sample rate. The following example will record 2 seconds from your microphone.
(You need to execute the above program by yourself in order to understand the recording procedure completely.) In the above example, "duration*fs" is the number of sample points to be recorded. The recorded sample points are stored in the variable "y", which is a vector of size 32000x1. The data type of "y" is double and the memory space taken by "y" is 256,000 bytes.
In the previous example, the number of channels is 1 and the data type for sample points is double. If we want to change these two default settings, we can introduce extra input arguments to the command "wavrecord". A detailed format of "wavrecord" is:
y = wavrecord(n, fs, channel, dataType);where "channel" (usually 1 or 2) is the number of recording channels, and "dataType" (such as 'double', 'single', 'int16', 'uint8') is the data type of the recorded sample points. Different data types will require different amount of memory space. Example follows.
This example is almost the same as the previous one, except that the data type is 'uint8'. The sample points are still kept in the variable "y" with the same size 32000x1. But the elements within "y" are integers between 0 and 255. The memory space of "y" is now only 32000 bytes, which is only 1/8 of that in the previous example.
The following table shows the data types supported by the command wavrecord.
Data types Space requirement per sample Range of the sample data double 8 bytes/sample Real number within [-1, 1] single 4 bytes/sample Real number within [-1, 1] int16 2 bytes/sample Integer within [-32768, 32767] or [-2^(nbits-1), 2^(nbits-1)-1] uint8 1 byte/sample Integer within [0, 255] or [0, 2^nbits-1]
MATLAB also offers another command "audiorecorder" to offer precision control over recording.
Audio Signal Processing and Recognition (音訊處理與辨識)