Can anyone please tell what the below code does?

[y, fs] = audioread('title.wav');
y = y(:,1);
dt = 1/fs;
t = 0:dt:(length(y)*dt)-dt;
plot(t,y);

 Accepted Answer

It reads the 'title.wav file, and returns a (Nx2) matrix ‘y’, and sampling frequency ‘fs’. It selects the left channel as ‘y’ (that is then an (Nx1) vector), then calculates the sampling interval ‘dt’, calculates a time vector ‘t’, and plots ‘y’ as a function of ‘t’.

6 Comments

Thank you very much for the answer. Can you please describe what does it mean by plotting 'y' as a function of 't'?
As always, my pleasure.
The plot call defines the x (independent) variable as the ‘t’ vector, and the y (dependent) variable as the ‘y’ vector.
I mean to ask whether there is a name for this plot? And also is it legible to get results from this plot?
It is simply a two-dimensional (2D) plot. I suppose you could call it a time-amplitude plot of the left channel of the .wav file if you need to describe it.
The results are the plot itself. You already have all the data required to plot the data, and no other information is created.
As always, my pleasure.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!