What is the format of the data from WAVREAD and needed for WAVWRITE in MATLAB?

3 views (last 30 days)
What is the format of the data from WAVREAD and needed for WAVWRITE in MATLAB?
I would like to know the exact output of the wavreader function in the matlab library. Its normal function is to open a WAV file and transform the audio information into a format which can be used by other routines. I want to know in more detail what that format is.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
The format is a sampled data format. The wav file format is just a binary file listing of samples with some format information at the start of the wav file (bits per sample, channels, etc.).
The WAVREAD function processes the wav file and returns some of the information (such as bits per sample and sample rate), along with all of the samples. For more information try the following at the MATLAB command prompt:
doc wavread
%or
help wavread
Here is an example that should help clarify this information. Listen to it to verify:
% stereo demonstration of wavread/wavwrite
clear all;
close all;
% wav sample parameters and time array
fs = 44100
Ts = 1/fs
nbits = 16
t=0:Ts:0.5;
% row vectors of samples
left = 0.99 * sin( 2 * pi * 2000 * t );
right = 0.99 * sin( 2 * pi * 200 * t );
% showing you the size
sizeLeft = size(left)
% flip to col vectors and concatenate
total = [ left' right' ];
% showing you the size
sizeTotal = size( total )
% plot it so we can see it
figure;
subplot(2,1,1);
plot( t, left );
title( 'left ear' );
subplot(2,1,2);
plot( t, right );
title( 'right ear' );
% write it out
wavwrite( total, fs, nbits, '2000HzInLeftEar200HzInRightEar.wav' );
% clear all variables so we can see what is reloaded
clear all;
disp( 'have written file and cleared all variables' )
% read it back in
[ y, fs, nbits ] = wavread( '2000HzInLeftEar200HzInRightEar.wav' );
% let's take a look at some data
sizeY = size(y)
fs
nbits
% setup time array
Ts = 1/fs
t=0:Ts:0.5;
left = y(:,1)';
right = y(:,2)';
% plot it so we can see it
figure;
subplot(2,1,1);
plot( t, left );
title( 'left ear' );
subplot(2,1,2);
plot( t, right );
title( 'right ear' );

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!