-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplotOnsets.m
More file actions
35 lines (30 loc) · 1.33 KB
/
plotOnsets.m
File metadata and controls
35 lines (30 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function plotOnsets(audio, Fs, audio_fileName, onsets)
% This function plots audio with a title based on the wav filename, plots detected onsets, and
% saves a 600dpi (journal spec) graphic as pdf. Note that a mono audio file is expected.
% Stereo audio files will be summed to mono. > 2ch audio files will just use ch1. ~PC
% Variables:
% The input variables for this function are returned by the loadResource
% function.
% - mono audio file, vector of doubles: audio
% - audio file sample rate, double: Fs
% - audio file name, string: audio_fileName
% Generate time axis
timeAxis = (1:length(audio))./Fs;
% Plot our audio
figAudio = figure;
plot(timeAxis, audio, 'k-');
ylim([-1 1]); % standard audio sample range
xlim([0 length(audio)/Fs]); % zero to end sample of audio
title('Audio and Onsets', 'FontSize', 24); % A sensible title
xlabel("Time, seconds"); % And sensible axis names
ylabel("Amplitude");
ax = gca; % Get ready for some axis formatting
ax.FontName = "Times"; % Times font standard
ax.FontSize = 24;
figAudio.WindowState = 'maximized'; % Keep everything the same size
% Plot our onsets
for i = 1:length(onsets)
xline(onsets(i, 1), '-r', 'LineWidth', 1);
end
figAudio_fileName = sprintf("%s_onsetPlot.pdf", audio_fileName); % Generate a filename
exportgraphics(figAudio, figAudio_fileName, 'Resolution', 600); % Save hi-res pdf graphic