- Take care while selecting value of i, as it depends upon the structure of files, as shown
Read and analyse multiple .wav files
10 ビュー (過去 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:
- Import file 1.wav
- Calculate the mean of file 1.wav
- Save the mean of file .wav as meanfile1.mat
- import file 2.wav
- repeat steps 1-3 on file 2, saving as meanfile2.mat
- And so on doing this for all the remaining .wav files
Please can anyone help with this?
Thank you!
0 件のコメント
回答 (2 件)
Prabhan Purwar
2019 年 9 月 19 日
Hi,
Following code illustrates the saving and loading of multiple .wav files
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:
3 件のコメント
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!!
Thomas Webber
2020 年 4 月 23 日
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.
Thanks!
GreyHunter
2020 年 10 月 3 日
編集済み: GreyHunter
2020 年 10 月 7 日
Hello,
Do you know how to read multiple audio files without using the dir function?
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Audio and Video Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!