This function generates and plots a spectrogram from a Wave object, allowing customization of the frequency resolution, amplitude threshold, and plot aesthetics. The matrix is obtained with seewave's spectro() function without normalization and the amplitude values are transformed to dBFS. The spectrogram is plotted using ggplot2
with optional dark mode.
Arguments
- wave
A Wave object (from the tuneR package) representing the audio data to be analyzed.
- freq.res
Numeric. The frequency resolution, specified in Hz. This determines the window length for the spectrogram. Default is 100 Hz.
- cutoff
Numeric. The minimum amplitude in dB to be displayed in the spectrogram. Values below this threshold are set to NA. Default is -60 dB.
- dark.plot
Logical. Whether to apply a dark theme to the spectrogram plot. If
TRUE
, the background and text are dark. Default isFALSE
.- plot.title
Character. Optional title for the plot. If not provided, no title is displayed. Default is
NULL
.
Value
A ggplot2
plot of the spectrogram. The function prints the plot to the graphics device and returns NULL
.
Examples
if (FALSE) { # \dontrun{
# Load a Wave file
wave <- tuneR::readWave(system.file("extdata", "test.wav", package = "tuneR"))
# Generate a spectrogram with default parameters
spectrogram(wave)
# Generate a spectrogram with a custom frequency resolution and dark plot mode
spectrogram(wave, freq.res = 50, cutoff = -50, dark.plot = TRUE, plot.title = "Spectrogram")
} # }