For Loop through .wav files
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
Jan
2021-3-2
Please post code as formatted text, not as screen shot. Then the readers can copy&paste it to suggest a solution.
回答(1 个)
Jan
2021-3-2
编辑:Jan
2021-3-2
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 个评论
Jan
2021-3-3
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio Processing Algorithm Design 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!