plot average spectra of multiple audio files in matlab

To plot the average spectra of multiple audio files in MATLAB, you can follow these steps:

  1. Load multiple audio files using audioread function. You can store them in a cell array for convenience.
main.m
audioFiles = {'file1.wav', 'file2.wav', 'file3.wav'};
audioData = cell(length(audioFiles), 1);

for i = 1:length(audioFiles)
    [audioData{i}, Fs] = audioread(audioFiles{i});
end
180 chars
7 lines
  1. Calculate the spectrogram of each audio file using spectrogram function. You can specify the window size, overlap, and FFT length according to your requirements.
main.m
[S, F, T] = cell(length(audioFiles), 1);

for i = 1:length(audioFiles)
    [S{i}, F{i}, T{i}] = spectrogram(audioData{i}, windowSize, overlap, fftLength, Fs);
end
163 chars
6 lines
  1. Calculate the average spectrogram by taking the mean of all spectrograms.
main.m
avgS = mean(cat(3, S{:}), 3);
30 chars
2 lines
  1. Plot the average spectrogram using imagesc function. You can adjust the color bar, title, and axis labels according to your requirements.
main.m
imagesc(T{1}, F{1}, 20*log10(abs(avgS)), [-100, 0]);
axis xy; colorbar;
title('Average Spectrogram');
xlabel('Time (sec)'); ylabel('Frequency (Hz)');
150 chars
5 lines

This should produce a plot of the average spectra of multiple audio files.

gistlibby LogSnag