Generate and plot spectral slice from window around a specified time point of a sound file.
draw_spectralslice(
sound,
time,
channel = 1,
freqRange = NULL,
energyRange = 60,
log = FALSE,
method = "fft",
multitaper_args = NULL,
windowLength = 0.005,
windowShape = "Gaussian",
color = "black",
lineWidth = 1,
freq_axisLabel = "Frequency (Hz)",
energy_axisLabel = "Sound pressure level (dB/Hz)",
mainTitle = "",
mainTitleAlignment = 0,
highlight = NULL,
draw_lines = NULL,
draw_rectangle = NULL,
draw_arrow = NULL,
annotate = NULL,
...
)
No return value, produces a figure.
String giving the file name of a sound file with the .wav extension.
Time (in seconds) specifying the center of the window from which to estimate spectrum.
Numeric giving the channel that should be used to
generate the spectrogram. Default is 1
.
Vector of two numbers giving the frequency range to be
used for plotting spectrograms. Default is NULL
, in which case the whole
spectrum is plotted using the Nyquist frequency for the upper limit.
Either numeric or vector of two numbers used to specify
the y-axis range in units of dB/Hz. If a single number is passed, this is
interpreted as the desired dynamic range of the y-axis. If a vector of
two numbers is passed, these are used to exactly delimit the y-axis.
Default is 60
, i.e. a dynamic range of 60 dB/Hz relative to the global
maximum.
Logical; should the frequency range be log scaled? Default is
FALSE
.
String specifying the spectral estimation. Default is fft
(for the fast discrete Fourier transform). The only other option is
multitaper
, in which case multitaper::spec.mtm is used to generate the
spectrum.
Optional named list of arguments passed on to
multitaper::spec.mtm if method='multitaper'
.
Window length in seconds for generating spectra.
Default is 0.005
.
String giving the name of the window shape to be
applied to the signal when generating spectrograms. Default is Gaussian
;
other options are square
, Hamming
, Bartlett
, Hanning
, Blackman
, or
Kaiser
.Note that the Gaussian window function provided by the phonTools
package and used for this function does not have the same properties as the
Gaussian window function used for spectral estimation in Praat.
String giving the name of the color to be used for plotting
the spectrum. Default is 'black'
.
Number giving the line width to use for plotting
the spectrum. Default is 1
.
String giving the name of the label to print along the
x-axis. Default is Frequency (Hz)
.
String giving the name of the label to print along
the y-axis. Default is Sound pressure level (dB/Hz)
.
String giving a title to print at the top of the plot. The default is an empty string, i.e. no title.
Number indicating the vertical alignment of the
plot title, where 0
(default) indicates left-alignment, 1
indicates
right-alignment, 0.5
indicates central alignment, etc, following the
conventions of the adj
argument of graphics::mtext.
Named list giving parameters for differential highlighting
of part of the plot based on the frequency domain. This list should contain
information about which parts of the plot to highlight, done with the
start
and end
arguments which must be numbers or numeric vectors.
Further contains the optional arguments color
(a string), drawSize
(numeric), and background
(a string specifying a background color).
Use for drawing straight lines. Takes
an argument of type list
which should contain arguments to pass on to
graphics::abline. Should have a named argument h
for horizontal lines,
or v
for vertical lines, or a
,b
for the intercept and slope of the
line otherwise. Alternatively a nested list can be passed if more (sets of)
lines should be drawn. Default is NULL
.
Use for drawing rectangles. Should be a named list containing arguments to pass on to graphics::rect. Can also be multiple nested lists, if more rectangles should be drawn.
Use for drawing arrows on plot components. Should be a named list containing arguments to pass on to graphics::arrows. Can also be multiple nested lists, if more rectangles should be drawn.
Use for annotating plot components. Should be a named list containing arguments to pass on tographics::text. Can also be multiple nested lists, if more annotations should be added.
Further global plotting arguments passed on to par()
.
datapath <- system.file('extdata', package='praatpicture')
soundFile <- paste0(datapath, '/1.wav')
draw_spectralslice(soundFile, time = 0.75)
Run the code above in your browser using DataLab