Showing posts with label plot. Show all posts
Showing posts with label plot. Show all posts

Sunday, April 12, 2015

Wavplot and Wavplay

Matlab has their built in function to play .wav file, but it didn't work in Unix and Linux-based OS, because the wavplay function only supported in Windows. Moreover, I want to plot waveform of .wav file in single command, so I don't need to wavread it before plot. For those two purposes, I made two shorts function namely wavplot and wavfile.

Wavplot
wavplot is simple function to plot .wav file. Why I need it? because I continuously working with .wav file, and I want to plot it directly to get information of sound file via its waveform. Here the code of wavplot function.

function wavplot(wavFile)
% wavplot(wavFile) plot waveform and spectrum of wav file
% bagus@ep.its.ac.id

if nargin>1
    fprintf('Usage: wavplot(wavFile \n');
    return;
end;

[y, fs]=wavread(wavFile);
plot(y)
end

How to use it? it is simple. If you have .wav file, for example it has name tone.wav and you are in the current directory of Matlab command window, you can directly plot it with this function,
wavplot('tone.wav')
And it will plot the wav file like the following,
Output of wavplot function
Related Posts Plugin for WordPress, Blogger...