For Loop through .wav files
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
NOTE I AM BRAND NEW TO MATLAB SO IF POSSIBLE PLEASE EXPLAIN AND/OR USE SIMPLE CODE
My professor asked me to write a code that will loop through my folder of four files creating a waveform, powerspectrum, and waveform for each file as well as saving those figures as a PDF before moving onto the next file.
This code is supposed to utitlize the listing = dir("PathName') function
Here is what I have
How on earth do I get this to work?
My Current Code:
dir("C:\Users\Karianne Kapfer\MATLAB\Assignment2\Soundfiles") %%the directory my files are in
for listing = dir("C:\Users\Karianne \MATLAB\Assignment2\Soundfiles")
%%Need to loop through the files
%%the graphs I am trying to make
fs = 64000
subplot(3,1,1)
plot(listing) <- This plot is also not working for some reason
xlabel("Samples")
ylabel('Amplitude')
title('Waveform')
hold on
subplot(3,1,2)
pspectrum(listing, fs)
xlabel("Frequency (kHz)")
ylabel('Amplitude')
title('Power Spectrom')
hold on
subplot(3,1,3)
s = spectrogram(listing)
spectrogram(listing,1024,[],[],fs,'yaxis')
publish('Assignment2MultipleFiles.mlx', 'pdf')
hold off
end
2 comentarios
Jan
el 2 de Mzo. de 2021
Please post code as formatted text, not as screen shot. Then the readers can copy&paste it to suggest a solution.
Respuestas (1)
Jan
el 2 de Mzo. de 2021
Editada: Jan
el 2 de Mzo. de 2021
Folder = 'insert your folder here'; % Sure that there is a sapce after your name?
FileList = dir(fullfile(Folder, '*.wav'));
for iFile = 1:numel(FileList)
File = fullfile(Folder, FileList(iFile).name);
% then audioread will help
end
2 comentarios
Jan
el 3 de Mzo. de 2021
No, FileList is a struct, which contains data about the file. You cannot plot the names and sizes of the files.
You want to import the contents of the files to get the data. As I have written already, audioread() can do this.
Ver también
Categorías
Más información sobre Audio Processing Algorithm Design en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!