Learn R Programming

seewave (version 1.5.5)

meanspec: Mean frequency spectrum of a time wave

Description

This function returns the mean frequency spectrum (i.e. the mean relative amplitude of the frequency distribution) of a time wave. Results can be expressed either in absolute or dB data.

Usage

meanspec(wave, f, wl = 512, wn = "hanning", ovlp = 0, PSD = FALSE,
PMF = FALSE, dB = NULL, dBref = NULL, from = NULL, to = NULL, peaks = NULL,
identify = FALSE, col = "black", cex = 1, colpeaks = "red",
cexpeaks = 1,  fontpeaks = 1, plot = 1, flab = "Frequency (kHz)",
alab = "Amplitude", flim = c(0,f/2000),alim = NULL, type ="l",...)

Arguments

wave
a vector, a matrix (first column), an object of class ts, Sample (left channel), or Wave (left channel).
f
sampling frequency of wave (in Hz). Does not need to be specified if wave is an object of class ts, Sample, or Wave<
wl
length of the window for the analysis (even number of points, by default = 512).
wn
window name, see ftwindow (by default "hanning").
ovlp
overlap between two successive analysis windows (in %).
PSD
if TRUE return Power Spectra Density, i. e. the square of the spectra.
PMF
if TRUE return Probability Mass Function, i. e. the probability distribution of frequencie.
dB
a character string specifying the type dB to return: "max0" for a maximum dB value at 0, "A", "B", "C" and "D" for common dB weights.
dBref
a dB reference value when dB is not NULL. NULL by default but should be set to 2*10e-5 for a 20 microPa reference (SPL).
from
start mark where to compute the spectrum (in s).
to
end mark where to compute the spectrum (in s).
peaks
if not NULL returns peaks value for a given span (see details).
identify
to identify frequency and amplitude values on the plot with the help of a cursor.
col
colour of the spectrum.
cex
pitch size.
colpeaks
colour of peaks value plotted on the spectrum.
cexpeaks
character size of peaks value plotted on the spectrum.
fontpeaks
font of peaks value plotted on the spectrum.
plot
if 1 returns frequency on x-axis, if 2 returns frequency on y-axis, (by default 1).
flab
title of the frequency axis.
alab
title of the amplitude axis.
flim
range of frequency axis (in kHz).
alim
range of amplitude axis.
type
if plot is TRUE, type of plot that should be drawn. See plot for details (by default "l" for lines).
...
other plot graphical parameters.

Value

  • If plot is FALSE, meanspec returns a two columns matrix, the first column corresponding to the frequency axis, the second column corresponding to the amplitude axis. If identify is TRUE, spec returns a list with two elements:
  • freqthe frequency of the points chosen on the spectrum
  • ampthe relative amplitude of the points chosen on the spectrum
  • If peaks is not NULL, spec returns a list with two elements:
  • specthe spectrum computed
  • of length wl/2,
  • peaksthe peaks values (in kHz).

Details

If from and to are FALSE then spec computes the mean spectrum of the whole signal. peaks setting corresponds to dimension of embed. See examples of spec.

See Also

spec, dynspec, corspec, diffspec, simspec, fft.

Examples

Run this code
data(orni)
# compute the mean spectrum of the whole time wave
meanspec(orni,f=22050)
# compute the mean spectrum of a time wave section (from 0.32 s to 0.39 s)
meanspec(orni,f=22050,from=0.32,to=0.39)
# different window lengths
op<-par(mfrow=c(3,1))
meanspec(orni,f=22050,wl=256)
title("wl=256")
meanspec(orni,f=22050,wl=1024)
title("wl=1024")
meanspec(orni,f=22050,wl=4096)
title("wl=4096")
par(op)
# different overlap values (almost no effects here...)
op<-par(mfrow=c(3,1))
meanspec(orni,f=22050)
title("ovlp=0")
meanspec(orni,f=22050,ovlp=50)
title("ovlp=50")
meanspec(orni,f=22050,ovlp=95)
title("ovlp=95")
par(op)
# use of flim to zoom in
op<-par(mfrow=c(2,1))
meanspec(orni,f=22050)
title("zoom in")
meanspec(orni,f=22050,wl=512,flim=c(4,6))
par(op)
# comparaison of spectrum and mean spectrum
op<-par(mfrow=c(2,1))
spec(orni,f=22050)
title("spec()")
meanspec(orni,f=22050)
title("meanspec()")
par(op)

Run the code above in your browser using DataLab