MATLAB Answers

Jack
0

Read and analyse multiple .wav files

Jack
さんによって質問されました 2019 年 9 月 15 日
最新アクティビティ Prabhan Purwar さんによって コメントされました 2019 年 9 月 30 日
Hi,
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!

  0 件のコメント

サインイン to comment.

タグ

1 件の回答

回答者: Prabhan Purwar 2019 年 9 月 19 日

Hi,
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
clc
clear
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);
save(matdata);
end
Please refer the following link for further information about MATLAB workspaces and the save function:

  2 件のコメント

Jack
2019 年 9 月 28 日
Hi,
Many thanks for your answer, that is extremely helpful. At what point in the code do I ask Matlab to read in the .wav files?
I have tried running your code and get the error: "Error using audioread (line 90)
The filename specified was not found in the MATLAB path."
Thanks again!
Prabhan Purwar 2019 年 9 月 30 日
Hey,
First try to identify which files are Matlab able to locate (as shown in the snapshot above), using the following code.
clc
clear
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)
** Place the .m file in the same folder where .wav files are located "C:\Users\ppurwar\Downloads\audiofiles\" (as in my case)
Following line of code reads the .wav file
[data,fs]=audioread(files(i).name);
Hope it helps!!

サインイン to comment.



Translated by