Learn R Programming

tuneR (version 0.2-6)

periodogram-methods: Periodogram (Spectral Density) Estimation on Wave objects

Description

This function estimates one or more periodograms (spectral densities) of the time series contained in an object of class Wave (or directly in a Wave file) using a window running through the time series (possibly with overlapping). It returns an object of class Wspec.

Usage

periodogram(object, ...)
## S3 method for class 'Wave':
periodogram(object, width = length(object), overlap = 0,
    starts = NULL, ends = NULL, taper = 0, normalize = TRUE, 
    frqRange = c(-Inf, Inf), ...)
## S3 method for class 'character':
periodogram(object, width, overlap = 0, from = 1, to = Inf, 
    units = c("samples", "seconds", "minutes", "hours"), 
    downsample = NA, channel = c("left", "right"), pieces = 1, ...)

Arguments

object
An object of class Wave or a character string pointing to a Wave file.
width
A window of width width running through the time series selects the samples from which the periodograms are to be calculated.
overlap
The window can be applied by each overlapping overlap samples.
starts
Start number (in samples) for a window. If not given, this value is derived from argument ends, or will be derived width and overlap.
ends
End number (in samples) for a window. If not given, this value is derived from argument starts, or will be derived from width and overlap.
taper
proportion of data to taper. See spec.pgram for details.
normalize
Logical; if TRUE (default), two steps will be applied: (i) the input signal will be normalized to amplitude max(abs(amplitude)) == 1, (ii) the resulting spec values will be normalized to sum up to one for e
frqRange
Numeric vector of two elements indicating minimum and maximum of the frequency range that is to be stored in the resulting object. This is useful to reduce memory consumption.
from
Where to start reading in the Wave file, in units.
to
Where to stop reading in the Wave file, in units.
units
Units in which from and to is given, the default is samples, but can be set to time intervals such as seconds, see the Usage Section above.
downsample
Sampling rate the object is to be downsampled to. If NA, the default, no changes are applied. Otherwise downsample must be in [2000, 192000]; typical values are 11025, 22050, and 44100 for CD quali
channel
Character, indicating whether the left or right channel should be extracted (see mono for details) - stereo processing is not yet implemented.
pieces
The Wave file will be read in in pieces steps in order to reduce the amount of required memory.
...
Further arguments to be passed to the underlying function spec.pgram.

Value

  • An object of class Wspec is returned containing the following slots.
  • freqVector of frequencies at which the spectral density is estimated. See spectrum for details. (1)
  • specList of vectors or matrices of the spec values returned by spec.pgram at frequencies corresponding to freq. Each element of the list corresponds to one periodogram estimated from samples of the window beginning at start of the Wave object.
  • kernelThe kernel argument, or the kernel constructed from spans returned by spec.pgram. (1)
  • dfThe distribution of the spectral density estimate can be approximated by a chi square distribution with df degrees of freedom. (1)
  • taperThe value of the taper argument. (1)
  • widthThe value of the width argument. (1)
  • overlapThe value of the overlap argument. (1)
  • normalizeThe value of the normalize argument. (1)
  • startsIf the argument starts was given in the call, its value. If the argument ends was given in the call, ends - width. If neither starts nor ends was given, the start points of all periodograms. In the latter case the start points are calculated from the arguments width and overlap.
  • stereoWhether the underlying Wave object was stereo ot not. (1)
  • samp.rateSampling rate of the underlying Wave object. (1)
  • varianceThe variance of samples in each window, corresponding to amplitude / loudness of sound.
  • energyThe energy $E$, also an indicator for the amplitude / loudness of sound: $$E(x_I) := 20 * log_{10} \sum_{j\in I}|x_j|,$$ where $I$ indicates the interval $I:=$ start[i]:end[i] for all $i:=1,\dots,$ length(starts).
  • Those slots marked with (1) contain the information once, because it is unique for all periodograms of estimated by the function call.

concept

  • Wave
  • spectrum

See Also

  • for the resulting objects' class:Wspec,
  • for plotting:plot-Wspec,
  • for the underlying periodogram calculations:spec.pgram,
  • for the input data class:Wave.

Examples

Run this code
# constructing a Wave object (1 sec.) containing sinus sound with 440Hz:
Wobj <- sine(440, bit = 16)
Wobj

# Calculate periodograms in windows of 4096 samples each - without
#   any overlap - resulting in an Wspec object that is printed:
Wspecobj <- periodogram(Wobj, width = 4096)
Wspecobj

# Plot the first periodogram from Wspecobj:
plot(Wspecobj)
# Plot the third one and choose a reasonable xlim:
plot(Wspecobj, which = 3, xlim = c(0, 1000))
# Mark frequency that has been generated before:
abline(v = 440, col="red")

FF(Wspecobj)              # all ~ 440 Hertz
noteFromFF(FF(Wspecobj))  # all diapason a

Run the code above in your browser using DataLab