Opening a folder in a folder, extracting a m4a data and filter it, save the filtered output into array.

3 vues (au cours des 30 derniers jours)
I am looking for help on my code, I have been working on this for weeks but I am still having troubles. Can any one tell me what is wrong with my code?
This is how my code works
I have a folder on my desktop, and I open it into the Matlab currentfolder.
There are 77 files in that folder, and I proceed to open it one at a time. #swallow_files dir
In each of the 77 folder, there are 2 folders, and I proceed to open it one at a time. #Thick_thin_files dir
In each of the 2 folders, there are 3 folders, and I proceed to open it one at a time. #Cup_table_tea_files dir
In each of the 3 folder, there are 1 m4a file on the first folder, and 10 m4a files on the other two folders, and I proceed to open it one at a time.
Each of the m4a file is filtered and stored into an array and saved into the Thick_thin_files directory.
The code I have is written as below
A = zeros(1,43); %set array of 43 zeros
samp_rate = 44000; % sampling rate of data
data_col = 2; % audio data is column 1
m = 1
cd 'C:\Users\OneDrive\Desktop\SFolders'
swallow_files = dir;
nswallow_files = length(swallow_files);
for i = 1 : nswallow_files
cd (swallow_files(i).name)
Thick_thin_files = dir;
nThick_thin_files = length(Thick_thin_files);
for j = 1:length(nThick_thin_files)
cd (Thick_thin_files(j).name)
Cup_table_tea_files = dir;
nCup_table_tea_files = length(Cup_table_tea_files);
for k = 1:length(Cup_table_tea_files)
%Execution of code on files subsequently
cd (Cup_table_tea_files(k).name)
A(m) = load('Cup_table_tea_files(k).name.m4a')
x = Cup_table_tea_files(k).name(1:(samp_rate/2),data_col); %take the first half second of audio data
x_mean = mean(x); %compute the mean
x_std = std(x); %compute the standard deviation
prompt = 'How many sets of standard deviations would you like the system to perform?';
nstd = input(prompt)
thresh = x_mean + (nstd * x_std); %find the points that cross the threshold
x2 = abs(Cup_table_tea_files(k).name(:,end)) > thresh;
A = find((x2(1:end-2)+x2(2:end-1)+x2(3:end))== 3,1); %find first 3 consecutive points
m = m + 1;
end
end
cd Thick_thin_files
save Cup_table_tea_files(k).name.mat A %save matrix in participant’s direct folder
end
  1 commentaire
Rik
Rik le 18 Mar 2020
It is not recommended to use cd in your code, use fullfile instead.
Personally I dislike using the command syntax ("cd Thick_thin_files") and prefer the function syntax ( "cd('Thick_thin_files')" ). That way there is no confusion possible about what you mean.
Also, do you really want to ask for user input every interation? Would it be possible for you application to ask the user only once to enter nstd?

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Audio I/O and Waveform Generation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by