Create and display spectrograms.
spectrogram (sound, fs = 22050, windowlength = 5,
timestep = -1000, padding = 10,
preemphasisf = 50, maxfreq = 5000, colors = TRUE,
dynamicrange = 50, nlevels = dynamicrange, maintitle = "",
show = TRUE, window = 'kaiser', windowparameter = 3,
quality = FALSE)
If output is set to TRUE, an object of class 'spectrogram', a list containing the elements:
a matrix containing the magnitude at each bin center. Frequencies differ across columns, while time varies between rows.
the sampling frequency of the sound from which the spectrogram was made.
the length of the analysis window used to create the spectrogram.
the timestep (in milliseconds) used to create the spectrogram.
the dynamic range (in dB) of the spectrogram.
the colors used to create the spectrogram. This value corresponds to the 'color' parameter set when calling spectrogram().
the maximum desired frequency when plotting.
Either a numeric vector representing a sequence of samples taken from a sound wave or a sound object created with the loadsound() or makesound() functions.
The sampling frequency in Hz. If a sound object is passed this does not need to be specified.
The desired analysis window length in milliseconds.
If a negative value is given, -N, then N equally-spaced time steps are calculated. If a positive number is given, this is the spacing between adjacent analyses, in milliseconds.
The amount of zero padding for each window, measured in units of window length. For example, if the window is 50 points, and padding = 10, 500 zeros will be appended to each window.
Preemphasis of 6 dB per octave is added to frequencies above the specified frequency. For no preemphasis, set to a frequency higher than the sampling frequency.
the maximum frequency to be displayed for the spectrogram up to a maximum of fs/2. This is set to 5000 Hz by default.
If TRUE, a color spectrogram will be displayed. If FALSE, greyscale is used. If a vector of colors is provided, these colors are used to create the spectrogram.
The number of divisions to be used for the z-axis of the spectrogram. By default it is set equal to the dynamic range, meaning that a single color represents 1 dB on the z-axis.
Values greater than this many dB below the maximum will be displayed in the same color.
A string indicating the spectrogram title if one is desired.
If FALSE, no spectrogram is plotted. This is useful if the user would like to perform an action on an existing spectrogram plot without having to redraw it.
the window to be applied to the signal, applied by the windowfunc function in this package.
the parameter for the window to be applied to the signal, if appropriate.
If TRUE, a contour plot is created, which results in a high-quality image that may be slow to plot. If FALSE, a lower-quality image is created that plots much faster.
Santiago Barreda <sbarreda@ucdavis.edu>
This function is used to create and plot spectrograms. The user may specify all analysis parameters, in addition to the colors used to display the spectrogram.
The function optionally returns a spectrogram object for which the plot() function is defined.
## uncoment and run.
#data (sound) ## use the example 'sound' object provided
#sound = loadsound() ## or run this line to use you own sound
#spectrogram (sound)
# spectrogram (sound, quality = TRUE)
Run the code above in your browser using DataLab