Audio file, Numerical amplitude data in table

Hi, I would like to find out the numerical values of amplitude of an audio file.
I managed to plot a amplitude vs time graph using the below code.
However, I cannot create a table of numerical amplitude values for set interval of time. For example, the audio file is 10 seconds then I want to find out the amplitude every 0.1 second so that I can get 100 values of amplitude.
Is it possible to produce a table like this?
Please help!!! I tried to work out myself but I really couldn't....
Thank you
[y,fs]=audioread("audiofile.wav");
y=y(:,1);
dt=1/fs;
t=0:dt:(length(y)*dt)-dt;
plot(t,y); xlabel('Seconds'); ylabel('Amplitude');

 Accepted Answer

It's trivial to convert your audio data to a timetable you can then retime that timetable to whichever period you want using whichever method is more appropriate:
[channels, fs] = audioread("audiofile.wav")
audio = array2timetable(channels, 'SampleRate', fs, 'VariableNames', compose('channel%d', 1:size(channels, 2))); %this is for a multichannel audio file.
%if only one channel:
%audio = timetable(channels, 'SampleRate', fs);
newaudio = retime(audio, 'regular', 'mean', 'Timestep', seconds(0.1)) %resample at 0.1 s, averaging samples. Choose whatever method you want

3 Comments

Thank you very much. I think it does what I meant.
However, when I tried this out, the values seems really small compared to the graph. Like the graph y-axis range is from around -0.4 to 0.4, but the numerical value is aroudn 10^-7.
Do you know what is the problem?
Again thank you so much for your help.
In my example, I use the 'mean' as a resampling method. For a fast sampled, oscillating signal, the mean may well be 0 at slow resampling rates. As I wrote, you have to chose the correct resampling method according to what you want. Maybe you want 'nearest'
Thank you. I get it now.
Have a nice day :D

Sign in to comment.

More Answers (0)

Asked:

on 7 May 2019

Commented:

on 7 May 2019

Community Treasure Hunt

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

Start Hunting!