Looping all audio files through a FFT and saving the figure
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I am able to run a FFT and save the figure each time manually. However, to save time I would like to just specify the folder that contains all the wav files and for the program to just go through each audio file and save the resulting figure automatically in a loop.
The FFT code is complete:
File= 'C:\Users\qkvm83\OneDrive - Durham University\Fieldwork\Haltwhistle_31_01_19\River_audio\Transect\Z24.wav'
[x,fs] = audioread(File);
lpad = 2*length(x);
xdft = fft(x,lpad);
xdft = xdft(1:lpad/2+1);
xdft = xdft/length(x);
xdft(2:end-1) = 2*xdft(2:end-1);
freq = 0:fs/lpad:fs/2;
plot(freq,(abs(xdft))), set(gca, 'YScale', 'log'), set(gca, 'XScale', 'log');
hold on
xlabel('Hz')
xlim([0,16000])
ylim([0.0000000001, 0.01])
q= abs(xdft);
ylabel('Amplitude')
hold off
I would just like to know how to set up a loop, that uses the folders directory. I have read through many old MatLab answers and read the literature, but my brain is frazzled now.
So in summary:
- How to set up the directory to 'C:\Users\qkvm83\OneDrive - Durham University\Fieldwork\Haltwhistle_31_01_19\River_audio\Transect\'
- How to set up the loop to go into the folder, take the audio files sequentially, then generate and save the figure into a new folder.
Any help would be beneficial, as I have been wrecking my brain for days on this.
0 个评论
采纳的回答
Geoff Hayes
2019-2-6
编辑:Geoff Hayes
2019-2-6
William - perhaps something like the following will help
function loadWavAndPerformFFT(fullPathToFolder)
wavFiles = dir (fullfile(fullPathToFolder, '*.wav'));
for k=1:length(wavFiles)
wavFile = wavFiles(k).name;
[x,fs] = audioread(wavFile);
% perform FFT
% show image
% save to file
end
end
where the above is a function that you would call with whatever folder you are interested in.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!