Read and analyse multiple .wav files

16 views (last 30 days)
Jack on 15 Sep 2019
Edited: GreyHunter on 7 Oct 2020
I have 100 .wav files in the same folder which I would like to perform analysis on. I would like to read in the files one at a time, perform some simple analysis on them (e.g. calculate the mean) and then save the outputs in to a seperate file.
The essential issue seems to be importing the file and then saving each analysed output seperately. The steps I see it are to automate the following:
  1. Import file 1.wav
  2. Calculate the mean of file 1.wav
  3. Save the mean of file .wav as meanfile1.mat
  4. import file 2.wav
  5. repeat steps 1-3 on file 2, saving as meanfile2.mat
  6. And so on doing this for all the remaining .wav files
Please can anyone help with this?
Thank you!

Answers (2)

Prabhan Purwar
Prabhan Purwar on 19 Sep 2019
Following code illustrates the saving and loading of multiple .wav files
  • Take care while selecting value of i, as it depends upon the structure of files, as shown
close all
for i=3:103
%i=3;(initial data)
%Imporing data from audiofiles folder
files = dir(fullfile('C:\Users\ppurwar\Downloads\audiofiles\')); %C:\Users\ppurwar\Downloads\audiofiles (folderpath)
[data,fs]=audioread(files(i).name); %set bias to i according to files structure
%sound(data(:,1),fs); %To hear sound
datamean=mean(data(:,1)); %finding mean
%Saving output to new folder
pathname = fileparts('C:\Users\ppurwar\Downloads\audiofiles\result\');%output folder
out=strcat('datamean',num2str(i),'.mat'); %output data name
matdata = fullfile(pathname,out);
Please refer the following link for further information about MATLAB workspaces and the save function:
Thomas Webber
Thomas Webber on 23 Apr 2020
Hi there,
I was just wondering if I can ask a follow up question to this. Is there any way to use the cat function in this loop to make the data variable contain all the .wav files values. I ideally want to have one data value for all .wav files to do some power spectrum analysis on.

Sign in to comment.

GreyHunter on 3 Oct 2020
Edited: GreyHunter on 7 Oct 2020
Do you know how to read multiple audio files without using the dir function?


Community Treasure Hunt

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

Start Hunting!