This function estimates one or more periodograms (spectral densities)
of the time series contained in an object of class Wave
or WaveMC
(or directly in a Wave file)
using a window running through the time series (possibly with overlapping).
It returns an object of class Wspec
.
periodogram(object, ...)
# S4 method for WaveGeneral
periodogram(object, width = length(object), overlap = 0,
starts = NULL, ends = NULL, taper = 0, normalize = TRUE,
frqRange = c(-Inf, Inf), ...)
# S4 method for character
periodogram(object, width, overlap = 0, from = 1, to = Inf,
units = c("samples", "seconds", "minutes", "hours"),
downsample = NA, channel = c("left", "right"), pieces = 1, ...)
A window of width ‘width
’ running through the time series selects the samples
from which the periodograms are to be calculated.
The window can be applied by each overlapping overlap
samples.
Start number (in samples) for a window.
If not given, this value is derived from argument ends
,
or will be derived width
and overlap
.
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
.
proportion of data to taper. See spec.pgram
for details.
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 each periodogram.
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.
Where to start reading in the Wave file, in units
.
Where to stop reading in the Wave file, in 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.
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 quality. See also downsample
.
Character, indicating whether the “left” or “right” channel should be extracted
(see mono
for details) - stereo processing is not yet implemented.
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
.
An object of class Wspec
is returned containing the following slots.
Vector of frequencies at which the spectral density is estimated.
See spectrum
for details. (1)
List 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
or WaveMC
object.
The kernel argument, or the kernel constructed from spans returned by spec.pgram
. (1)
The distribution of the spectral density estimate can be approximated by a chi square distribution with
df
degrees of freedom. (1)
The value of the taper
argument. (1)
The value of the width
argument. (1)
The value of the overlap
argument. (1)
The value of the normalize
argument. (1)
If 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
.
Always FALSE
(for back compatibility). (1)
The variance of samples in each window, corresponding to amplitude / loudness of sound.
The “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)
.
for the resulting objects' class: Wspec
,
for plotting: plot-Wspec
,
for the underlying periodogram calculations: spec.pgram
,
for the input data class: Wave-class, Wave
, WaveMC-class, WaveMC
.
# NOT RUN {
# constructing a Wave object (1 sec.) containing sinus sound with 440Hz:
Wobj <- sine(440)
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