For Loop through .wav files

13 Ansichten (letzte 30 Tage)
Karianne Kapfer
Karianne Kapfer am 2 Mär. 2021
Kommentiert: Jan am 3 Mär. 2021
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 Kommentare
Jan
Jan am 2 Mär. 2021
Please post code as formatted text, not as screen shot. Then the readers can copy&paste it to suggest a solution.
Karianne Kapfer
Karianne Kapfer am 2 Mär. 2021
Done, I find this harder to read but if its helpful to others that is all that matters!

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 2 Mär. 2021
Bearbeitet: Jan am 2 Mär. 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 Kommentare
Karianne Kapfer
Karianne Kapfer am 2 Mär. 2021
So when plotting my data is now the FileList correct?
Ex. plot(FileList)
Becuase that does not work I get an error about too few arguments.
Jan
Jan am 3 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Audio I/O and Waveform Generation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by