0% found this document useful (0 votes)
694 views

Wavread in Matlab Sound File

wavread is a MATLAB function that reads WAVE (.wav) audio files. It returns the sampled audio data and additional information like sample rate, number of bits, etc. It can read all or a portion of the audio data. It supports common WAVE file formats including 8-bit, 16-bit, and 32-bit integer samples as well as 32-bit floating point samples.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
694 views

Wavread in Matlab Sound File

wavread is a MATLAB function that reads WAVE (.wav) audio files. It returns the sampled audio data and additional information like sample rate, number of bits, etc. It can read all or a portion of the audio data. It supports common WAVE file formats including 8-bit, 16-bit, and 32-bit integer samples as well as 32-bit floating point samples.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Read WAVE (.

wav) sound file - MATLAB

http://www.mathworks.com/help/matlab/ref/wavread.html

wavread
Read WAVE (.wav) sound file

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).

[ y , Fs , nbits , opts ] = wavread( filename) returns a structure opts of additional information contained

in the WAV file. The content of this structure differs from file to file. Typical structure fields include opts .fmt (audio format information) and opts .info (text that describes the title, author, etc.).

[ ___ ] = 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):

'double' 'native'

Double-precision normalized samples (default). Samples in the native data type found in the file.

siz = wavread( filename ,'size') returns the size of the audio data contained in filename instead of the

actual audio data, returning the vector siz = [ samples channels] .

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

Number of Bits 8 16

MATLAB Data Type


uint8 (unsigned integer) int16 (signed integer)

Data Range 0 <= y <= 255 -32768 <= y <= +32767

You created this PDF from an application that is not licensed to print to novaPDF printer (http://www.novapdf.com)23/11/2012 17:31 1 de 3

Read WAVE (.wav) sound file - MATLAB

http://www.mathworks.com/help/matlab/ref/wavread.html

Number of Bits 24 32

MATLAB Data Type


int32 (signed integer) single (floating point)

Data Range -2^23 <= y <= 2^23-1 -1.0 <= y < +1.0

Double Formats

Number of Bits
N<32 N=32

MATLAB Data Type


double double

Data Range -1.0 <= y < +1.0 -1.0 <= y <= +1.0 Note: Values in y might exceed -1.0 or +1.0 for the case of N=32 bit data samples stored in the WAV file.

wavread supports multi-channel data, with up to 32 bits per sample.

wavread supports Pulse-code Modulation (PCM) data format only.

Examples
Create a WAV file from the example file handel.mat , and read portions of the file back into MATLAB.

% Create WAV file in current folder. load handel.mat

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);

% Pause before next read and playback operation. duration = numel(y) / Fs; pause(duration + 2)

% Read and play only the first 2 seconds. nsamples = 2 * Fs; [y2, Fs] = wavread(hfile, nsamples); sound(y2, Fs); pause(4)

% Read and play the middle third of the file. sizeinfo = wavread(hfile, 'size');

tot_samples = sizeinfo(1); startpos = tot_samples / 3; endpos = 2 * startpos;

[y3, Fs] = wavread(hfile, [startpos endpos]); sound(y3, Fs);

You created this PDF from an application that is not licensed to print to novaPDF printer (http://www.novapdf.com)23/11/2012 17:31 2 de 3

Read WAVE (.wav) sound file - MATLAB

http://www.mathworks.com/help/matlab/ref/wavread.html

See Also
audioinfo | audioplayer | audioread | audiorecorder | audiowrite | mmfileinfo | sound

Was this topic helpful?

You created this PDF from an application that is not licensed to print to novaPDF printer (http://www.novapdf.com)23/11/2012 17:31 3 de 3

You might also like