audiowrite

Writes a matrix of samples to an audio file.

Category: Data Import and Analysis > Data Import and Export

Syntax

audiowrite(filename, y, Fs)

Writes y at sample rate Fs as 16-bit audio.

audiowrite(filename, y, Fs, 'BitsPerSample', n)

Chooses the bit depth of the file.

Description

Values outside -1 to 1 are clipped when converted to integers, so normalize the signal first if it can exceed that range. Every column of y becomes a channel of the file.

Input arguments

filename
Output file name. The extension selects the format, for example .wav.
y
Samples, one column per channel. Floating-point data should lie between -1 and 1.
Fs
Sample rate in hertz.
'BitsPerSample'
Bit depth, such as 16 or 24.

Example

Stereo file

t = (0:99)'/8000;
y = [sin(2*pi*440*t), sin(2*pi*660*t)];
audiowrite('st.wav', y, 8000);
info = audioinfo('st.wav');
disp([info.NumChannels info.TotalSamples info.SampleRate])
Output
           2         100        8000

See also

audioread audioinfo