Audio file, Numerical amplitude data in table

11 views (last 30 days)
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

Guillaume
Guillaume on 7 May 2019
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
Guillaume
Guillaume on 7 May 2019
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'
Jina Jeon
Jina Jeon on 7 May 2019
Thank you. I get it now.
Have a nice day :D

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!