batch reading wav files in matlab to create a matrix for neural network training set

你离开我真会死。 提交于 2019-12-10 17:41:07

问题


I am working on a small neural network project and I am very new to Matlab.

I have about 400 short wav files, which have to be read, and then combined into a matrix data set. I was not able to find any information on how to be able to load all the wav files into Matlab so that it stores each file with a different name.

My questions are:

  • Is it possible to batch process the wav files in Matlab to have each vector stored as a separate data?
  • What would be the procedure of populating the matrix with the processed wav file vectors, given that they are of different dimensions (lengths)?

回答1:


This solution makes use of cell arrays, {...}, that can handle data of different dimensions, sizes and even types. Here, Y will store the .wav sampled data and FS the sampled rate of all the audio files in a directory.

% create some data (write waves)
load handel.mat;                  %predifined sound in matlab stored in .mat
audiowrite('handel1.wav',y,Fs);   %write the first wave file
audiowrite('handel2.wav',y,Fs);   %write the second
clear y Fs                        %clear the data


% reading section
filedir = dir('*.wav');           %list the current folder content for .wav file
Y = cell(1,length(filedir));      %pre-allocate Y in memory (edit from @ Werner)
FS = Y;                           %pre-allocate FS in memory (edit from @ Werner)
for ii = 1:length(filedir)        %loop through the file names

    %read the .wav file and store them in cell arrays
    [Y{ii,1}, FS{ii,1}] = audioread(filedir(ii).name);  

end

You can access the data with

for ind_wav = 1:length(Y)
    wav_data = Y{ind_wav,1};
end


来源:https://stackoverflow.com/questions/18773349/batch-reading-wav-files-in-matlab-to-create-a-matrix-for-neural-network-training

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!