For Loop through .wav files
Afficher commentaires plus anciens
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 commentaires
Jan
le 2 Mar 2021
Please post code as formatted text, not as screen shot. Then the readers can copy&paste it to suggest a solution.
Karianne Kapfer
le 2 Mar 2021
Réponses (1)
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 commentaires
Karianne Kapfer
le 2 Mar 2021
Jan
le 3 Mar 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.
Catégories
En savoir plus sur Spectral Measurements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!