Professional Documents
Culture Documents
Wavread - Read WAVE Sound File: Graphical Interface
Wavread - Read WAVE Sound File: Graphical Interface
Syntax
y = wavread(filename)
[y, Fs] = wavread(filename)
[y, Fs, nbits] = wavread(filename)
[y, Fs, nbits, opts] = wavread(filename)
[...] = wavread(filename, N)
[...] = wavread(filename, [N1 N2])
[...] = wavread(..., fmt)
siz = wavread(filename,'size')
Description
y = wavread(filename) loads a WAVE file specified by the string filename, returning the
sampled data in y. If filename does not include an extension, wavread appends .wav.
[y, Fs] = wavread(filename) returns the sample rate (Fs) in Hertz used to encode the data in
the file.
[y, Fs, nbits] = wavread(filename) returns the number of bits per sample (nbits).
[...] = wavread(filename, N) returns only the first N samples from each channel in the file.
[...] = wavread(filename, [N1 N2]) returns only samples N1 through N2 from each
channel in the file.
[...] = wavread(..., fmt) specifies the data format of y used to represent samples read
from the file. fmt can be either of the following values, or a partial match (case-insensitive):
Output Scaling
The range of values in y depends on the data format fmt specified. Some examples of output
scaling based on typical bit-widths found in a WAV file are given below for both 'double' and
'native' formats.
Native Formats
Double Formats
Examples
Create a WAV file from the demo file handel.mat, and read portions of the file back into
MATLAB.
hfile = 'handel.wav';
wavwrite(y, Fs, hfile)
clear y Fs
% Read the data back into MATLAB, and listen to audio.
[y, Fs, nbits, readinfo] = wavread(hfile);
sound(y, Fs);
tot_samples = sizeinfo(1);
startpos = tot_samples / 3;
endpos = 2 * startpos;
Description
wavwrite(y,filename) writes the data stored in the variable y to a WAVE file called
filename. The filename input is a string enclosed in single quotes. The data has a sample rate
of 8000 Hz and is assumed to be 16-bit. Each column of the data represents a separate channel.
Therefore, stereo data should be specified as a matrix with two columns.
wavwrite(y,Fs,filename) writes the data stored in the variable y to a WAVE file called
filename. The data has a sample rate of Fs Hz and is assumed to be 16-bit.
wavwrite(y,Fs,N,filename) writes the data stored in the variable y to a WAVE file called
filename. The data has a sample rate of Fs Hz and is N-bit, where N is 8, 16, 24, or 32.
Input Data Ranges
The range of values in y depends on the number of bits specified by N and the data type of y. The
following tables list the valid input ranges based on the value of N and the data type of y.
For floating point data where N < 32, amplitude values are clipped to the range –1.0 <= y < +1.0.
Note 8-, 16-, and 24-bit files are type 1 integer pulse code modulation (PCM). 32-bit
files are written as type 3 normalized floating point.
Description
[m d] = wavfinfo(filename) returns information about the contents of the WAVE sound file
specified by the string filename. Enclose the filename input in single quotes.
mis the string 'Sound (WAV) file', if filename is a WAVE file. Otherwise, it contains an
empty string ('').
d is a string that reports the number of samples in the file and the number of channels of audio
data. If filename is not a WAVE file, it contains the string 'Not a WAVE file'.