Function for plotting spectrograms called by praatpicture. Instead of using
this function directly, just use
praatpicture('my_sound_file', frames='spectrogram')
.
specplot(
sig,
sr,
t,
start,
end,
tfrom0 = TRUE,
freqRange = c(0, 5000),
windowLength = 0.005,
dynamicRange = 60,
timeStep = 1000,
windowShape = "Gaussian",
colors = c("white", "black"),
pitch_plotOnSpec = FALSE,
pt = NULL,
pitch_plotType = "draw",
pitch_scale = "hz",
pitch_freqRange = NULL,
pitch_axisLabel = NULL,
pitch_color = "black",
pitch_highlight = NULL,
formant_plotOnSpec = FALSE,
fm = NULL,
formant_plotType = "speckle",
formant_dynamicRange = 30,
formant_color = "black",
formant_highlight = NULL,
intensity_plotOnSpec = FALSE,
it = NULL,
intensity_range = NULL,
intensity_axisLabel = "Intensity (dB)",
intensity_color = "black",
intensity_highlight = NULL,
tgbool = FALSE,
lines = NULL,
focusTierColor = "black",
focusTierLineType = "dotted",
ind = NULL,
min_max_only = TRUE,
highlight = NULL,
axisLabel = "Frequency (Hz)",
drawSize = 1,
speckleSize = 1
)
No return values, called internally by praatpicture and sibling functions.
Numeric vector corresponding to a sound signal.
Integer giving the sampling rate of the signal.
Numeric vector giving times corresponding to the signal.
Start time (in seconds) of desired plotted area.
End time (in seconds) of desired plotted area.
Logical; should time on the x-axis run from 0 or from the
original time? Default is TRUE
.
Vector of two integers giving the frequency range to be
used for plotting spectrograms. Default is c(0,5000)
.
Window length in seconds for generating spectrograms.
Default is 0.005
.
Dynamic range in dB for generating spectrograms. The
maximum intensity minus dynamicRange
will all be printed in white. Default
is 50
.
How many time steps should be calculated for spectrograms?
Default is 1000
. Note that this takes a while to plot, so for fiddling with
plotting parameters it is a good idea to choose a smaller value.
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
, or Blackman
.
Note that the Gaussian window function provided by the phonTools
package
and used in praatpicture()
does not have the same properties as the
Gaussian window function used for spectral estimation in Praat; plotting
a simple sine wave with high dynamic range will produce sidelobes in
praatpicture()
but not in Praat. It's recommended to use Blackman windows
instead if you have this problem.
Vector of strings giving the names of colors to be used
for plotting the spectrogram; default is c('white', 'black')
. The first
value is used for plotting the lowest visible amplitude, and the last for
plotting the highest visible amplitude. Vectors with more than two color
names can be used for plotting values in between in different colors.
Boolean; should pitch be plotted on top of
spectrogram? Default is FALSE
.
Pitch object loaded using rPraat::pt.read or similar object.
String giving the type of pitch plot to produce; default
is draw
(a line plot), the only other option is speckle
(a point plot).
Alternatively a vector c('draw','speckle')
can be passed, in which case
both are used.
String giving the frequency scale to use when producing
pitch plots. Default is hz
; other options are logarithmic
(also in Hz),
semitones
, erb
, and mel
.
Vector of two integers giving the frequency range to be
used for producing pitch plots. Default is NULL
, in which case the pitch
range is automatically reset to c(-12,30)
for the semitones
scale,
c(0,10)
for the erb
scale, and c(50,500)
for the Hz-based scales,
following Praat defaults.
String giving the name of the label to print along the
y-axis when printing a pitch track. Default is NULL
, in which case the
axis label will depend on the scale.
String or vector of strings giving the name of the color
to be used for plotting pitch. Default is 'black'
. If a vector of two
strings is passed, the second color will be used for background highlighting.
Named list giving parameters for differential
highlighting of pitch based on the time domain. This list
should contain information about which parts of the plot to highlight, either
done with the start
and end
arguments which must be numbers or numeric
vectors, or using the tier
and label
arguments to highlight based on
information in a plotted TextGrid. Further contains the optional arguments
color
(string or vector of strings, see pitch_color
),
drawSize
or speckleSize
(both numeric).
Boolean; should formants be plotted on top of
spectrogram? Default is FALSE
.
Formant object loaded using rPraat::formant.read or similar object.
String giving the type of formant plot to produce;
default is speckle
(a point plot), the only other option is draw
(a line
plot). Alternatively a vector c('draw','speckle')
can be passed, in which
case both are used.
Dynamic range in dB for producing formant plots.
When a formant plot of formant_plotType='speckle'
is drawn, no formants are
shown in frames with intensity level formant_dynamicRange
below the maximum
intensity. Default is 30
. If set to 0
, all formants are shown.
String or vector of strings giving the name(s) of
colors to be used for plotting formants. If one color is provided, all
formants will be plotted in this color. If multiple colors are provided,
different formants will be shown in different colors. Default is 'black'
.
If the length of this vector twice the number of formants plotted, the first
half of strings will be used for the formants' primary colors and the second
half will be used for background highlighting. If the length of this vector
is one more than the number of formants plotted, the last string will
be used for background highlighting.
Named list giving parameters for differential
highlighting of formants based on the time domain. This list
should contain information about which parts of the plot to highlight, either
done with the start
and end
arguments which must be numbers or numeric
vectors, or using the tier
and label
arguments to highlight based on
information in a plotted TextGrid. Further contains the optional arguments
color
(string or vector of strings, see formant_color
),
drawSize
or speckleSize
(both numeric).
Boolean; should intensity be plotted on top of
spectrogram? Default is FALSE
.
Intensity object loaded using rPraat::it.read or similar object.
Vector of two integers giving the intensity range to be
used for producing intensity plots. Default is NULL
, in which case the
range is simply the minimum and maximum levels in the curve.
String giving the name of the label to print along
the y-axis when plotting intensity. Default is Intensity (dB)
.
String or vector of strings giving the name of the
color to be used for plotting intensity. Default is 'black'
. If a vector of
two strings is passed, the second color will be used for background
highlighting.
Named list giving parameters for differential
highlighting of the intensity contour based on the time domain. This list
should contain information about which parts of the plot to highlight, either
done with the start
and end
arguments which must be numbers or numeric
vectors, or using the tier
and label
arguments to highlight based on
information in a plotted TextGrid. Further contains the optional arguments
color
(string or vector of strings, see intensity_color
) and
drawSize
(integer).
Logical; should dotted lines be plotted corresponding to
locations in a TextGrid? Default is FALSE
.
Numeric vector giving locations in seconds of locations from
a TextGrid to be plotted with dotted lines. Default is NULL
.
String or vector of strings giving the color(s) to
use for plotting focus tier lines. If multiple tiers are focused, a vector
of the same length can be passed, and the nth tier will be plotted in the
nth color. Default is 'black'
.
String or vector of strings giving the line
type(s) for plotting focus tier lines. If multiple tiers are focused, a
vector of the same length can be passed, and the nth tier will be plotted in
the nth line type. Default is 'dotted'
.
Integer indexing waveform relative to other plot components.
Default is NULL
.
Logical; should only minimum and maximum values be given
on the y-axis? Default is TRUE
. Can also be a logical vector if some but
not all plot components should have minimum and maximum values on the y-axis.
Ignored for TextGrid component.
Named list giving parameters for differential
highlighting of the spectrogram based on the time domain. This list
should contain information about which parts of the plot to highlight, either
done with the start
and end
arguments which must be numbers or numeric
vectors, or using the tier
and label
arguments to highlight based on
information in a plotted TextGrid. Further contains the argument
colors
(vector of strings, see colors
).
String giving the name of the label to print along the
y-axis when plotting a spectrogram. Default is Frequency (Hz)
.
Number indicating the line width of plot components where
the _plotType
is 'draw'
(i.e., pitch, formants, or intensity rendered as
line plots). Default is 1
. Controls the lwd
argument of
graphics::lines.
Number indicating the point size of plot components where
the _plotType
is 'speckle'
(i.e. pitch or formants rendered as point
plots). Default is 1
. Controls the cex
arguments of graphics::points.
# Don't use directly
datapath <- system.file('extdata', package='praatpicture')
soundFile <- paste0(datapath, '/1.wav')
praatpicture(soundFile, frames='spectrogram')
Run the code above in your browser using DataLab