Audio file, Numerical amplitude data in table
11 views (last 30 days)
Show older comments
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');
0 Comments
Accepted Answer
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
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'
More Answers (0)
See Also
Categories
Find more on Multirate Signal Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!