Title: | Sound Analysis and Synthesis |
---|---|
Description: | Functions for analysing, manipulating, displaying, editing and synthesizing time waves (particularly sound). This package processes time analysis (oscillograms and envelopes), spectral content, resonance quality factor, entropy, cross correlation and autocorrelation, zero-crossing, dominant frequency, analytic signal, frequency coherence, 2D and 3D spectrograms and many other analyses. See Sueur et al. (2008) <doi:10.1080/09524622.2008.9753600> and Sueur (2018) <doi:10.1007/978-3-319-77647-7>. |
Authors: | Jerome Sueur [aut, cre], Thierry Aubin [aut], Caroline Simonis [aut], Laurent Lellouch [ctr], Pierre Aumond [ctr], Adèle de Baudouin [ctr], Ethan C. Brown [ctr], Guillaume Corbeau [ctr], Marion Depraetere [ctr], Camille Desjonquères [ctr], François Fabianek [ctr], Amandine Gasc [ctr], Sylvain Haupert [ctr], Eric Kasten [ctr], Jonathan Lees [ctr], Jean Marchal [ctr], Andre Mikulec [ctr], Sandrine Pavoine [ctr], David Pinaud [ctr], Alicia Stotz [ctr], Luis J. Villanueva-Rivera [ctr], Zev Ross [ctr], Carl G. Witthoft [ctr], Hristo Zhivomirov [ctr] |
Maintainer: | Jerome Sueur <[email protected]> |
License: | GPL (>= 2) |
Version: | 2.2.3 |
Built: | 2024-11-12 06:53:06 UTC |
Source: | CRAN |
This function computes the Acoustic Complexity Index (ACI) as described in Pieretti et al. (2011)
ACI(wave, f, channel = 1, wl = 512, ovlp = 0, wn = "hamming", flim = NULL, nbwindows = 1)
ACI(wave, f, channel = 1, wl = 512, ovlp = 0, wn = "hamming", flim = NULL, nbwindows = 1)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
wl |
window length for the analysis (even number of points) (by default = 512). |
ovlp |
overlap between two successive windows (in %). |
wn |
window name, see |
flim |
a numeric vector of length 2 to select a frequency band (in kHz). |
nbwindows |
a numeric vector of length 1 specifying the number of
windows (by default 1, ie a single window including the complete |
The function computes first a short-term Fourier transform and then
the ACI index.
The function returns only the ACI total, ACI tot in Pieretti et
al. (2010).
See the references for details on computation.
A vector of length 1 returning the ACI total.
Values returned were checked with the results provided by the add-on Soundscapemeter for the software Wavesurfer.
Laurent Lellouch, improved by Amandine Gasc and Morgane Papin
Pieretti N, Farina A, Morri FD (2011) A new methodology to infer the
singing activity of an avian community: the Acoustic Complexity Index
(ACI). Ecological Indicators, 11, 868-873.
Farina A, Pieretti N, Piccioli L (2011) The soundscape methodology for long-term bird monitoring: a Mediterranean Europe case-study. Ecological Informatics, 6, 354-363.
data(tico) ACI(tico) ## dividing the sound sample into 4 windows of equal duration ACI(tico, nbwindows=4) ## selection of a frequency band ACI(tico, flim=c(2,6))
data(tico) ACI(tico) ## dividing the sound sample into 4 windows of equal duration ACI(tico, nbwindows=4) ## selection of a frequency band ACI(tico, flim=c(2,6))
This function returns statistics based on STFT time and frequency contours.
acoustat(wave, f, channel = 1, wl = 512, ovlp = 0, wn = "hanning", tlim = NULL, flim = NULL, aggregate = sum, fraction = 90, plot = TRUE, type = "l", ...)
acoustat(wave, f, channel = 1, wl = 512, ovlp = 0, wn = "hanning", tlim = NULL, flim = NULL, aggregate = sum, fraction = 90, plot = TRUE, type = "l", ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
wl |
window length for the analysis (even number of points) (by default = 512). |
ovlp |
overlap between two successive windows (in %). |
wn |
window name, see |
tlim |
modifications of the time limits of the analysis (in s). |
flim |
modifications of the frequency limits of the analysis (in kHz). |
aggregate |
a character vector of length 1 specifying the function to be applied on the rows (time) and columns (frequency) of the STFT matrix. By default set to |
fraction |
a numeric vector of length 1, specifying a particular fraction of the contours amplitude to be captured by the initial and terminal percentile values (in %). See details. |
plot |
a logical, if |
type |
if |
... |
other |
The principle of acoustat
is as follows:
Compute the short-term Fourier transform (STFT) with usual
parameters (wl
for window length, ovlp
for overlap of
successive windows, and wn
for the name of window shape).
This results in a time * frequency matrix.
Compute an aggregation function (specified with the argument
aggregate
set by default to sum
) accross rows and
columns of time * frequency matrix.)
This results in two components: (i) the time contour, and (ii) the frequency contour.
Each contour is considered as a probability mass function (PMF) and transformed into a cumulated distribution function (CDF).
Measures are extracted from each CDF: median (M), initial
percentile (P1) value, terminal percentile (P2) value, interpercentile range (IPR). P1, P2 and IPR are defined using a fraction parameter
(fraction
) that sets the percent of the contour amplitude to be captured by the initial and terminal percentile values. A fraction of 50% would result in the familiar quartiles and interquartile range. An energy fraction of 80% would return the 10th and 90th percentile values, and the width of the range in between.
The function returns a list with 10 items:
time.contour |
the time contour as a two-column matrix, the first colum being time (s) and the second colum being the amplitude probability mass function (no scale). |
freq.contour |
the frequency contour as a two-column matrix, the first colum being frequency (kHz) and the second colum being the amplitude probability mass function (no scale). |
time.P1 |
the time initial percentile |
time.M |
the time median |
time.P2 |
the time terminal percentile |
time.IPR |
the time interpercentile range |
freq.P1 |
the frequency initial percentile |
freq.M |
the frequency median |
freq.P2 |
the frequency terminal percentile |
freq.IPR |
the frequency interpercentile range |
acoustat
was originally developped in Matlab language by Kurt Fristrup and XXXX Watkins (1992) .
The R function was kindly checked by Kurt Fristrup.
Jerome Sueur
Fristrup, K. M. and Watkins, W. A. 1992. Characterizing acoustic features of marine animal sounds. Woods Hole Oceanographic Institution Technical Report WHOI-92-04.
data(tico) note <- cutw(tico, from=0.5, to=0.9, output="Wave") ## default setting acoustat(note) ## change the percentile fraction acoustat(note, fraction=50) ## change the STFT parameters acoustat(note, wl=1024, ovlp=80) ## change the function to compute the aggregate contours ## standard deviation instead of sum acoustat(note, aggregate=sd) ## direct time and frequency selection acoustat(tico, tlim=c(0.5,0.9), flim=c(3,6)) ## some useless graphical changes acoustat(note, type="o", col="blue")
data(tico) note <- cutw(tico, from=0.5, to=0.9, output="Wave") ## default setting acoustat(note) ## change the percentile fraction acoustat(note, fraction=50) ## change the STFT parameters acoustat(note, wl=1024, ovlp=80) ## change the function to compute the aggregate contours ## standard deviation instead of sum acoustat(note, aggregate=sd) ## direct time and frequency selection acoustat(tico, tlim=c(0.5,0.9), flim=c(3,6)) ## some useless graphical changes acoustat(note, type="o", col="blue")
Add or insert a silence section to a time wave.
addsilw(wave, f, channel = 1, at = "end", choose = FALSE, d = NULL, plot = FALSE, output = "matrix", ...)
addsilw(wave, f, channel = 1, at = "end", choose = FALSE, d = NULL, plot = FALSE, output = "matrix", ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
at |
position where to add the silence section (in s).
Can be also specified as |
choose |
logical, if |
d |
duration of the silence section to add (in s). |
plot |
logical, if |
output |
character string, the class of the object to return, either
|
... |
other |
If plot
is FALSE
, a new wave is returned. The class
of the returned object is set with the argument output
.
Jerome Sueur [email protected]
oscillo
, cutw
,deletew
,
fadew
,pastew
, mutew
,revw
,
zapsilw
This function deletes all signal which amplitude is below a selected threshold.
afilter(wave, f, channel = 1, threshold = 5, plot = TRUE, listen = FALSE, output = "matrix", ...)
afilter(wave, f, channel = 1, threshold = 5, plot = TRUE, listen = FALSE, output = "matrix", ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
threshold |
amplitude threshold (in %). |
plot |
logical, if |
listen |
if |
output |
character string, the class of the object to return,
either |
... |
other |
The threshold
value is in % relative to the maximal value
of wave
. Signal inferior to this value is clipped.
If plot
is FALSE
, a new wave is returned. The class
of the returned object is set with the argument output
.
This function is used as an argument (threshold
) in the
following functions: autoc
, csh
,
dfreq
, timer
and zc
.
Jerome Sueur [email protected]
data(orni) op<-par(mfrow=c(2,1)) afilter(orni,f=22050) title(main = "threshold level = 5") afilter(orni,f=22050,threshold=0.5,colwave="blue") title(main = "threshold level = 0.5") par(op)
data(orni) op<-par(mfrow=c(2,1)) afilter(orni,f=22050) title(main = "threshold level = 5") afilter(orni,f=22050,threshold=0.5,colwave="blue") title(main = "threshold level = 0.5") par(op)
This function computes the resonant and cutoff frequencies when recording in a given aquarium according to the criteria explained in Akamatsu et al. (2002)
akamatsu(Lx, Ly, Lz, mode = c(1,1,1), c = 148000, plot = FALSE, xlab = "Frequency (kHz)", ylab = "Attenuation distance (cm)", ...)
akamatsu(Lx, Ly, Lz, mode = c(1,1,1), c = 148000, plot = FALSE, xlab = "Frequency (kHz)", ylab = "Attenuation distance (cm)", ...)
Lx |
watertank length (in cm). |
Ly |
watertank width (in cm). |
Lz |
watertank height (in cm). |
mode |
mode, see details. |
c |
sound velocity in cm/s (by default 148000 cm/s in water). |
plot |
logical, if |
xlab |
title of the x axis if |
ylab |
title of the y axis if |
... |
other |
From Akamatsu et al. (2002):
1. Resonant frequency
The calculated resonant frequencies of a rectangular glass tank with the dimension of Lx , Ly , and Lz (in centimeters) can
be described by the following equation:
where c is the sound velocity (cm/s) and each l, m, n reprents an
integer, and the combination of these paramameters designates the
'mode number'. The mode (1, 1, 1) represents the resonance wave of minimum
frequency. The mode (2, 1, 1) represents one of the higher order of
resonant component and has additional node of the soundpressure level
at the middle of the X axis, i.e., Lx/2.
2. Cutoff frequency
The cutoff frequency can be calculated as follows:
3. Attenuation distance
The theoretical attenuation distance D can be expressed in function of the
cutoff frequency and the projected frequency following:
A list of two items:
res |
Resonant frequency (in Hz). See |
cut |
Cut frequency (in Hz). See |
Camille Desjonqueres
Akamatsu T, Okumura T, Novarini N, Yan HY (2002) Emprical refinements applicable to the recording of fish sounds in small tanks. Journal of the Acoustical Society of America, 112, 3073-3082.
akamatsu(60, 30, 40)
akamatsu(60, 30, 40)
This function computes the Fourier analysis of a time wave envelope. This allows to detect periodicity, in particular those generated by amplitude modulations.
ama(wave, f, channel = 1, envt = "hil", wl = 512, plot = TRUE, type = "l", ...)
ama(wave, f, channel = 1, envt = "hil", wl = 512, plot = TRUE, type = "l", ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
envt |
the type of envelope to be used: either "abs" for absolute amplitude envelope or "hil" for Hilbert amplitude envelope. |
wl |
length of the window for the analysis (even number of points, by default = 512). |
plot |
logical, if |
type |
if |
... |
other |
This function is based on env
and meanspec
.
The envelope of wave
is first computed and the spectrum of this envelope
is then processed. All env
and meanspec
arguments can be
set up. Be sure to set up wl
large enough if you want to detect low amplitude
modulation periodicity.
If plot
is FALSE
, ama
returns a numeric
vector corresponding to the computed spectrum.
If peaks
is not NULL
, ama
returns a list with
two elements:
spec |
the spectrum computed |
peaks |
the peaks values (in kHz). |
Jerome Sueur [email protected]
data(orni) # detection of the main amplitude modulation in a cicada song: # one with a 0.258 kHz frequency (due to pulses in the echemes) # one with a 2.369 kHz frequency (fundamental frequency) ama(orni,f=22050,wl=1024) # these amplitude modulations can be identify with a cursor: ama(orni,f=22050,wl=1024,identify=TRUE)
data(orni) # detection of the main amplitude modulation in a cicada song: # one with a 0.258 kHz frequency (due to pulses in the echemes) # one with a 2.369 kHz frequency (fundamental frequency) ama(orni,f=22050,wl=1024) # these amplitude modulations can be identify with a cursor: ama(orni,f=22050,wl=1024,identify=TRUE)
This function computes the Acoustic Richness index based on M and Ht indices
AR(..., datatype = "objects", envt = "hil", msmooth = NULL, ksmooth = NULL, ssmooth = NULL, pattern = "[wav]$|[WAV]$|[mp3]$")
AR(..., datatype = "objects", envt = "hil", msmooth = NULL, ksmooth = NULL, ssmooth = NULL, pattern = "[wav]$|[WAV]$|[mp3]$")
... |
|
datatype |
A character string to specify if inputs are either |
envt |
the type of envelope to be returned: either |
msmooth |
mean smooth. See |
ksmooth |
kernel smooth via kernel. See |
ssmooth |
sum smooth. See |
pattern |
an optional regular expression. Only file names which match the regular expression will be returned when |
AR is ranked index based on the rank of the M and Ht indices obtained with the functions M
and th
respectively following:
with
A data.frame
with three columns (M, Ht, AR) and n columns, with n the number of objects (respectively files) used as input.
As a ranked index, the results returned by AR strongly depends with the set of objects (respectively files) used as input. Comparaison between different data sets may be spurious. Computing AR on a set of a single object does not make any sense but is allowed.
Jerome Sueur and Marion Depraetere
Depraetere M, Pavoine S, Jiguet F, Gasc A, Duvail S, Sueur J (2012) Monitoring animal diversity using acoustic indices: implementation in a temperate woodland. Ecological Indicators, 13, 46-54.
## input as R objects data(orni) data(tico) AR(orni, tico) ## give names to objects if you wish to have them as row names of the returned data.frame AR(orni=orni, tico=tico) ## input as files stored in the working directory ## file names will be used as row names of the returned data.frame ## Not run: require(tuneR) AR(getwd(), datatype="files") ## End(Not run)
## input as R objects data(orni) data(tico) AR(orni, tico) ## give names to objects if you wish to have them as row names of the returned data.frame AR(orni=orni, tico=tico) ## input as files stored in the working directory ## file names will be used as row names of the returned data.frame ## Not run: require(tuneR) AR(getwd(), datatype="files") ## End(Not run)
This function generates dB data following theoretical spherical attenuation of sound.
attenuation(lref, dref = 1, dstop, n, plot = TRUE, xlab = "Distance (m)", ylab = "dB", type = "l", ...)
attenuation(lref, dref = 1, dstop, n, plot = TRUE, xlab = "Distance (m)", ylab = "dB", type = "l", ...)
lref |
reference intensity or pressure level (in dB). |
dref |
reference distance corresponding to |
dstop |
maximal distance of propagation (in m.). |
n |
number of points generated between |
plot |
logical, if |
xlab |
title of the x axis. |
ylab |
title of the y axis. |
type |
if |
... |
other |
If plot
is FALSE
return a numeric vector with the data generated.
Sound attenuation in a free, unbounded medium behaves in accordance with
the inverse square law. attenuation
generates data following this rule
from a reference point where sound intensity level (SIL) or
sound pressure level (SPL) is known. Such theoretical data can be compared with
experimental data collected in a real environment.
Jerome Sueur
Hartmann, W. M. 1998 Signals, sound and sensation. New York: Springer.
# theoretical attenuation up to 150 m of a 100 dB/1m sound source attenuation(lref=100, dref=1, dstop=150, n=200)
# theoretical attenuation up to 150 m of a 100 dB/1m sound source attenuation(lref=100, dref=1, dstop=150, n=200)
This function reads and decomposes the files names generated by an Audiomoth device, audio digal recorders produced by the society Open Acoustic Devices.
audiomoth(x, tz = "")
audiomoth(x, tz = "")
x |
a character vector with |
tz |
a character vector defining a time zone specification. See |
The digital recorder Audiomoth produced by Open Acoustic
Devices (https://www.openacousticdevices.info/) generates .wav
files which names contains information about the time of
recording. The information is encoded in hexadecimal
(e.g. "5E9089F0"). The function audiomoth
decodes this
information so that time of recording can be retrieved in numeric or
time format.
The function returns a data.frame
with the following
columns:
year |
year of recording, numeric |
month |
month of recording, numeric |
day |
day of recording, numeric |
hour |
hour of recording, numeric |
min |
minute of recording, numeric |
sec |
second of recording, numeric |
time |
time in |
For the time zone see the 607 time zone names stored in
OlsonNames
.
The file names of Audiomoth may change with time. There is no
guarantee that the function will be updated on time.
Jerome Sueur
See Open Acoustic Devices website for details regarding the Audiomoth: https://www.openacousticdevices.info/.
audiomoth.rename
, as.POSIXct
, OlsonNames
, songmeter
## HEXADECIMAL EXAMPLES (OLD FORMAT) ## recording done on Friday 10 April 2020 16:54:44 UTC ## computer time zone (local time, Europe, Paris for the test) audiomoth("5E90A4D4.WAV") ## UTC audiomoth("5E90A4D4.WAV", tz="UTC") ## GMT (= UTC as UTC and GMT are synonyms) audiomoth("5E90A4D4.WAV", tz="GMT") ## UTC -2 audiomoth("5E90A4D4.WAV", tz="Etc/GMT-2") ## in Asia, Japan audiomoth("5E90A4D4.WAV", tz="Japan") ## in South-America, Cayenne audiomoth("5E90A4D4.WAV", tz="America/Cayenne") ## several files filenames <- c("5E914ED0.WAV", "5E915128.WAV", "5E915380.WAV", "5E9155D8.WAV", "5E915830.WAV", "5E915A88.WAV", "5E915CE0.WAV", "5E915F38.WAV", "5E916190.WAV", "5E9163E8.WAV") audiomoth(filenames) ## YYYYMMDD_HHMMSS.WAV FORMAT (ACTUAL FORMAT) ## single file audiomoth("20230715_150000.wav") ## several files filenames <- c("20230715_150000.wav", "20230715_151500.wav", "20230715_153000.wav", "20230715_154500.wav") audiomoth(filenames)
## HEXADECIMAL EXAMPLES (OLD FORMAT) ## recording done on Friday 10 April 2020 16:54:44 UTC ## computer time zone (local time, Europe, Paris for the test) audiomoth("5E90A4D4.WAV") ## UTC audiomoth("5E90A4D4.WAV", tz="UTC") ## GMT (= UTC as UTC and GMT are synonyms) audiomoth("5E90A4D4.WAV", tz="GMT") ## UTC -2 audiomoth("5E90A4D4.WAV", tz="Etc/GMT-2") ## in Asia, Japan audiomoth("5E90A4D4.WAV", tz="Japan") ## in South-America, Cayenne audiomoth("5E90A4D4.WAV", tz="America/Cayenne") ## several files filenames <- c("5E914ED0.WAV", "5E915128.WAV", "5E915380.WAV", "5E9155D8.WAV", "5E915830.WAV", "5E915A88.WAV", "5E915CE0.WAV", "5E915F38.WAV", "5E916190.WAV", "5E9163E8.WAV") audiomoth(filenames) ## YYYYMMDD_HHMMSS.WAV FORMAT (ACTUAL FORMAT) ## single file audiomoth("20230715_150000.wav") ## several files filenames <- c("20230715_150000.wav", "20230715_151500.wav", "20230715_153000.wav", "20230715_154500.wav") audiomoth(filenames)
This function renames or copies files created with an Audiomoth device in a readable format including the data and time of recording.
audiomoth.rename(dir, overwrite = FALSE, tz = "", prefix = "")
audiomoth.rename(dir, overwrite = FALSE, tz = "", prefix = "")
dir |
a character vector, path to directory where the .WAV files are stored. |
overwrite |
a logical, to specify if the files should be renamed
or copied, if |
tz |
a character vector defining a time zone specification. See |
prefix |
a charcter vector for a prefix name to be added at the beginning of the file name. |
The format of the new file names follows the format of the
SongMeter SM2/SM4 deveices: PREFIX_YYYYMMDD_HHMMSS.wav
.
1 logical vector indicating which operation succeeded for each of the files attempted.
Be careful if you overwrite the files.
Jerome Sueur
This function returns the fundamental frequency of a harmonic time wave. This is achieved by computing a correlation of the signal with itself after a time delay.
autoc(wave, f, channel = 1, wl = 512, fmin, fmax, threshold = NULL, plot = TRUE, xlab = "Time (s)", ylab = "Frequency (kHz)", ylim = c(0, f/2000), pb = FALSE, ...)
autoc(wave, f, channel = 1, wl = 512, fmin, fmax, threshold = NULL, plot = TRUE, xlab = "Time (s)", ylab = "Frequency (kHz)", ylim = c(0, f/2000), pb = FALSE, ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
wl |
length of the window for the analysis (even number of points, by default = 512). |
fmin |
the minimum frequency to detect (in Hz). See details. |
fmax |
the maximum frequency to detect (in Hz). See details |
threshold |
amplitude threshold for signal detection (in %). |
plot |
logical, if |
xlab |
title of the x-axis. |
ylab |
title of the y-axis. |
ylim |
the range of y values. |
pb |
if |
... |
other |
'fmin' and 'fmax' can help by reducing computing time but can also produce less accurate results.
When plot
is FALSE
, autoc
returns a two-column matrix, the first column corresponding to time in seconds (x-axis) and the second column corresponding to
to fundamental frequency in kHz (y-axis).
NA corresponds to pause sections in wave
(see threshold
).
Jerome Sueur [email protected] and Thierry Aubin [email protected]
Hopp, S. L., Owren, M. J. and Evans, C. S. (Eds) 1998. Animal acoustic communication. Springer, Berlin, Heidelberg.
data(sheep) # fundamental frequency of a sheep res <- autoc(sheep, f=8000, threshold=5, fmin=100, fmax=700, plot=FALSE) spectro(sheep, f=8000, ovlp=75, scale=FALSE) points(res, pch=20) legend(0.5, 3.6, "Fundamental frequency", pch=20, bty=0, cex=0.7)
data(sheep) # fundamental frequency of a sheep res <- autoc(sheep, f=8000, threshold=5, fmin=100, fmax=700, plot=FALSE) spectro(sheep, f=8000, ovlp=75, scale=FALSE) points(res, pch=20) legend(0.5, 3.6, "Fundamental frequency", pch=20, bty=0, cex=0.7)
Generate a simple beep to be used as an alert, for instance at the end of a loop of when ending up a long script.
beep(d = 0.5, f = 8000, cf = 1000)
beep(d = 0.5, f = 8000, cf = 1000)
d |
duration (in s) |
f |
sampling frequency (in Hz) |
cf |
carrier frequency (in Hz) |
Nothing returned, a pure tone sound is played back. The default duration is 0.5 s and the default frequency is 1000 Hz
The function uses listen
of seewave
which
calls play
of tuneR
. You might need to set up your sound
player with setWavPlayer
of tuneR
.
Jerome Sueur
## Not run: # default settings beep() # change the duration and the frequency beep(d=1, cf=880) ## End(Not run)
## Not run: # default settings beep() # change the duration and the frequency beep(d=1, cf=880) ## End(Not run)
This function is a Butterworth frequency filter that filters out a selected frequency section of of a time wave (low-pass, high-pass, low-stop, high-stop, bandpass or bandstop frequency filter).
bwfilter(wave, f, channel = 1, n = 1, from = NULL, to = NULL, bandpass = TRUE, listen = FALSE, output = "matrix")
bwfilter(wave, f, channel = 1, n = 1, from = NULL, to = NULL, bandpass = TRUE, listen = FALSE, output = "matrix")
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
n |
Order of the filter. See details. |
from |
start frequency (in Hz) where to apply the filter. |
to |
end frequency (in Hz) where to apply the filter. |
bandpass |
if |
listen |
if |
output |
character string, the class of the object to return, either
|
The order of the filter determines the value of the roll-off value, that is the dB decrease per octave of the transfer function. A filter of order n will have a transfer function with a roll-off value of - n*6 dB.
A new wave is returned. The class
of the returned object is set with the argument output
.
This function mainly uses the functions filter()
and
filtfilt()
from the package signal
Jerome Sueur, functions filter()
and
filtfilt()
from the package signal
.
Stoddard, P. K. (1998). Application of filters in bioacoustics. In: Hopp, S. L., Owren, M. J. and Evans, C. S. (Eds), Animal acoustic communication. Springer, Berlin, Heidelberg,pp. 105-127.
ffilter
, bwfilter
, preemphasis
, lfs
, afilter
require(signal) f <- 8000 a <- noisew(f=f, d=1) ## low-pass # 1st order filter res <- bwfilter(a, f=f, n=1, to=1500) # 8th order filter res <- bwfilter(a, f=f, n=8, to=1500) ## high-pass res <- bwfilter(a, f=f, from=2500) ## band-pass res <- bwfilter(a, f=f, from=1000, to=2000) ## band-stop res <- bwfilter(a, f=f, from=1000, to=2000,bandpass=FALSE)
require(signal) f <- 8000 a <- noisew(f=f, d=1) ## low-pass # 1st order filter res <- bwfilter(a, f=f, n=1, to=1500) # 8th order filter res <- bwfilter(a, f=f, n=8, to=1500) ## high-pass res <- bwfilter(a, f=f, from=2500) ## band-pass res <- bwfilter(a, f=f, from=1000, to=2000) ## band-stop res <- bwfilter(a, f=f, from=1000, to=2000,bandpass=FALSE)
This function returns a two-dimension coherence representation between two time waves. The function corresponds to a sliding coherence function along the two signals. This produces a 2-D density plot. An amplitude contour plot can be overlaid.
ccoh(wave1, wave2, f, channel = c(1,1), wl = 512, ovlp = 0, plot = TRUE, grid = TRUE, scale = TRUE, cont = FALSE, collevels = seq(0, 1, 0.01), palette = reverse.heat.colors, contlevels = seq(0, 1, 0.01), colcont = "black", colbg="white", colgrid = "black", colaxis = "black", collab="black", xlab = "Time (s)", ylab = "Frequency (kHz)", scalelab = "Coherence", main = NULL, scalefontlab = 1, scalecexlab =0.75, axisX = TRUE, axisY = TRUE, flim = NULL, flimd = NULL, ...)
ccoh(wave1, wave2, f, channel = c(1,1), wl = 512, ovlp = 0, plot = TRUE, grid = TRUE, scale = TRUE, cont = FALSE, collevels = seq(0, 1, 0.01), palette = reverse.heat.colors, contlevels = seq(0, 1, 0.01), colcont = "black", colbg="white", colgrid = "black", colaxis = "black", collab="black", xlab = "Time (s)", ylab = "Frequency (kHz)", scalelab = "Coherence", main = NULL, scalefontlab = 1, scalecexlab =0.75, axisX = TRUE, axisY = TRUE, flim = NULL, flimd = NULL, ...)
wave1 |
a first R object |
wave2 |
a second R object |
f |
sampling frequency of |
channel |
channel of the R objects, by default left channel (1) for each object. |
wl |
window length for the analysis (even number of points, by default = 512). |
ovlp |
overlap between two successive windows (in %). |
plot |
logical, if |
grid |
logical, if |
scale |
logical, if |
cont |
logical, if |
collevels |
a set of levels which are used to partition the amplitude range of the coherence (should be between 0 and 1. |
palette |
a color palette function to be used to assign colors in
the plot, see |
contlevels |
a set of levels which are used to partition the amplitude range for contour overplot (in dB). |
colcont |
colour for |
colbg |
background colour. |
colgrid |
colour for |
colaxis |
color of the axes. |
collab |
color of the labels. |
xlab |
label of the time axis. |
ylab |
label of the frequency axis. |
scalelab |
label fo the amplitude scale. |
main |
label of the main title. |
scalefontlab |
font of the amplitude scale label. |
scalecexlab |
cex of the amplitude scale label. |
axisX |
logical, if |
axisY |
logical, if |
flim |
modifications of the frequency Y-axis limits. |
flimd |
dynamic modifications of the frequency Y-axis limits. New |
... |
Coherence is a frequency domain function computed to show the degree
of a relationship between two signals.
The value of the coherence function ranges between zero and one,
where a value of zero indicates there is no causal relationship between the signals.
A value of one indicates the existence of linear frequency response between the
two signals. This can be used, for instance, to compare the input and output
signals of a system.
Any colour palette can be used. In particular, it is possible to use other
palettes coming with seewave: temp.colors
, reverse.gray.colors.1
,
reverse.gray.colors.2
,
spectro.colors
, reverse.terrain.colors
,
reverse.topo.colors
, reverse.cm.colors
corresponding
to the reverse of terrain.colors
, topo.colors
,
cm.colors
.
Use locator
to identify points.
This function returns a list of three items:
time |
a numeric vector corresponding to the time axis. |
freq |
a numeric vector corresponding to the frequency axis. |
amp |
a numeric matrix corresponding to the coherence.
Each column corresponds to a coherence function of length |
This function is based on spec.pgram
, contour
and
filled.contour
. See spectro
for graphical changes.
Jerome Sueur [email protected] but this function is
mainly based on spec.pgram
by Martyn Plummer, Adrian Trapletti
and B.D. Ripley
coh
, spectro
, spec.pgram
.
wave1<-synth(d=1,f=4000,cf=500) wave2<-synth(d=1,f=4000,cf=800) ccoh(wave1,wave2,f=4000)
wave1<-synth(d=1,f=4000,cf=500) wave2<-synth(d=1,f=4000,cf=800) ccoh(wave1,wave2,f=4000)
This function returns the cepstrum of a time wave allowing fundamental frequency detection.
ceps(wave, f, channel = 1, phase = FALSE, wl = 512, at = NULL, from = NULL, to = NULL, tidentify = FALSE, fidentify = FALSE, col = "black", cex = 1, plot = TRUE, qlab = "Quefrency (bottom: s, up: Hz)", alab = "Amplitude", qlim = NULL, alim = NULL, type = "l", ...)
ceps(wave, f, channel = 1, phase = FALSE, wl = 512, at = NULL, from = NULL, to = NULL, tidentify = FALSE, fidentify = FALSE, col = "black", cex = 1, plot = TRUE, qlab = "Quefrency (bottom: s, up: Hz)", alab = "Amplitude", qlim = NULL, alim = NULL, type = "l", ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
phase |
if |
wl |
if |
at |
position where to compute the cepstrum (in s). |
from |
start position where to compute the cepstrum (in s). |
to |
end position to compute the cepstrum (in s). |
tidentify |
to identify time values on the plot with the help of a cursor. |
fidentify |
to identify frequency values on the plot with the help of a cursor. |
col |
colour of the cepstrum. |
cex |
pitch size of the cepstrum. |
plot |
logical, if |
qlab |
title of the quefrency axis (in s). |
alab |
title of the amplitude axis. |
qlim |
range of quefrency axis. |
alim |
range of amplitude axis. |
type |
if |
... |
other |
The cepstrum of a time wave is the inverse Fourier transform of the logarithm
of the Fourier transform. The cepstrum of a wave s is then calculated as follows:
The independent variable of a cepstral graph is called the quefrency.
The quefrency is a measure of time, though not in the sense of a signal
in the time domain. A correspondence with the frequency domain is obtained
by simply computing the reverse of the temporal x coordinate. For instance if
a peak appears at 0.005 s, this reveals a frequency peak at 200 Hz (=1/0.005).
This explain the two scales plotted when plot
is TRUE
.
If at
, from
or to
are FALSE
then ceps
computes the cepstrum of the whole signal.
When using tidentify
or tidentify
, press ‘stop’
tools bar button to return values in the console.
When plot
is FALSE
, ceps
returns the cesptral profile as a two-column matrix, the first column corresponding to quefrency (x-axis) and the second
corresponding to amplitude (y-axis).
The argument peaks
is no more available
(version > 1.5.6). See the function fpeaks
for peak(s) detection.
Cepstral analysis is mainly used in speech processing.
This analysis allows to extract the fundamental frequency, see the examples.
This function is based on fft
.
Jerome Sueur [email protected]
Oppenheim, A.V. and Schafer, R.W. 2004. From frequency to quefrency: a history of the cepstrum. Signal Processing Magazine IEEE, 21: 95-106.
data(sheep) par(mfrow=c(2,1)) # phase not taken into account ceps(sheep,f=8000,at=0.4,wl=1024) # phase taken into account ceps(sheep,f=8000,at=0.4,wl=1024, phase=TRUE)
data(sheep) par(mfrow=c(2,1)) # phase not taken into account ceps(sheep,f=8000,at=0.4,wl=1024) # phase taken into account ceps(sheep,f=8000,at=0.4,wl=1024, phase=TRUE)
This function returns a two-dimension cepstrographic representation of a time wave. The function corresponds to a short-term cepstral transform. An amplitude contour plot can be overlaid.
cepstro(wave, f, channel = 1, wl = 512, ovlp = 0, plot = TRUE, grid = TRUE, scale = TRUE, cont = FALSE, collevels = seq(0, 1, 0.01), palette = reverse.heat.colors, contlevels = seq(0, 1, 0.01), colcont = "black", colbg="white", colgrid = "black", colaxis = "black", collab = "black", xlab = "Time (s)", ylab = "Quefrency (ms)", scalelab = "Amplitude", main = NULL, scalefontlab = 1, scalecexlab = 0.75, axisX = TRUE, axisY = TRUE, tlim = NULL, qlim = NULL, ...)
cepstro(wave, f, channel = 1, wl = 512, ovlp = 0, plot = TRUE, grid = TRUE, scale = TRUE, cont = FALSE, collevels = seq(0, 1, 0.01), palette = reverse.heat.colors, contlevels = seq(0, 1, 0.01), colcont = "black", colbg="white", colgrid = "black", colaxis = "black", collab = "black", xlab = "Time (s)", ylab = "Quefrency (ms)", scalelab = "Amplitude", main = NULL, scalefontlab = 1, scalecexlab = 0.75, axisX = TRUE, axisY = TRUE, tlim = NULL, qlim = NULL, ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
wl |
if |
ovlp |
overlap between two successive windows (in %). |
plot |
logical, if |
grid |
logical, if |
scale |
logical, if |
cont |
logical, if |
collevels |
a set of levels which are used to partition the amplitude range of the cepstrogram (in dB). |
palette |
a color palette function to be used to assign colors in the plot. |
contlevels |
a set of levels which are used to partition the amplitude range for contour overplot (in dB). |
colcont |
colour for |
colbg |
background colour. |
colgrid |
colour for |
colaxis |
color of the axes. |
collab |
color of the labels. |
xlab |
label of the time axis. |
ylab |
label of the quefrency axis. |
main |
label of the main title. |
scalelab |
amplitude scale label. |
scalefontlab |
font of the amplitude scale label. |
scalecexlab |
cex of the amplitude scale label. |
axisX |
if |
axisY |
if |
tlim |
modifications of the time X-axis limits. |
qlim |
modifications of the quefrency Y-axis limits (in ms). |
... |
other |
It is unfortunately not possible to turn the y-axis to a frequency scale.
See spectro
for the use of the graphical arguments.
This function returns a list of three items:
time |
a numeric vector corresponding to the time axis. |
freq |
a numeric vector corresponding to the quefrency axis. |
amp |
a numeric matrix corresponding to the the successive cepstral profiles computed along time. |
This function is based on ceps
.
Jerome Sueur [email protected].
Oppenheim, A.V. and Schafer, R.W. 2004. From frequency to quefrency: a history of the cepstrum. Signal Processing Magazine IEEE, 21: 95-106.
data(sheep) sheepc <- cutw(sheep, f=8000, from = 0.19, to = 2.3) cepstro(sheepc,f=8000)
data(sheep) sheepc <- cutw(sheep, f=8000, from = 0.19, to = 2.3) cepstro(sheepc,f=8000)
This function returns the frequency coherence between two time waves.
coh(wave1, wave2, f, channel=c(1,1), plot =TRUE, xlab = "Frequency (kHz)", ylab = "Coherence", xlim = c(0,f/2000), type = "l",...)
coh(wave1, wave2, f, channel=c(1,1), plot =TRUE, xlab = "Frequency (kHz)", ylab = "Coherence", xlim = c(0,f/2000), type = "l",...)
wave1 |
a first R object. |
wave2 |
a second R object. |
f |
sampling frequency of |
channel |
channel of the R objects, by default left channel (1) for each object. |
plot |
logical, if |
xlab |
title of the frequency X-axis. |
ylab |
title of the coherence Y-axis. |
xlim |
range of frequency X-axis. |
type |
if |
... |
other |
Coherence is a frequency domain function computed to show the degree of a relationship between two signals. The value of the coherence function ranges between zero and one, where a value of zero indicates there is no causal relationship between the signals. A value of one indicates the existence of linear frequency response between the two signals. This can be used, for instance, to compare the input and output signals of a system.
When plot
is FALSE
, this coh
returns a two-column matrix, the
first column being the frequency axis in kHz (x-axis) and the second column being the coherence (y-axis).
This function is based on spec.pgram
.
Jerome Sueur [email protected] but this function
is based on spec.pgram
by Martyn Plummer, Adrian Trapletti and B.D. Ripley.
wave1<-synth(d=1,f=4000,cf=500) wave2<-synth(d=1,f=4000,cf=800) coh(wave1,wave2,f=4000)
wave1<-synth(d=1,f=4000,cf=500) wave2<-synth(d=1,f=4000,cf=800) coh(wave1,wave2,f=4000)
This function processes a feedforward comb filter and plots a spectrogram of the filtered wave asso- ciated with the frequency response of the filter.
combfilter(wave, f, channel = 1, alpha, K, units = c("samples", "seconds"), plot = FALSE, output = "matrix", ...)
combfilter(wave, f, channel = 1, alpha, K, units = c("samples", "seconds"), plot = FALSE, output = "matrix", ...)
wave |
an |
f |
sampling frequency (in Hz). Does not need to be specified if
embedded in |
channel |
channel of the R object, by default left channel (1). |
alpha |
a numeric vector of length 1 for the scaling factor. See Details. |
K |
a numeric vector of lenght 1 for the delay length, in
|
units |
units in which |
plot |
a logical, if |
output |
character string, the class of the object to return,
either |
... |
other arguments to be passed to |
A comb filter consists in adding a delayed version of a signal to itself resulting in constructive and destructive interference. The feedforward version of a comb filter can be written following:
where alpha is the scaling factor and K the delay length. The frequency response of the filter is obtained with:
The frequency response is periodic. The depth of the cycles is controlled with alpha and the number of cycles with K.
A new wave is returned. The class of the returned object is set with the argument output
.
Setting K to high values may generate unwanted results.
The feedback form of the combfilter is not implemented yet.
Jerome Sueur
combfilter
, fir
, squarefilter
, drawfilter
, ffilter
, bwfilter
## Not run: f <- 44100 ## chirp s1 <- synth(f=f, cf=1, d=2, fm=c(0,0,f/2,0,0), out="Wave") combfilter(s1, alpha=1, K=50, plot=TRUE) ## harmonic sound s2 <- synth(f=f, d=2, cf=600, harmonics=rep(1, 35), output="Wave") combfilter(s2, alpha=1, K=10, plot=TRUE) ## noise, units in seconds s3 <- noisew(d=2, f=44100, out="Wave") combfilter(s3, alpha=0.5, K=1e-4, units="seconds", plot=TRUE) ## End(Not run)
## Not run: f <- 44100 ## chirp s1 <- synth(f=f, cf=1, d=2, fm=c(0,0,f/2,0,0), out="Wave") combfilter(s1, alpha=1, K=50, plot=TRUE) ## harmonic sound s2 <- synth(f=f, d=2, cf=600, harmonics=rep(1, 35), output="Wave") combfilter(s2, alpha=1, K=10, plot=TRUE) ## noise, units in seconds s3 <- noisew(d=2, f=44100, out="Wave") combfilter(s3, alpha=0.5, K=1e-4, units="seconds", plot=TRUE) ## End(Not run)
This function converts sound pressure level (in dB) in sound power (Watt), intensity (Watt/m2) and pressure (Pa). By default, these conversions are applied to air-borne sound.
convSPL(x, d = 1, Iref = 10^-12, pref = 2*10^-5)
convSPL(x, d = 1, Iref = 10^-12, pref = 2*10^-5)
x |
a numeric vector or a matrix describind SPL values (in dB). |
d |
the distance from the sound source where SPL values have been measured (in meter) (by default = 1m) |
Iref |
reference intensity (in Watt/m2) (by default = 10^-12) |
pref |
reference pressure (in Pa) (by default = 2*10^-5) |
convSPL
returns a list containing three components:
P |
data converted in sound power (in Watt). |
I |
data converted in sound intensity (in Watt/m2). |
p |
data converted in sound pressure (in Pa). |
Iref
and pref
correspond to a 1 kHz sound in air.
Jerome Sueur [email protected]
Hartmann, W. M. 1998 Signals, sound and sensation. New York: Springer.
# conversion of two SPL measurements taken at 0.5 m from the source convSPL(c(80,85),d=0.5)
# conversion of two SPL measurements taken at 0.5 m from the source convSPL(c(80,85),d=0.5)
This function tests the similarity between two time wave envelopes by returning their maximal correlation and the time shift related to it.
corenv(wave1, wave2, f, channel=c(1,1), envt="hil", msmooth = NULL, ksmooth = NULL, ssmooth = NULL, plot = TRUE, plotval = TRUE, method = "spearman", col = "black", colval = "red", cexval = 1, fontval = 1, xlab = "Time (s)", ylab = "Coefficient of correlation (r)", type = "l", pb = FALSE, ...)
corenv(wave1, wave2, f, channel=c(1,1), envt="hil", msmooth = NULL, ksmooth = NULL, ssmooth = NULL, plot = TRUE, plotval = TRUE, method = "spearman", col = "black", colval = "red", cexval = 1, fontval = 1, xlab = "Time (s)", ylab = "Coefficient of correlation (r)", type = "l", pb = FALSE, ...)
wave1 |
a first R object. |
wave2 |
a second R object. |
f |
sampling frequency of |
channel |
channel of the R objects, by default left channel (1) for each object. |
envt |
the type of envelope to be used: either "abs" for absolute
amplitude envelope or "hil" for Hilbert amplitude envelope. See |
msmooth |
a vector of length 2 to smooth the amplitude envelope with a
mean sliding window. The first component is the window length
(in number of points). The second component is the overlap between
successive windows (in %). See |
ksmooth |
|
ssmooth |
sum smooth. See |
plot |
logical, if |
plotval |
logical, if |
method |
a character string indicating which correlation coefficient is
to be computed ("pearson", "spearman", or "kendall")
(see |
col |
colour of r values. |
colval |
colour of r max and frequency offset values. |
cexval |
character size of r max and frequency offset values. |
fontval |
font of r max and frequency offset values. |
xlab |
title of the frequency axis. |
ylab |
title of the r axis. |
type |
if |
pb |
if |
... |
other |
Successive correlations between the envelopes of wave1
and wave2
are computed when regularly sliding forward and backward wave2
along
wave1
.
The maximal correlation is obtained at a particular shift (time offset).
This shift may be positive or negative.
The higher smooth
is set up,
the faster will be the computation but less precise the results will be.
The corresponding p value, obtained with cor.test
, is plotted.
Inverting wave1
and wave2
may give slight different results.
If plot
is FALSE
, corenv
returns a list containing four
components:
r |
a two-column matrix, the first colum corresponding to the time
shift (frequency x-axis) and the second column corresponding to the successive
r correlation values between |
rmax |
the maximum correlation value between |
p |
the p value corresponding to |
t |
the time offset corresponding to |
Jerome Sueur
env
,corspec
,covspectro
,
cor
,cor.test
.
## Not run: data(orni) # cross-correlation between two echemes of a cicada song wave1<-cutw(orni,f=22050,from=0.3,to=0.4,plot=FALSE) wave2<-cutw(orni,f=22050,from=0.58,to=0.68,plot=FALSE) corenv(wave1,wave2,f=22050) ## End(Not run)
## Not run: data(orni) # cross-correlation between two echemes of a cicada song wave1<-cutw(orni,f=22050,from=0.3,to=0.4,plot=FALSE) wave2<-cutw(orni,f=22050,from=0.58,to=0.68,plot=FALSE) corenv(wave1,wave2,f=22050) ## End(Not run)
This function tests the similarity between two frequency spectra by returning their maximal correlation and the frequency shift related to it.
corspec(spec1, spec2, f = NULL, mel = FALSE, plot = TRUE, plotval = TRUE, method = "spearman", col = "black", colval = "red", cexval = 1, fontval = 1, xlab = NULL, ylab = "Coefficient of correlation (r)", type="l",...)
corspec(spec1, spec2, f = NULL, mel = FALSE, plot = TRUE, plotval = TRUE, method = "spearman", col = "black", colval = "red", cexval = 1, fontval = 1, xlab = NULL, ylab = "Coefficient of correlation (r)", type="l",...)
spec1 |
a first data set resulting of a spectral analysis obtained
with |
spec2 |
a first data set resulting of a spectral analysis obtained
with |
f |
sampling frequency of waves used to obtain |
mel |
a logical, if |
plot |
logical, if |
plotval |
logical, if |
method |
a character string indicating which correlation coefficient is
to be computed ("pearson", "spearman", or "kendall")
(see |
col |
colour of r values. |
colval |
colour of r max and frequency offset values. |
cexval |
character size of r max and frequency offset values. |
fontval |
font of r max and frequency offset values. |
xlab |
title of the frequency axis. |
ylab |
title of the r axis. |
type |
if |
... |
other |
It is important not to have data in dB.
Successive correlations between spec1
and spec2
are computed when regularly
shifting spec2
towards lower or higher frequencies.
The maximal correlation is obtained at a particular shift (frequency offset).
This shift may be positive or negative.
The corresponding p value, obtained with cor.test
, is plotted.
Inverting spec1
and spec2
may give slight different results, see examples.
If plot
is FALSE
, corspec
returns a list containing four
components:
r |
a two-column matrix, the first colum corresponding to the frequency
shift (frequency x-axis) and the second column corresponding to the successive
r correlation values between |
rmax |
the maximum correlation value between |
p |
the p value corresponding to |
f |
the frequency offset corresponding to |
Jerome Sueur, improved by Laurent Lellouch
Hopp, S. L., Owren, M. J. and Evans, C. S. (Eds) 1998. Animal acoustic communication. Springer, Berlin, Heidelberg.
spec
, meanspec
, corspec
,
covspectro
, cor
, cor.test
.
## Not run: data(tico) ## compare the two first notes spectra a<-spec(tico,f=22050,wl=512,at=0.2,plot=FALSE) c<-spec(tico,f=22050,wl=512,at=1.1,plot=FALSE) op<-par(mfrow=c(2,1), mar=c(4.5,4,3,1)) spec(tico,f=22050,at=0.2,col="blue") par(new=TRUE) spec(tico,f=22050,at=1.1,col="green") legend(x=8,y=0.5,c("Note A", "Note C"),lty=1,col=c("blue","green"),bty="o") par(mar=c(5,4,2,1)) corspec(a,c, ylim=c(-0.25,0.8),xaxs="i",yaxs="i",las=1) par(op) ## different correlation methods give different results... op<-par(mfrow=c(3,1)) corspec(a,c,xaxs="i",las=1, ylim=c(-0.25,0.8)) title("spearmann correlation (by default)") corspec(a,c,xaxs="i",las=1,ylim=c(0,1),method="pearson") title("pearson correlation") corspec(a,c,xaxs="i",las=1,ylim=c(-0.23,0.5),method="kendall") title("kendall correlation") par(op) ## inverting x and y does not give exactly similar results op<-par(mfrow=c(2,1),mar=c(2,4,3,1)) corspec(a,c) corspec(c,a) par(op) ## mel scale require(tuneR) data(orni) orni.mel <- melfcc(orni, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) orni.mel.mean <- apply(orni.mel$aspectrum, MARGIN=2, FUN=mean) tico.mel <- melfcc(tico, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) tico.mel.mean <- apply(tico.mel$aspectrum, MARGIN=2, FUN=mean) corspec(orni.mel.mean, tico.mel.mean, f=22050, mel=TRUE, plot=TRUE) ## End(Not run)
## Not run: data(tico) ## compare the two first notes spectra a<-spec(tico,f=22050,wl=512,at=0.2,plot=FALSE) c<-spec(tico,f=22050,wl=512,at=1.1,plot=FALSE) op<-par(mfrow=c(2,1), mar=c(4.5,4,3,1)) spec(tico,f=22050,at=0.2,col="blue") par(new=TRUE) spec(tico,f=22050,at=1.1,col="green") legend(x=8,y=0.5,c("Note A", "Note C"),lty=1,col=c("blue","green"),bty="o") par(mar=c(5,4,2,1)) corspec(a,c, ylim=c(-0.25,0.8),xaxs="i",yaxs="i",las=1) par(op) ## different correlation methods give different results... op<-par(mfrow=c(3,1)) corspec(a,c,xaxs="i",las=1, ylim=c(-0.25,0.8)) title("spearmann correlation (by default)") corspec(a,c,xaxs="i",las=1,ylim=c(0,1),method="pearson") title("pearson correlation") corspec(a,c,xaxs="i",las=1,ylim=c(-0.23,0.5),method="kendall") title("kendall correlation") par(op) ## inverting x and y does not give exactly similar results op<-par(mfrow=c(2,1),mar=c(2,4,3,1)) corspec(a,c) corspec(c,a) par(op) ## mel scale require(tuneR) data(orni) orni.mel <- melfcc(orni, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) orni.mel.mean <- apply(orni.mel$aspectrum, MARGIN=2, FUN=mean) tico.mel <- melfcc(tico, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) tico.mel.mean <- apply(tico.mel$aspectrum, MARGIN=2, FUN=mean) corspec(orni.mel.mean, tico.mel.mean, f=22050, mel=TRUE, plot=TRUE) ## End(Not run)
This function tests the similarity between two spectrograms by returning their maximal covariance and the time shift related to it.
covspectro(wave1, wave2, f, channel = c(1,1), wl = 512, wn = "hanning", n, plot = TRUE, plotval = TRUE, method = "spearman", col = "black", colval = "red", cexval = 1, fontval = 1, xlab = "Time (s)", ylab = "Normalised covariance (cov)", type = "l", pb = FALSE, ...)
covspectro(wave1, wave2, f, channel = c(1,1), wl = 512, wn = "hanning", n, plot = TRUE, plotval = TRUE, method = "spearman", col = "black", colval = "red", cexval = 1, fontval = 1, xlab = "Time (s)", ylab = "Normalised covariance (cov)", type = "l", pb = FALSE, ...)
wave1 |
a first R object. |
wave2 |
a second R object. |
f |
sampling frequency of |
channel |
channel of the R objects, by default left channel (1) for each object. |
wl |
length of the window for the analysis (even number of points, by default = 512). |
wn |
window name, see |
n |
number of covariances computed between |
plot |
logical, if |
plotval |
logical, if |
method |
a character string indicating which correlation coefficient is
to be computed ("pearson", "spearman", or "kendall")
(see |
col |
colour of r values. |
colval |
colour of r max and frequency offset values. |
cexval |
character size of r max and frequency offset values. |
fontval |
font of r max and frequency offset values. |
xlab |
title of the frequency axis. |
ylab |
title of the r axis. |
type |
if |
pb |
if |
... |
other |
Successive covariances between the spectrogram of wave1
and
the spectrogram of wave2
are computed when regularly sliding
forward and backward wave2
along wave1
.
The maximal covariance is obtained at a particular shift (time offset).
This shift may be positive or negative.n
sets in how many steps wave2
will be slided along wave1
.
Time process can be then decreased by setting low n
value.
Inverting wave1
and wave2
may give slight different results.
If plot
is FALSE
, covspectro
returns a list containing
three components:
cov |
the successive covariance values between |
covmax |
the maximum covariance between |
t |
the time offset corresponding to |
Jerome Sueur [email protected]
Hopp, S. L., Owren, M. J. and Evans, C. S. (Eds) 1998. Animal acoustic communication. Springer, Berlin, Heidelberg.
corspec
, corenv
, spectro
,
cor
,
# covariance between two notes of a birdsong ## Not run: data(tico) note1<-cutw(tico, f=22050, from=0.5, to=0.9) note2<-cutw(tico, f=22050, from=0.9, to=1.3) covspectro(note1,note2,f=22050,n=37) ## End(Not run)
# covariance between two notes of a birdsong ## Not run: data(tico) note1<-cutw(tico, f=22050, from=0.5, to=0.9) note2<-cutw(tico, f=22050, from=0.9, to=1.3) covspectro(note1,note2,f=22050,n=37) ## End(Not run)
This function returns the crest factor and localizes the different crest(s).
crest(wave, f, channel = 1, plot = FALSE, col = 2, cex = 3, symbol = "*", ...)
crest(wave, f, channel = 1, plot = FALSE, col = 2, cex = 3, symbol = "*", ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
plot |
if |
col |
color of the symbol indicating the localisation of the crest(s) |
cex |
symbol magnification |
symbol |
symbol indicating the localisation of the crest(s) |
... |
other |
The crest factor of a time series s is calculated according to:
with rms the root-mean-square (see rms
).
The function returns a list of three items
C |
crest factor |
val |
value of the crest(s) |
loc |
location of the crest(s) |
There might be several crests (maxima) along the time wave but there is a single crest factor.
Jerome Sueur [email protected]
Hartmann, W. M. 1998 Signals, sound and sensation. New York: Springer.
data(tico) crest(tico, f=22050) # see the crest location and change the default graphical parameters crest(tico, f=22050, plot=TRUE, sym="-")
data(tico) crest(tico, f=22050) # see the crest location and change the default graphical parameters crest(tico, f=22050, plot=TRUE, sym="-")
This function computes the continuous spectral entropy (H) of a time wave.
csh(wave, f, channel = 1, wl = 512, wn = "hanning", ovlp = 0, fftw = FALSE, threshold = NULL, plot = TRUE, xlab = "Times (s)", ylab = "Spectral Entropy", ylim = c(0, 1.1), type = "l", ...)
csh(wave, f, channel = 1, wl = 512, wn = "hanning", ovlp = 0, fftw = FALSE, threshold = NULL, plot = TRUE, xlab = "Times (s)", ylab = "Spectral Entropy", ylim = c(0, 1.1), type = "l", ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
wl |
if |
wn |
window name, see |
ovlp |
overlap between two successive windows (in %). |
fftw |
if |
threshold |
amplitude threshold for signal detection (in %). |
plot |
logical, if |
xlab |
title of the x axis. |
ylab |
title of the y axis. |
ylim |
the range of y values. |
type |
if |
... |
other |
See sh
for computing method.
When plot
is FALSE
, csh
returns a two-column matrix, the
first column being time in seconds (x-axis) and the second column being the spectral entropy (y-axis) computed along time.
NA corresponds to pause sections in wave
(see threshold
).
The spectral entropy of a noisy signal will tend towards 1 whereas the spectral entropy of a pure tone signal will tend towards 0.
Jerome Sueur [email protected]
Toh, A. M., Togneri, R. & Nordholm, S. 2005 Spectral entropy as speech features for speech recognition. Proceedings of PEECS, pp. 60-65.
data(orni) csh(orni,f=22050,wl=512,ovlp=50) # using the threshold argument can lead to some edge effets # here sh=1 at the end of echemes csh(orni,f=22050,wl=512,ovlp=50,threshold=5)
data(orni) csh(orni,f=22050,wl=512,ovlp=50) # using the threshold argument can lead to some edge effets # here sh=1 at the end of echemes csh(orni,f=22050,wl=512,ovlp=50,threshold=5)
This function can be used to select (cut) a specific part of a frequency spectrum.
cutspec(spec, f = NULL, flim, mel = FALSE, norm = FALSE, PMF = FALSE)
cutspec(spec, f = NULL, flim, mel = FALSE, norm = FALSE, PMF = FALSE)
spec |
a vector or a two-column matrix set resulting of a spectral analysis.
This can be the value obtained with |
f |
sampling frequency of |
flim |
a vector of length 2 to specify the new frequency range (in kHz). |
mel |
a logical, if |
norm |
a logical, if |
PMF |
a logical, if |
A new spectrum is returned.
The class of the returned object is the one of the input object (spec
)
The sampling frequency f
is not necessary if spec
has been obtained with
either spec
or meanspec
.
This function can be used before calling analysis function like sh
or
sfm
. See examples.
Jerome Sueur, improved by Laurent Lellouch
data(orni) a <- meanspec(orni,f=22050,plot=FALSE) b <- cutspec(a,flim=c(4,8)) ## quick check with a plot plot(b,type="l") ## effects on spectral entropy sfm(a) sfm(b) ## mel scale require(tuneR) mel <- melfcc(orni, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) melspec.mean <- apply(mel$aspectrum, MARGIN=2, FUN=mean) c <- cutspec(melspec.mean, f=22050, flim=c(4000,8000), mel=TRUE)
data(orni) a <- meanspec(orni,f=22050,plot=FALSE) b <- cutspec(a,flim=c(4,8)) ## quick check with a plot plot(b,type="l") ## effects on spectral entropy sfm(a) sfm(b) ## mel scale require(tuneR) mel <- melfcc(orni, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) melspec.mean <- apply(mel$aspectrum, MARGIN=2, FUN=mean) c <- cutspec(melspec.mean, f=22050, flim=c(4000,8000), mel=TRUE)
This function selects and cuts a section of data describing a time wave. Original and cut sections can be plotted as oscillograms for comparison.
cutw(wave, f, channel=1, from = NULL, to = NULL, choose = FALSE, plot = FALSE, marks = TRUE, output="matrix", ...)
cutw(wave, f, channel=1, from = NULL, to = NULL, choose = FALSE, plot = FALSE, marks = TRUE, output="matrix", ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
from |
start mark (in s). |
to |
end mark (in s). |
choose |
logical, if |
plot |
logical, if |
marks |
logical, if |
output |
character string, the class of the object to return,
either |
... |
other |
If plot
is TRUE
returns a two-frame plot with both
original and cut sections.
If plot
is FALSE
, a new wave is returned. The class
of the returned object is set with the argument output
.
Jerome Sueur
oscillo
, addsilw
,deletew
,
fadew
,mutew
,pastew
,revw
,
zapsilw
# a 0.4 s section in a bird song data(tico) a<-cutw(tico,f=22050,from=0.5,to=0.9) oscillo(a,22050) # a direct way to see what has been cut cutw(tico,f=22050,from=0.5,to=0.9,plot=TRUE)
# a 0.4 s section in a bird song data(tico) a<-cutw(tico,f=22050,from=0.5,to=0.9) oscillo(a,22050) # a direct way to see what has been cut cutw(tico,f=22050,from=0.5,to=0.9,plot=TRUE)
This function displays a vertical or horizontal dB colour scale to be used with
spectro
plots.
dBscale(collevels, palette = spectro.colors, side = 4, textlab = "Amplitude\n(dB)", cexlab = 0.75, fontlab = 1, collab = "black", colaxis = "black",...)
dBscale(collevels, palette = spectro.colors, side = 4, textlab = "Amplitude\n(dB)", cexlab = 0.75, fontlab = 1, collab = "black", colaxis = "black",...)
collevels |
a set of levels which are used to partition the amplitude range of the spectrogram (in dB). |
palette |
a color palette function to be used to assign colors in
the plot, see |
side |
side of the axis. |
textlab |
text of the label. |
cexlab |
character size of the label. |
fontlab |
font of the label. |
collab |
colour of the label. |
colaxis |
colour of the axis. |
... |
other |
This function, based on filled.contour
by Ross Ihaka,
is not supposed to be used by itself but as a legend of spectro
.
Any colour palette can be used. In particular, it is possible
to use other palettes coming with
seewave: rev.gray.colors.1
, rev.gray.colors.2
,
rev.heat.colors
, rev.terrain.colors
, rev.topo.colors
,
rev.cm.colors
corresponding to the reverse of heat.colors
,
terrain.colors
, topo.colors
, cm.colors
.
Jerome Sueur [email protected] and Caroline Simonis [email protected].
data(pellucens) # place the scale on the left and not on the right as spectro() does def.par <- par(no.readonly = TRUE) layout(matrix(c(1, 2), nc = 2), widths = c(1, 5)) par(mar=c(5,3,4,2)) dBscale(collevels=seq(-30,0,1),side=2) par(mar=c(5,4,4,2)) spectro(pellucens, f=22050,wl=512,scale=FALSE) par(def.par) # place the scale on the top and not on the right as spectro() does def.par <- par(no.readonly = TRUE) layout(matrix(c(0,1,2,2), nc = 2, byrow=TRUE),widths=c(1,2),heights=(c(1,5.5))) par(mar=c(0.5,3,4,2)) dBscale(collevels=seq(-30,0,1), textlab = "",side=3) mtext("Amplitude (dB)",side=2,line = 1,at=0.6,cex=0.75) par(mar=c(5,4,0.5,2)) spectro(pellucens, f=22050,wl=512,scale=FALSE) par(def.par)
data(pellucens) # place the scale on the left and not on the right as spectro() does def.par <- par(no.readonly = TRUE) layout(matrix(c(1, 2), nc = 2), widths = c(1, 5)) par(mar=c(5,3,4,2)) dBscale(collevels=seq(-30,0,1),side=2) par(mar=c(5,4,4,2)) spectro(pellucens, f=22050,wl=512,scale=FALSE) par(def.par) # place the scale on the top and not on the right as spectro() does def.par <- par(no.readonly = TRUE) layout(matrix(c(0,1,2,2), nc = 2, byrow=TRUE),widths=c(1,2),heights=(c(1,5.5))) par(mar=c(0.5,3,4,2)) dBscale(collevels=seq(-30,0,1), textlab = "",side=3) mtext("Amplitude (dB)",side=2,line = 1,at=0.6,cex=0.75) par(mar=c(5,4,0.5,2)) spectro(pellucens, f=22050,wl=512,scale=FALSE) par(def.par)
This function returns the four most common dB weightings.
dBweight(f, dBref = NULL)
dBweight(f, dBref = NULL)
f |
frequency (in Hz). |
dBref |
dB reference level (by default |
By default, the function returns four weightings. When
dBref
is not NULL
then the function returns the
conversion from a dB reference level to four dB weighting levels.
dBweight
returns a list of five items corresponding to five
dB weightings.
A |
dB (A) |
B |
dB (B) |
C |
dB (C) |
D |
dB (D) |
ITU |
dB ITU-R 468 |
The transfer equations used here come from Wipipedia but they were originally coming from the appendix of an international standard on the design performance of sound level meters IEC 651:1979 (Neil Glenister, pers. com.).
Jerome Sueur [email protected], Zev Ross, and Andrey Anikin
https://en.wikipedia.org/wiki/A-weighting, https://en.wikipedia.org/wiki/ITU-R_468_noise_weighting
# weight for a 50 Hz frequency dBweight(f=50) # A weight for the 1/3 Octave centre frequencies. dBweight(f=c(20,25,31.5,40,50,63,80,100,125,160,200,250, 315,400,500,630,800,1000,1500, 1600,2000,2500,3150,4000,5000, 6300,8000,10000,12500,16000,20000))$A # correction for a 50 Hz sound emitted at 100 dB dBweight(f=50, dB=100) # weighting curves plot f <- seq(10,20000,by=10) par(las=1) plot(f, dBweight(f)$A, type="n", log="x", xlim=c(10,10^5),ylim=c(-80,20),xlab="",ylab="",xaxt="n",yaxt="n") abline(v=c(seq(10,100,by=10),seq(100,1000,by=100), seq(1000,10000,by=1000),seq(10000,100000,by=10000), c(100,1000,10000,100000)),col="lightgrey",lty=2) abline(v=c(100,1000,10000,100000),col="grey") abline(h=seq(-80, 20, 20),col="grey") par(new=TRUE) plot(f, dBweight(f)$A, type="l", log="x", xlab="Frequency (Hz)", ylab="dB",lwd=2, col="blue", xlim=c(10,10^5),ylim=c(-80,20)) title(main="Acoustic weighting curves (10 Hz - 20 kHz)") lines(x=f, y=dBweight(f)$B, col="green",lwd=2) lines(x=f, y=dBweight(f)$C, col="red",lwd=2) lines(x=f, y=dBweight(f)$D, col="black",lwd=2) legend("bottomright",legend=c("dB(A)","dB(B)","dB(C)","dB(D)"), lwd=2,col=c("blue","green","red","black"),bty="o",bg="white")
# weight for a 50 Hz frequency dBweight(f=50) # A weight for the 1/3 Octave centre frequencies. dBweight(f=c(20,25,31.5,40,50,63,80,100,125,160,200,250, 315,400,500,630,800,1000,1500, 1600,2000,2500,3150,4000,5000, 6300,8000,10000,12500,16000,20000))$A # correction for a 50 Hz sound emitted at 100 dB dBweight(f=50, dB=100) # weighting curves plot f <- seq(10,20000,by=10) par(las=1) plot(f, dBweight(f)$A, type="n", log="x", xlim=c(10,10^5),ylim=c(-80,20),xlab="",ylab="",xaxt="n",yaxt="n") abline(v=c(seq(10,100,by=10),seq(100,1000,by=100), seq(1000,10000,by=1000),seq(10000,100000,by=10000), c(100,1000,10000,100000)),col="lightgrey",lty=2) abline(v=c(100,1000,10000,100000),col="grey") abline(h=seq(-80, 20, 20),col="grey") par(new=TRUE) plot(f, dBweight(f)$A, type="l", log="x", xlab="Frequency (Hz)", ylab="dB",lwd=2, col="blue", xlim=c(10,10^5),ylim=c(-80,20)) title(main="Acoustic weighting curves (10 Hz - 20 kHz)") lines(x=f, y=dBweight(f)$B, col="green",lwd=2) lines(x=f, y=dBweight(f)$C, col="red",lwd=2) lines(x=f, y=dBweight(f)$D, col="black",lwd=2) legend("bottomright",legend=c("dB(A)","dB(B)","dB(C)","dB(D)"), lwd=2,col=c("blue","green","red","black"),bty="o",bg="white")
This function selects and delete a section of data describing a time wave. Original section and section after deletion can be plotted as oscillograms for comparison.
deletew(wave, f, channel = 1, from = NULL, to = NULL, choose = FALSE, plot = FALSE, marks = TRUE, output = "matrix", ...)
deletew(wave, f, channel = 1, from = NULL, to = NULL, choose = FALSE, plot = FALSE, marks = TRUE, output = "matrix", ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
from |
start position (in s). |
to |
end position (in s). |
choose |
logical, if |
plot |
logical, if |
marks |
logical, if |
output |
character string, the class of the object to return, either "matrix", "Wave", "Sample", "audioSample" or "ts". |
... |
other |
If plot
is TRUE
returns a two-frame plot with both
original and resulting sections.
If plot
is FALSE
, a new wave is returned. The class
of the returned object is set with the argument output
.
Jerome Sueur [email protected]
oscillo
, addsilw
,cutw
,
fadew
, mutew
, pastew
,
revw
, zapsilw
# deletion a 0.4 s section in a bird song data(tico) a<-deletew(tico,f=22050,from=0.5,to=0.9) oscillo(a,22050) # a direct way to see what has been cut deletew(tico,f=22050,from=0.5,to=0.9,plot=TRUE)
# deletion a 0.4 s section in a bird song data(tico) a<-deletew(tico,f=22050,from=0.5,to=0.9) oscillo(a,22050) # a direct way to see what has been cut deletew(tico,f=22050,from=0.5,to=0.9,plot=TRUE)
This function gives the dominant frequency (i. e. the frequency of highest amplitude) of a time wave.
dfreq(wave, f, channel = 1, wl = 512, wn = "hanning", ovlp = 0, fftw= FALSE, at = NULL, tlim = NULL, threshold = NULL, bandpass = NULL, clip = NULL, plot = TRUE, xlab = "Times (s)", ylab = "Frequency (kHz)", ylim = c(0, f/2000), ...)
dfreq(wave, f, channel = 1, wl = 512, wn = "hanning", ovlp = 0, fftw= FALSE, at = NULL, tlim = NULL, threshold = NULL, bandpass = NULL, clip = NULL, plot = TRUE, xlab = "Times (s)", ylab = "Frequency (kHz)", ylim = c(0, f/2000), ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
wl |
length of the window for the analysis (even number of points, by default = 512). |
wn |
window name, see |
ovlp |
overlap between two successive analysis windows (in % ). |
fftw |
if |
at |
time position where the dominant frequency has to be computed (in s.). |
tlim |
modifications of the time X-axis limits. |
threshold |
amplitude threshold for signal detection (in % ). |
bandpass |
a numeric vector of length two, giving the lower and upper limits of a frequency bandpass filter (in Hz). |
clip |
a numeric value to select dominant frequency values according to their amplitude in reference to a maximal value of 1 for the whole signal (has to be >0 & < 1). |
plot |
logical, if |
xlab |
title of the x axis. |
ylab |
title of the y axis. |
ylim |
the range of y values. |
... |
other |
When plot
is FALSE
, dfreq
returns a two-column matrix, the first column corresponding to time in seconds (x-axis) and the second column corresponding to
to dominant frequency in kHz (y-axis).
NA corresponds to pause sections in wave
(see threshold
).
This function is based on fft
.
Jerome Sueur [email protected]
data(tico) f <- 22050 # default dfreq(tico,f) # using the amplitude threshold and changing the graphical output dfreq(tico, f, ovlp=50,threshold=5, type="l", col=2) # using 'at' argument for specific positions along the time axis dfreq(tico, f, at=c(0.25, 0.75, 1.2, 1.6)) dfreq(tico, f, at=seq(0.5, 1.4, by=0.005), threshold=5) # a specific number of measures on a single note dfreq(tico, f, at=seq(0.5, 0.9, len=100), threshold=5, xlim=c(0.5,0.9)) # overlap on spectrogram # and use of 'clip' argument to better track the dominant frequency # in noisy conditions op <- par() ticon <- tico@left/max(tico@left) + noisew(d=length(tico@left)/f, f) spectro(ticon, f) res <- dfreq(ticon, f, clip=0.3, plot=FALSE) points(res, col=2, pch =13) par(op)
data(tico) f <- 22050 # default dfreq(tico,f) # using the amplitude threshold and changing the graphical output dfreq(tico, f, ovlp=50,threshold=5, type="l", col=2) # using 'at' argument for specific positions along the time axis dfreq(tico, f, at=c(0.25, 0.75, 1.2, 1.6)) dfreq(tico, f, at=seq(0.5, 1.4, by=0.005), threshold=5) # a specific number of measures on a single note dfreq(tico, f, at=seq(0.5, 0.9, len=100), threshold=5, xlim=c(0.5,0.9)) # overlap on spectrogram # and use of 'clip' argument to better track the dominant frequency # in noisy conditions op <- par() ticon <- tico@left/max(tico@left) + noisew(d=length(tico@left)/f, f) spectro(ticon, f) res <- dfreq(ticon, f, clip=0.3, plot=FALSE) points(res, col=2, pch =13) par(op)
This function compares two distributions (e.g. two frequency spectra) by computing the difference between two cumulative frequency spectra
diffcumspec(spec1, spec2, f = NULL, mel = FALSE, plot = FALSE, type = "l", lty = c(1, 2), col = c(2, 4, 8), flab = NULL, alab = "Cumulated amplitude", flim = NULL, alim = NULL, title = TRUE, legend = TRUE, ...)
diffcumspec(spec1, spec2, f = NULL, mel = FALSE, plot = FALSE, type = "l", lty = c(1, 2), col = c(2, 4, 8), flab = NULL, alab = "Cumulated amplitude", flim = NULL, alim = NULL, title = TRUE, legend = TRUE, ...)
spec1 |
any distribution, especially a spectrum obtained with |
spec2 |
any distribution, especially a spectrum obtained with
|
f |
sampling frequency of waves used to obtain |
mel |
a logical, if |
plot |
logical, if |
type |
if |
col |
a vector of length 3 for the colour of |
lty |
a vector of length 2 for the line type of |
flab |
title of the frequency axis. |
alab |
title of the amplitude axis. |
flim |
the range of frequency values. |
alim |
range of amplitude axis. |
title |
logical, if |
legend |
logical, if |
... |
other |
Both spectra are transformed into cumulative distribution functions
(CDF).
Spectral difference is then computed according to:
A numeric vector of length 1 returning the difference between the two spectra. No unit.
This metric is sensitive not only to the spectral overlap between but also to the mean frequential distance between the different frequency peaks.
Laurent Lellouch, Jerome Sueur
Lellouch L, Pavoine S, Jiguet F, Glotin H, Sueur J (2014) Monitoring temporal change of bird communities with dissimilarity acoustic indices. Methods in Ecology and Evolution, in press.
kl.dist
, ks.dist
, simspec
,
diffspec
, logspec.dist
, itakura.dist
## Hz scale data(tico) data(orni) orni.hz <- meanspec(orni, plot=FALSE) tico.hz <- meanspec(tico, plot=FALSE) diffcumspec(orni.hz, tico.hz, plot=TRUE) ## mel scale require(tuneR) orni.mel <- melfcc(orni, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) orni.mel.mean <- apply(orni.mel$aspectrum, MARGIN=2, FUN=mean) tico.mel <- melfcc(tico, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) tico.mel.mean <- apply(tico.mel$aspectrum, MARGIN=2, FUN=mean) diffcumspec(orni.mel.mean, tico.mel.mean, f=22050, mel=TRUE, plot=TRUE)
## Hz scale data(tico) data(orni) orni.hz <- meanspec(orni, plot=FALSE) tico.hz <- meanspec(tico, plot=FALSE) diffcumspec(orni.hz, tico.hz, plot=TRUE) ## mel scale require(tuneR) orni.mel <- melfcc(orni, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) orni.mel.mean <- apply(orni.mel$aspectrum, MARGIN=2, FUN=mean) tico.mel <- melfcc(tico, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) tico.mel.mean <- apply(tico.mel$aspectrum, MARGIN=2, FUN=mean) diffcumspec(orni.mel.mean, tico.mel.mean, f=22050, mel=TRUE, plot=TRUE)
This function estimates the surface difference between two amplitude envelopes.
diffenv(wave1, wave2, f, channel = c(1,1), envt = "hil", msmooth = NULL, ksmooth = NULL, plot = FALSE, lty1 = 1, lty2 = 2, col1 = 2, col2 = 4, cold = 8, xlab = "Time (s)", ylab = "Amplitude", ylim = NULL, legend = TRUE, ...)
diffenv(wave1, wave2, f, channel = c(1,1), envt = "hil", msmooth = NULL, ksmooth = NULL, plot = FALSE, lty1 = 1, lty2 = 2, col1 = 2, col2 = 4, cold = 8, xlab = "Time (s)", ylab = "Amplitude", ylim = NULL, legend = TRUE, ...)
wave1 |
a first R object. |
wave2 |
a second R object. |
f |
sampling frequency of |
channel |
channel of the R objects, by default left channel (1) for each object. |
envt |
the type of envelope to be used: either "abs" for absolute
amplitude envelope or "hil" for Hilbert amplitude envelope. See |
msmooth |
a vector of length 2 to smooth the amplitude envelope with a
mean sliding window. The first component is the window length
(in number of points). The second component is the overlap between
successive windows (in %). See |
ksmooth |
|
plot |
logical, if |
lty1 |
line type of the first envelope (envelope of |
lty2 |
line type of the second envelope (envelope of |
col1 |
colour of the first envelope (envelope of |
col2 |
colour of the second envelope (envelope of |
cold |
colour of the surface difference. |
xlab |
title of the time axis. |
ylab |
title of the amplitude axis. |
ylim |
range of amplitude axis. |
legend |
logical, if |
... |
other |
D is a Manhattan distance (l1 norm).
Envelopes of both waves are first transformed as probability mass functions (PMF).
Envelope difference is then computed according to:
The difference is returned. This value is without unit.
When plot
is TRUE
, both envelopes and their difference surface are
plotted on the same graph.
This method can be used as a relative distance estimation between different envelopes.
Jerome Sueur [email protected].
Sueur, J., Pavoine, S., Hamerlynck, O. & Duvail, S. (2008) - Rapid acoustic survey for biodiversity appraisal. PLoS ONE, 3(12): e4065.
env
, corenv
, diffspec
,
diffwave
data(tico) ; tico <- tico@left data(orni) ; orni <- orni@left # selection in tico of two waves with similar duration tico2<-tico[1:length(orni)] diffenv(tico2,orni,f=22050,plot=TRUE) # smoothing the envelope gives a better graph but slightly changes the result diffenv(tico2,orni,f=22050,msmooth=c(20,0),plot=TRUE)
data(tico) ; tico <- tico@left data(orni) ; orni <- orni@left # selection in tico of two waves with similar duration tico2<-tico[1:length(orni)] diffenv(tico2,orni,f=22050,plot=TRUE) # smoothing the envelope gives a better graph but slightly changes the result diffenv(tico2,orni,f=22050,msmooth=c(20,0),plot=TRUE)
This function estimates the surface difference between two frequency spectra.
diffspec(spec1, spec2, f = NULL, mel = FALSE, plot = FALSE, type="l", lty=c(1, 2), col =c(2, 4, 8), flab = NULL, alab = "Amplitude", flim = NULL, alim = NULL, title = TRUE, legend = TRUE, ...)
diffspec(spec1, spec2, f = NULL, mel = FALSE, plot = FALSE, type="l", lty=c(1, 2), col =c(2, 4, 8), flab = NULL, alab = "Amplitude", flim = NULL, alim = NULL, title = TRUE, legend = TRUE, ...)
spec1 |
a first data set resulting of a spectral analysis obtained
with |
spec2 |
a first data set resulting of a spectral analysis obtained
with |
f |
sampling frequency of waves used to obtain |
mel |
a logical, if |
plot |
logical, if |
type |
if |
lty |
a vector of length 2 for the line type of |
col |
a vector of length 3 for the colour of |
flab |
title of the frequency axis. |
alab |
title of the amplitude axis. |
flim |
the range of frequency values. |
alim |
range of amplitude axis. |
title |
logical, if |
legend |
logical, if |
... |
other |
D is a Manhattan distance (l1 norm).
Both spectra are first transformed as probability mass functions (PMF).
Spectral difference is then computed according to:
, with 0 < D < 1.
The difference is returned. This value is without unit.
When plot
is TRUE
, both spectra and their difference surface are
plotted on the same graph.
This method can be used as a relative distance estimation
between different spectra.
The dB value obtained can be very different from the one visually estimated
when looking at the graph (plot=TRUE
).
Jerome Sueur, Sandrine Pavoine and Laurent Lellouch
Sueur, J., Pavoine, S., Hamerlynck, O. and Duvail, S. (2008). Rapid acoustic survey for biodiversity appraisal. PLoS One, 3(12): e4065.
spec
, meanspec
, corspec
,
simspec
, diffcumspec
, diffenv
, kl.dist
,
ks.dist
, logspec.dist
, itakura.dist
a <- noisew(f=8000,d=1) b <- synth(f=8000,d=1,cf=2000) c <- synth(f=8000,d=1,cf=1000) d <- noisew(f=8000,d=1) speca <- spec(a,f=8000,wl=512,at=0.5,plot=FALSE) specb <- spec(b,f=8000,wl=512,at=0.5,plot=FALSE) specc <- spec(c,f=8000,wl=512,at=0.5,plot=FALSE) specd <- spec(d,f=8000,wl=512,at=0.5,plot=FALSE) diffspec(speca,speca,f=8000) #[1] 0 => similar spectra of course ! diffspec(speca,specb) diffspec(speca,specc,plot=TRUE) diffspec(specb,specc,plot=TRUE) diffspec(speca,specd,plot=TRUE) ## mel scale require(tuneR) data(orni) data(tico) orni.mel <- melfcc(orni, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) orni.mel.mean <- apply(orni.mel$aspectrum, MARGIN=2, FUN=mean) tico.mel <- melfcc(tico, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) tico.mel.mean <- apply(tico.mel$aspectrum, MARGIN=2, FUN=mean) diffspec(orni.mel.mean, tico.mel.mean, f=22050, mel=TRUE, plot=TRUE)
a <- noisew(f=8000,d=1) b <- synth(f=8000,d=1,cf=2000) c <- synth(f=8000,d=1,cf=1000) d <- noisew(f=8000,d=1) speca <- spec(a,f=8000,wl=512,at=0.5,plot=FALSE) specb <- spec(b,f=8000,wl=512,at=0.5,plot=FALSE) specc <- spec(c,f=8000,wl=512,at=0.5,plot=FALSE) specd <- spec(d,f=8000,wl=512,at=0.5,plot=FALSE) diffspec(speca,speca,f=8000) #[1] 0 => similar spectra of course ! diffspec(speca,specb) diffspec(speca,specc,plot=TRUE) diffspec(specb,specc,plot=TRUE) diffspec(speca,specd,plot=TRUE) ## mel scale require(tuneR) data(orni) data(tico) orni.mel <- melfcc(orni, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) orni.mel.mean <- apply(orni.mel$aspectrum, MARGIN=2, FUN=mean) tico.mel <- melfcc(tico, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) tico.mel.mean <- apply(tico.mel$aspectrum, MARGIN=2, FUN=mean) diffspec(orni.mel.mean, tico.mel.mean, f=22050, mel=TRUE, plot=TRUE)
This function estimates the difference between two waves by computing the product between envelope surface difference and frequency surface difference.
diffwave(wave1, wave2, f, channel = c(1,1), wl = 512, envt = "hil", msmooth = NULL, ksmooth = NULL)
diffwave(wave1, wave2, f, channel = c(1,1), wl = 512, envt = "hil", msmooth = NULL, ksmooth = NULL)
wave1 |
a first R object. |
wave2 |
a second R object. |
f |
sampling frequency of |
channel |
channel of the R objects, by default left channel (1) for each object. |
wl |
window length for spectral analysis (even number of points). |
envt |
the type of envelope to be used: either "abs" for absolute
amplitude envelope or "hil" for Hilbert amplitude envelope. See |
msmooth |
a vector of length 2 to smooth the amplitude envelope with a
mean sliding window. The first component is the window length
(in number of points). The second component is the overlap between
successive windows (in %). See |
ksmooth |
D is a Manhattan distance (l1 norm).
This function computes the product between the values obtained with
diffspec
and diffenv
functions.
This then gives a global (time and frequency) estimation of dissimilarity.
The frequency mean spectrum and the amplitude envelope needed for computing
respectively diffspec
and diffenv
are automatically generated.
They can be controlled through wl
, msmooth
and ksmooth
arguments respectively.
See examples below and examples in diffspec
and diffenv
for implications on the results.
A single value varying between 0 and 1 is returned. The value has no unit.
This method can be used as a relative distance estimation between different waves.
Jerome Sueur [email protected]
Sueur, J., Pavoine, S., Hamerlynck, O. & Duvail, S. (2008) - Rapid acoustic survey for biodiversity appraisal. PLoS ONE, 3(12): e4065.
data(tico) ; tico <- tico@left data(orni) ; orni <- orni@left # selection in tico to have two waves of similar duration (length) tico <- tico[1:length(orni)] diffwave(tico,orni,f=22050) # changing the frequency parameter (wl) diffwave(tico,orni,f=22050,wl=1024) # changing the temporal parameter (msmooth) diffwave(tico,orni,f=22050,msmooth=c(20,0))
data(tico) ; tico <- tico@left data(orni) ; orni <- orni@left # selection in tico to have two waves of similar duration (length) tico <- tico[1:length(orni)] diffwave(tico,orni,f=22050) # changing the frequency parameter (wl) diffwave(tico,orni,f=22050,wl=1024) # changing the temporal parameter (msmooth) diffwave(tico,orni,f=22050,msmooth=c(20,0))
This function transforms a numeric (time) series into a sequence of symbols
discrets(x, symb = 5, collapse = TRUE, plateau=1)
discrets(x, symb = 5, collapse = TRUE, plateau=1)
x |
a |
symb |
the number of symbols used for the discretisation, can be set to 3 or 5 only. |
collapse |
logical, if |
plateau |
a numeric vector of length 1 taking the values |
The function partitions the numeric (time) series into a sequence of finite number of symbols.
These symbols result of the comparaison of each series value with its temporal neighbours.
They are two discretisations available:
when symb
is set to 3, each value will be replaced by either:
- I if the series is Increasing,
- D if the series is Decreasing,
- F if the series remains Flat,
when symb
is set to 5, each value will be replaced by either:
- I if the series is Increasing,
- D if the series is Decreasing,
- F if the series remains Flat,
- P if the series shows a Peak,
- T if the series shows a Trough.
The argument plateau
can be used to control the way a plateau
is encoded. A plateau is an elevated flat region that can be either
considered a 'flat peak' encoded as PF...FP (plateau
= 1
) or as an increase, a flat region and a decrease encoded as
IF...FD (plateau = 1
. The default value (plateau
= 1
) refers to Cazelles et al. (2004).
A character string of length 1 if collapse
is TRUE
.
Otherwise, a character string of length n-2 if symbol=5
(the first and last values cannot be replaced with a symbol)
or n-1 if symbol=3
(the first value cannot be replaced with a symbol.)
Jerome Sueur, improved by Laurent Lellouch
Cazelles, B. 2004 Symbolic dynamics for identifying similarity between rhythms of ecological time series. Ecology Letters, 7: 755-763.
# a random variable discrets(rnorm(30)) discrets(rnorm(30),symb=3) # a frequency spectrum data(tico) spec1<-spec(tico,f=22050,at=0.2,plot=FALSE) discrets(spec1[,2])
# a random variable discrets(rnorm(30)) discrets(rnorm(30),symb=3) # a frequency spectrum data(tico) spec1<-spec(tico,f=22050,at=0.2,plot=FALSE) discrets(spec1[,2])
This function lets the user modifying the amplitude envelope of a time wave by drawing it with the graphics device
drawenv(wave, f, channel = 1, n = 20, plot = FALSE, listen = FALSE, output = "matrix")
drawenv(wave, f, channel = 1, n = 20, plot = FALSE, listen = FALSE, output = "matrix")
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
n |
the maximum number of points to draw the new envelope. Valid values start at 1. |
plot |
if |
listen |
if |
output |
character string, the class of the object to return, either
|
The function first plots an oscillogram view of wave
.
The user has then to choose points on the positive side of the y-axis (amplitude).
The junction of these points will draw a new amplitude envelope.
The order of points along the x-axis (time) is not important
but points cannot be cancelled. When this process is finished
the new time wave is returned in the console or as an oscillogram
in a second graphics device if plot
is TRUE
.
The function uses locator
.
If plot
is FALSE
, a new wave is returned. The class
of the returned object is set with the argument output
.
Jerome Sueur [email protected]
## Not run: a<-synth(d=1,f=22050,cf=1000) # drawenv(a,f=22050,plot=TRUE) # choose points on the oscillogram view to draw a new enveloppe # stop (ESC on Windows; right mouse button on Linux) # check the result on the second graphics device opened thanks to plot=TRUE ## End(Not run)
## Not run: a<-synth(d=1,f=22050,cf=1000) # drawenv(a,f=22050,plot=TRUE) # choose points on the oscillogram view to draw a new enveloppe # stop (ESC on Windows; right mouse button on Linux) # check the result on the second graphics device opened thanks to plot=TRUE ## End(Not run)
This function lets the user drawing the amplitude profile of a frequency filter.
drawfilter(f, n = 256, continuous = TRUE, discrete = TRUE)
drawfilter(f, n = 256, continuous = TRUE, discrete = TRUE)
f |
a numeric vector of length 1 for the sampling frequency of the object to be filtered (in Hz). |
n |
a numeric vector of length 1 for the length (i.e. number of points) of the filter. By default = 256 to fit with a FIR with wl = 512. |
continuous |
a logical ( |
discrete |
a logical ( |
If the same frequency of a discrete filter is selected twice then the sum of the amplitudes of the two selections is used.
If both arguments continuous
and discrete
are set to TRUE
and if frequencies selected overlap between the two filters then only the frequencies of the discrete filter are considered.
The function returns a two-column matrix, the first column is the frequency in kHz and the second column is the amplitude of the filter.
This function can be used to prepare bandpass or bandstop custom filters to be used with fir
and ffilter
. See examples.
Laurent Lellouch
fir
, squarefilter
, combfilter
, ffilter
, drawenv
## Not run: f <- 8000 a <- noisew(f=f, d=1) ## bandpass continuous and discrete cont.disc <- drawfilter(f=f/2) a.cont.disc <- fir(a, f=f, custom=cont.disc) spectro(a.cont.disc, f=f) ## bandpass continuous only cont <- drawfilter(f=f/2, discrete=FALSE) a.cont <- fir(a, f=f, custom=cont) spectro(a.cont, f=f) ## bandstop continuous only cont.stop <- drawfilter(f=f/2, discrete=FALSE) a.cont.stop <- fir(a, f=f, custom=cont.stop, bandpass=FALSE) spectro(a.cont.stop, f=f) ## bandpass discrete only disc <- drawfilter(f=f/2, continuous=FALSE) a.disc <- fir(a, f=f, custom=disc, bandpass=FALSE) spectro(a.disc, f=f) ## End(Not run)
## Not run: f <- 8000 a <- noisew(f=f, d=1) ## bandpass continuous and discrete cont.disc <- drawfilter(f=f/2) a.cont.disc <- fir(a, f=f, custom=cont.disc) spectro(a.cont.disc, f=f) ## bandpass continuous only cont <- drawfilter(f=f/2, discrete=FALSE) a.cont <- fir(a, f=f, custom=cont) spectro(a.cont, f=f) ## bandstop continuous only cont.stop <- drawfilter(f=f/2, discrete=FALSE) a.cont.stop <- fir(a, f=f, custom=cont.stop, bandpass=FALSE) spectro(a.cont.stop, f=f) ## bandpass discrete only disc <- drawfilter(f=f/2, continuous=FALSE) a.disc <- fir(a, f=f, custom=disc, bandpass=FALSE) spectro(a.disc, f=f) ## End(Not run)
Returns the duration (in second) of a time wave
duration(wave, f, channel=1)
duration(wave, f, channel=1)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
A numeric vector of length 1 returning the duration in second.
Jerome Sueur
data(tico) duration(tico)
data(tico) duration(tico)
This graphical function displays a time wave as an windowed oscillogram.
dynoscillo(wave, f, channel = 1, wd = NULL, wl = NULL, wnb = NULL, title = TRUE, ...)
dynoscillo(wave, f, channel = 1, wd = NULL, wl = NULL, wnb = NULL, title = TRUE, ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
wd |
a numerical vector, duration of the window (in seconds) |
wl |
a numerical vector, length of the window (in number of points). |
wnb |
a numerical vector, number of windows (no unit). |
title |
a logical, if |
... |
other |
The arguments wd
, wl
and wn
have to be used isolated, not in conjunction. They basically do the same, ie they set the duration of the zooming window that is slided along the signal. For instance, for a 5 seconds sound with a sampling rate (f
) at 44.1 kHz, wl = 4096
is equivalent to wd = 4096 / 44100 = 0.093 s
and equivalent to wnb = 5*4096 / 44100 = 53
.
This function requires the package rpanel
.
Jerome Sueur
## Not run: require(rpanel) data(tico) dynoscillo(tico, wn=4) ## End(Not run)
## Not run: require(rpanel) data(tico) dynoscillo(tico, wn=4) ## End(Not run)
This function plots dynamically a sliding spectrum along a time wave. This basically corresponds to a short-term Fourier transform.
dynspec(wave, f, channel = 1, wl = 512, wn = "hanning", zp = 0, ovlp = 0, fftw = FALSE, norm = FALSE, dB = NULL, dBref = NULL, plot = TRUE, title = TRUE, osc = FALSE, tlab = "Time (s)", flab = "Frequency (kHz)", alab = "Amplitude", alim = NULL, flim = c(0, f/2000), type = "l", from = NULL, to = NULL, envt = NULL, msmooth = NULL, ksmooth = NULL, colspec = "black", coltitle = "black", colbg = "white", colline = "black", colaxis = "black", collab = "black", cexlab = 1, fontlab = 1, colwave = "black", coly0 = "lightgrey", colcursor = "red", bty = "l")
dynspec(wave, f, channel = 1, wl = 512, wn = "hanning", zp = 0, ovlp = 0, fftw = FALSE, norm = FALSE, dB = NULL, dBref = NULL, plot = TRUE, title = TRUE, osc = FALSE, tlab = "Time (s)", flab = "Frequency (kHz)", alab = "Amplitude", alim = NULL, flim = c(0, f/2000), type = "l", from = NULL, to = NULL, envt = NULL, msmooth = NULL, ksmooth = NULL, colspec = "black", coltitle = "black", colbg = "white", colline = "black", colaxis = "black", collab = "black", cexlab = 1, fontlab = 1, colwave = "black", coly0 = "lightgrey", colcursor = "red", bty = "l")
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
wl |
if |
wn |
window name, see |
zp |
zero-padding (even number of points), see |
ovlp |
overlap between two successive windows (in % ). |
fftw |
if |
norm |
logical, if |
dB |
a character string specifying the type dB to return: "max0" for a maximum dB value at 0, "A", "B", "C", "D", and "ITU" for common dB weights. |
dBref |
a dB reference value when |
plot |
logical, if |
title |
logical, if |
osc |
logical, if |
tlab |
title of the time axis. |
flab |
title of the frequency axis. |
alab |
title of the amplitude axis. |
flim |
range of frequency axis. |
alim |
range of amplitude axis. |
type |
type of plot that should be drawn for the sliding spectrum.
See |
from |
start mark where to compute the sliding spectrum (in s). |
to |
end mark where to compute the sliding spectrum (in s). |
envt |
the type of envelope to be plooted:
either "abs" for absolute amplitude envelope or "hil" for Hilbert amplitude envelope.
See |
msmooth |
when |
ksmooth |
|
colspec |
colour of the sliding spectrum. |
coltitle |
if |
colbg |
background colour. |
colline |
colour of axes line. |
colaxis |
colour of the axes. |
collab |
colour of axes title. |
cexlab |
character size for axes title. |
fontlab |
font for axes title. |
colwave |
colour of the oscillogram or of the envelope (only when |
coly0 |
colour of the y=0 line (only when |
colcursor |
colour of oscillogram cursor (only when |
bty |
the type of box to be drawn around the oscillogram (only
when |
Use the slider panel to move along the time wave.
Use the argument norm
if you wish to have each spectrum normalised, i.e.
with values between 0 and 1 or maximised to 0 dB when dB
is TRUE
.
The function requires the package rpanel that is based on the package tcltk.
This function returns a list of three items:
time |
a numeric vector corresponding to the time axis. |
freq |
a numeric vector corresponding to the frequency axis. |
amp |
a numeric matrix corresponding to the amplitude values.
Each column is a Fourier transform of length |
This function is very similar to a spectrogram. See the Details
of
spectro
for some information regarding the short term Fourier
transform.
Jerome Sueur and Caroline Simonis
spectro
, spectro3D
,
wf
, spec
, dynspectro
,
fft
, oscillo
, env
.
## Not run: data(sheep) require(rpanel) dynspec(sheep,f=8000,wl=1024,ovlp=50,osc=TRUE) ## End(Not run)
## Not run: data(sheep) require(rpanel) dynspec(sheep,f=8000,wl=1024,ovlp=50,osc=TRUE) ## End(Not run)
This function plots dynamically a sliding spectrogram along a time wave.
dynspectro(wave, f, channel = 1, slidframe = 10, wl = 512, wn = "hanning", zp = 0, ovlp = 75, fftw = FALSE, dB = TRUE, plot = TRUE, title = TRUE, osc = FALSE, tlab = "Time (s)", flab = "Frequency (kHz)", alab = "Amplitude", from = NULL, to = NULL, collevels = NULL, palette = spectro.colors, envt = NULL, msmooth = NULL, ksmooth = NULL, coltitle = "black", colbg = "white", colline = "black", colaxis = "black", collab = "black", cexlab = 1, fontlab = 1, colwave = "black", coly0 = "lightgrey", colcursor = "red", bty = "l")
dynspectro(wave, f, channel = 1, slidframe = 10, wl = 512, wn = "hanning", zp = 0, ovlp = 75, fftw = FALSE, dB = TRUE, plot = TRUE, title = TRUE, osc = FALSE, tlab = "Time (s)", flab = "Frequency (kHz)", alab = "Amplitude", from = NULL, to = NULL, collevels = NULL, palette = spectro.colors, envt = NULL, msmooth = NULL, ksmooth = NULL, coltitle = "black", colbg = "white", colline = "black", colaxis = "black", collab = "black", cexlab = 1, fontlab = 1, colwave = "black", coly0 = "lightgrey", colcursor = "red", bty = "l")
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
slidframe |
size of the sliding frame (in percent of the wave duration). |
wl |
if |
wn |
window name, see |
zp |
zero-padding (even number of points), see |
ovlp |
overlap between two successive windows (in % ). |
fftw |
if |
dB |
a logical, if |
plot |
logical, if |
title |
logical, if |
osc |
logical, if |
tlab |
title of the time axis. |
flab |
title of the frequency axis. |
alab |
title of the amplitude axis. |
from |
start mark where to compute the sliding spectrogram (in s). |
to |
end mark where to compute the sliding spectrogram (in s). |
collevels |
a set of levels which are used to partition the amplitude range of the spectrogram. |
palette |
a color palette function to be used to assign colors in the plot. |
envt |
the type of envelope to be plooted:
either "abs" for absolute amplitude envelope or "hil" for Hilbert amplitude envelope.
See |
msmooth |
when |
ksmooth |
|
coltitle |
if |
colbg |
background colour. |
colline |
colour of axes line. |
colaxis |
colour of the axes. |
collab |
colour of axes title. |
cexlab |
character size for axes title. |
fontlab |
font for axes title. |
colwave |
colour of the oscillogram or of the envelope (only when |
coly0 |
colour of the y=0 line (only when |
colcursor |
colour of oscillogram cursor (only when |
bty |
the type of box to be drawn around the oscillogram (only
when |
Use the slider panel to move along the time wave.
The function requires the package rpanel that is based on the
package tcltk.
The function is mainly written for inspecting long sounds.
The function is based on image
for fast display when
spectro
is based on filled.contour
.
Displaying the amplitude envelope with the argument envt
can
slow down significantly the display.
This function returns a list of three items:
time |
a numeric vector corresponding to the time axis. |
freq |
a numeric vector corresponding to the frequency axis. |
amp |
a numeric matrix corresponding to the amplitude values.
Each column is a Fourier transform of length |
This function is very similar to a spectrogram. See the Details
of
spectro
for some information regarding the short term Fourier
transform.
David Pinaud and Jerome Sueur
spectro
, spectro3D
,
wf
, spec
, dynspec
,
fft
, oscillo
, env
.
## Not run: data(sheep) require(rpanel) dynspectro(sheep, ovlp=95, osc=TRUE) ## End(Not run)
## Not run: data(sheep) require(rpanel) dynspectro(sheep, ovlp=95, osc=TRUE) ## End(Not run)
This function generate echoes of a time wave.
echo(wave, f, channel = 1, amp, delay, plot = FALSE, listen = FALSE, output = "matrix", ...)
echo(wave, f, channel = 1, amp, delay, plot = FALSE, listen = FALSE, output = "matrix", ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
amp |
a vector describing the relative amplitude of the successive echoes. Each value of the vector should be in [0,1] |
delay |
a vector describing the time delays of the successive echoes
from the beginning of |
plot |
logical, if |
listen |
if |
output |
character string, the class of the object to return, either
|
... |
other |
amp
and delay
should strictly have the same length corresponding
to the number of desired echoes.
If plot
is FALSE
, a new wave is returned. The class
of the returned object is set with the argument output
.
This function is based on a convolution (convolve
) between the
input wave and a pulse echo filter.
Jerome Sueur [email protected]
Stoddard, P. K. (1998). Application of filters in bioacoustics. In: Hopp, S. L., Owren, M. J. and Evans, C. S. (Eds), Animal acoustic communication. Springer, Berlin, Heidelberg,pp. 105-127.
# generation of the input wave a <- synth(f=11025,d=1,cf=2000,shape="tria",am=c(50,10),fm=c(1000,10,1000,0,0)) # generation of three echoes # with respectively a relative amplitude of 0.8, 0.4, and 0.2 # and with a delay of 1s, 2s, and 3s from the beginning of the input wave aecho <- echo(a,f=11025,amp=c(0.8,0.4,0.2),delay=c(1,2,3)) # another echo with time delays overlapping with the input wave aecho <- echo(a,f=11025,amp=c(0.4,0.2,0.4),delay=c(0.6,0.8,1.5))
# generation of the input wave a <- synth(f=11025,d=1,cf=2000,shape="tria",am=c(50,10),fm=c(1000,10,1000,0,0)) # generation of three echoes # with respectively a relative amplitude of 0.8, 0.4, and 0.2 # and with a delay of 1s, 2s, and 3s from the beginning of the input wave aecho <- echo(a,f=11025,amp=c(0.8,0.4,0.2),delay=c(1,2,3)) # another echo with time delays overlapping with the input wave aecho <- echo(a,f=11025,amp=c(0.4,0.2,0.4),delay=c(0.6,0.8,1.5))
This function returns the absolute or Hilbert amplitude envelope of a time wave.
env(wave, f, channel = 1, envt = "hil", msmooth = NULL, ksmooth = NULL, ssmooth = NULL, asmooth = NULL, fftw = FALSE, norm = FALSE, plot = TRUE, k = 1, j = 1, ...)
env(wave, f, channel = 1, envt = "hil", msmooth = NULL, ksmooth = NULL, ssmooth = NULL, asmooth = NULL, fftw = FALSE, norm = FALSE, plot = TRUE, k = 1, j = 1, ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
envt |
the type of envelope to be returned: either "abs" for absolute amplitude envelope or "hil" for Hilbert amplitude envelope. See Details section. |
msmooth |
a vector of length 2 to smooth the amplitude envelope with a mean sliding window. The first component is the window length (in number of points). The second component is the overlap between successive windows (in %). See examples. |
ksmooth |
kernel smooth via |
ssmooth |
length of the sliding window used for a sum smooth. |
asmooth |
length of the sliding window used for an autocorrelation smooth. |
fftw |
if |
norm |
a logical, if |
plot |
logical, if |
k |
number of horizontal sections when |
j |
number of vertical sections when |
... |
other |
When envt
is set as "abs", the amplitude envelope returned
is the absolute value of wave
.
When envt
is set as "hil", the amplitude envelope returned is the modulus
(Mod
) of the analytical signal of wave
obtained through the Hilbert transform (hilbert
).
Data are returned as one-column matrix when plot
is FALSE
.
Be aware that smoothing with either msmooth
or ksmooth
changes the original number of points describing wave
.
Jerome Sueur. Implementation of 'fftw' argument by Jean Marchal and Francois Fabianek. Implementation of 'asmooth' by Thibaut Marin-Cudraz.
data(tico) # Hilbert amplitude envelope env(tico) # absolute amplitude envelope env(tico, envt="abs") # smoothing with a 10 points and 50% overlaping mean sliding window env(tico, msmooth=c(10,50)) # smoothing kernel env(tico, ksmooth=kernel("daniell",10)) # sum smooth env(tico, ssmooth=50) # autocorrelation smooth env(tico, asmooth=50) # overplot of oscillographic and envelope representations oscillo(tico) par(new=TRUE) env(tico, colwave=2)
data(tico) # Hilbert amplitude envelope env(tico) # absolute amplitude envelope env(tico, envt="abs") # smoothing with a 10 points and 50% overlaping mean sliding window env(tico, msmooth=c(10,50)) # smoothing kernel env(tico, ksmooth=kernel("daniell",10)) # sum smooth env(tico, ssmooth=50) # autocorrelation smooth env(tico, asmooth=50) # overplot of oscillographic and envelope representations oscillo(tico) par(new=TRUE) env(tico, colwave=2)
Export sound data as a text file that can be read by a sound player like 'Goldwave'
export(wave, f = NULL, channel = 1, filename = NULL, header=TRUE, ...)
export(wave, f = NULL, channel = 1, filename = NULL, header=TRUE, ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
filename |
name of the new file. (by default the name of |
header |
either a logical or a character vector,
if |
... |
other |
Creates a new text file with a header describing the main features of the sound (wave). For instance, for a 2 s sound with a sampling frequency of 8000 Hz, the header will be: [ASCII 8000Hz, Channels: 1, Samples: 160000, Flags: 0]. This type of file can be read by sound players like Goldwave (http://www.goldwave.com/).
Jerome Sueur [email protected]
a<-synth(f=8000,d=2,cf=2000,plot=FALSE) export(a,f=8000) unlink("a.txt")
a<-synth(f=8000,d=2,cf=2000,plot=FALSE) export(a,f=8000) unlink("a.txt")
This function applies a “fade in” and/or a “fade out” to a time wave following a linear, exponential or cosinus-like shape.
fadew(wave, f, channel = 1, din = 0, dout = 0, shape = "linear", plot = FALSE, listen = FALSE, output = "matrix", ...)
fadew(wave, f, channel = 1, din = 0, dout = 0, shape = "linear", plot = FALSE, listen = FALSE, output = "matrix", ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
din |
fade in duration. |
dout |
fade out duration. |
shape |
fade shape, |
plot |
logical, if |
listen |
if |
output |
character string, the class of the object to return, either
|
... |
other |
If plot
is FALSE
, a new wave is returned. The class
of the returned object is set with the argument output
.
Jerome Sueur [email protected]
oscillo
, addsilw
, cutw
,
deletew
,mutew
, pastew
, revw
,
zapsilw
a<-noisew(d=5,f=4000) op<-par(mfrow=c(3,1)) fadew(a,f=4000,din=1,dout=2,plot=TRUE,title="Linear",cexlab=0.8) fadew(a,f=4000,din=1,dout=2,shape="exp",plot=TRUE,title="Exponential shape", colwave="blue",coltitle="blue",cexlab=0.8) fadew(a,f=4000,din=1,dout=2,shape="cos",plot=TRUE,title="Cosinus-like shape", colwave="red",coltitle="red",cexlab=0.8) par(op)
a<-noisew(d=5,f=4000) op<-par(mfrow=c(3,1)) fadew(a,f=4000,din=1,dout=2,plot=TRUE,title="Linear",cexlab=0.8) fadew(a,f=4000,din=1,dout=2,shape="exp",plot=TRUE,title="Exponential shape", colwave="blue",coltitle="blue",cexlab=0.8) fadew(a,f=4000,din=1,dout=2,shape="cos",plot=TRUE,title="Cosinus-like shape", colwave="red",coltitle="red",cexlab=0.8) par(op)
This graphical function returns a frequency spectrum as a bar plot.
fbands(spec, f = NULL, bands = 10, width = FALSE, mel = FALSE, plot = TRUE, xlab = NULL, ylab = "Relative amplitude", ...)
fbands(spec, f = NULL, bands = 10, width = FALSE, mel = FALSE, plot = TRUE, xlab = NULL, ylab = "Relative amplitude", ...)
spec |
a data set resulting of a spectral analysis obtained
with |
f |
sampling frequency of |
bands |
a numeric vector. If vector of length 1, then sets the number of bands dividing in equal parts the spectrum. If of length > 1, then takes the values as kHz limits of the bands dividing the spectrum. These bands can be of different size. See details and examples. |
width |
logical, if |
mel |
a logical, if |
plot |
logical, if |
xlab |
label of the x-axis. |
ylab |
label of the y-axis. |
... |
other |
The function proceeds as follows
divides the spectrum in bands. The limits of the bands are set
with the argument bands
. There are two options:
you set a number of bands with equal size by giving a single
value to bands
. For instance, setting bands
to a value
of 10 will slice the spectrum in 10 equal parts and return 10 local
peaks.
you set the limits of the bands. This is achieve by giving a
numeric vector to bands
. The limits can follow a regular or
irregular series. For instance attributing the vector c(0,2,4,8) will
generate the following bands [0,2[, [2,4[, [4,8] kHz. Be aware that
the last value should not exceed half the sampling frequency used to
obtain the spectrum spec
.
uses the function barplot
.
A two-column matrix, the first column corresponding to the frequency values (x-axis, mean of the bars limits) and the second column corresponding to height values (y-axis) of the bars.
The value below bars is the mean between the corresponding frequency limits.
Jerome Sueur, improved by Laurent Lellouch
data(sheep) spec <- meanspec(sheep, f=8000, plot=FALSE) # default plot fbands(spec) # setting a specific number of bands fbands(spec, bands=6) #setting specific regular bands limits fbands(spec, bands=seq(0,4,by=0.25)) # some plot tuning op <- par(las=1) fbands(spec, bands=seq(0,4,by=0.1), horiz=TRUE, col=heat.colors(41), xlab="", ylab="", cex.axis=0.75, cex.names = 0.75, axes=FALSE) par(op) # showing or not the width of the bands oct <- octaves(440,3)/1000 op <- par(mfrow=c(2,1)) fbands(spec, bands=oct, col="blue") fbands(spec, bands=oct, width = TRUE, col="red") par(op) # kind of horizontal zoom op <- par(mfrow=c(2,1)) fbands(spec, bands=seq(0,4,by=0.2), col=c(rep(1,10), rep("orange",5),rep(1,5)), main="all frequency range") fbands(spec, bands=seq(2,3,by=0.2), col="orange", main="a subset or zoom in") par(op) # kind of dynamic frequency bands specs <- dynspec(sheep, f=8000, plot= FALSE)$amp out <- apply(specs, f=8000, MARGIN=2, FUN = fbands, bands = seq(0,4,by=0.2), col = 1, ylim=c(0,max(specs))) # mel scale require(tuneR) mel <- melfcc(sheep, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) melspec.mean <- apply(mel$aspectrum, MARGIN=2, FUN=mean) melspec.mean <- melspec.mean/max(melspec.mean) # [0,1] scaling fbands(melspec.mean, f=8000, bands=8)
data(sheep) spec <- meanspec(sheep, f=8000, plot=FALSE) # default plot fbands(spec) # setting a specific number of bands fbands(spec, bands=6) #setting specific regular bands limits fbands(spec, bands=seq(0,4,by=0.25)) # some plot tuning op <- par(las=1) fbands(spec, bands=seq(0,4,by=0.1), horiz=TRUE, col=heat.colors(41), xlab="", ylab="", cex.axis=0.75, cex.names = 0.75, axes=FALSE) par(op) # showing or not the width of the bands oct <- octaves(440,3)/1000 op <- par(mfrow=c(2,1)) fbands(spec, bands=oct, col="blue") fbands(spec, bands=oct, width = TRUE, col="red") par(op) # kind of horizontal zoom op <- par(mfrow=c(2,1)) fbands(spec, bands=seq(0,4,by=0.2), col=c(rep(1,10), rep("orange",5),rep(1,5)), main="all frequency range") fbands(spec, bands=seq(2,3,by=0.2), col="orange", main="a subset or zoom in") par(op) # kind of dynamic frequency bands specs <- dynspec(sheep, f=8000, plot= FALSE)$amp out <- apply(specs, f=8000, MARGIN=2, FUN = fbands, bands = seq(0,4,by=0.2), col = 1, ylim=c(0,max(specs))) # mel scale require(tuneR) mel <- melfcc(sheep, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) melspec.mean <- apply(mel$aspectrum, MARGIN=2, FUN=mean) melspec.mean <- melspec.mean/max(melspec.mean) # [0,1] scaling fbands(melspec.mean, f=8000, bands=8)
This function computes the altered frequency of a moving source due to the Doppler effect.
fdoppler(f, c = 340, vs, vo = 0, movs = "toward", movo = "toward")
fdoppler(f, c = 340, vs, vo = 0, movs = "toward", movo = "toward")
f |
original frequency produced by the source (in Hz or kHz) |
c |
speed of sound in meters/second. |
vs |
speed of the source in meters/second. |
vo |
speed of the observer in meters/second. The observer is static by default
i.e. |
movs |
movement direction of the source in relation with observer position,
either |
movo |
movement direction of the observer in relation with the source position,
either |
The altered frequency f' is computed according to:
with f = original frequency produced by the source (in Hz or kHz),
vs = speed of the source,
vo = speed of the observer.
The altered frequency is returned in a vector.
You can use wasp
to have exact values of c
.
See examples.
Jerome Sueur [email protected]
# a 400 Hz source moving toward or away from the observer at 85 m/s fdoppler(f=400,vs=85) # [1] 533.3333 fdoppler(f=400,vs=85,movs="away") # [1] 320 # use wasp() if you wish to have exact sound speed at a specific temperature fdoppler(f=wasp(f=400,t=25)$c, vs=85) # [1] 461.8667 # Doppler effect at different source speeds f<-seq(1,10,by=1); lf<-length(f) v<-seq(10,300,by=20); lv<-length(v) res<-matrix(numeric(lf*lv),ncol=lv) for(i in 1:lv) res[,i]<-fdoppler(f=f,vs=v[i]) op<-par(bg="lightgrey") matplot(x=f,y=res,type="l",lty=1,las=1,col= spectro.colors(lv), xlab="Source frequency (kHz)", ylab="Altered frequency (kHz)") legend("topleft",legend=paste(as.character(v),"m/s"), lty=1,col= spectro.colors(lv)) title(main="Doppler effect at different source speeds") par(op)
# a 400 Hz source moving toward or away from the observer at 85 m/s fdoppler(f=400,vs=85) # [1] 533.3333 fdoppler(f=400,vs=85,movs="away") # [1] 320 # use wasp() if you wish to have exact sound speed at a specific temperature fdoppler(f=wasp(f=400,t=25)$c, vs=85) # [1] 461.8667 # Doppler effect at different source speeds f<-seq(1,10,by=1); lf<-length(f) v<-seq(10,300,by=20); lv<-length(v) res<-matrix(numeric(lf*lv),ncol=lv) for(i in 1:lv) res[,i]<-fdoppler(f=f,vs=v[i]) op<-par(bg="lightgrey") matplot(x=f,y=res,type="l",lty=1,las=1,col= spectro.colors(lv), xlab="Source frequency (kHz)", ylab="Altered frequency (kHz)") legend("topleft",legend=paste(as.character(v),"m/s"), lty=1,col= spectro.colors(lv)) title(main="Doppler effect at different source speeds") par(op)
This function filters out a selected frequency section of a time wave (low-pass, high-pass, low-stop, high-stop, bandpass or bandstop frequency filter).
ffilter(wave, f, channel = 1, from = NULL, to = NULL, bandpass = TRUE, custom = NULL, wl = 1024, ovlp = 75, wn = "hanning", fftw = FALSE, rescale=FALSE, listen=FALSE, output="matrix")
ffilter(wave, f, channel = 1, from = NULL, to = NULL, bandpass = TRUE, custom = NULL, wl = 1024, ovlp = 75, wn = "hanning", fftw = FALSE, rescale=FALSE, listen=FALSE, output="matrix")
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
from |
start frequency (in Hz) where to apply the filter. |
to |
end frequency (in Hz) where to apply the filter. |
bandpass |
if |
custom |
a vector describing the frequency response of a custom filter.
This can be manually generated or obtained with |
wl |
window length for the analysis (even number of points). |
ovlp |
overlap between successive FFT windows (in %). |
wn |
window name, see |
fftw |
if |
rescale |
a logical, if |
listen |
a logical, if |
output |
character string, the class of the object to return, either
|
A short-term Fourier transform is first applied to the signal
(see spectro
), then the frequency filter is applied and the new
signal is eventually generated using the reverse of the Fourier Transform
(istft
).
There is therefore neither temporal modifications nor
amplitude modifications.
If plot
is FALSE
, a new wave is returned. The class
of the returned object is set with the argument output
.
Jerome Sueur
afilter
,lfs
,fir
,
preemphasis
, combfilter
, bwfilter
a<-noisew(f=8000,d=1) # low-pass b<-ffilter(a,f=8000,to=1500) spectro(b,f=8000,wl=512) # high-pass c<-ffilter(a,f=8000,from=2500) spectro(c,f=8000,wl=512) # band-pass d<-ffilter(a,f=8000,from=1000,to=2000) spectro(d,f=8000,wl=512) # band-stop e<-ffilter(a,f=8000,from=1500,to=2500,bandpass=FALSE) spectro(e,f=8000,wl=512) # custom myfilter1<-rep(c(rep(0,64),rep(1,64)),4) g<-ffilter(a,f=8000,custom=myfilter1) spectro(g,f=8000)
a<-noisew(f=8000,d=1) # low-pass b<-ffilter(a,f=8000,to=1500) spectro(b,f=8000,wl=512) # high-pass c<-ffilter(a,f=8000,from=2500) spectro(c,f=8000,wl=512) # band-pass d<-ffilter(a,f=8000,from=1000,to=2000) spectro(d,f=8000,wl=512) # band-stop e<-ffilter(a,f=8000,from=1500,to=2500,bandpass=FALSE) spectro(e,f=8000,wl=512) # custom myfilter1<-rep(c(rep(0,64),rep(1,64)),4) g<-ffilter(a,f=8000,custom=myfilter1) spectro(g,f=8000)
This function helps in knowing whether you are working in the near or far field.
field(f, d)
field(f, d)
f |
frequency (Hz) |
d |
distance from the sound source (m) |
Areas very close to the sound source are in the near-field where the contribution
of particle velocity to sound energy is greater thant that of sound pressure and where
these components are not in phase. Sound propagation properties are also different
near or far from the source. It is therefore important to know where the microphone
was from the source.
To know this, the product k*d is computed according to:
with d = distance from the source (m), f = frequency (Hz)
and c = sound celerity (m/s).
If k*d is greatly inferior 1 then the microphone is in the near field.
The decision help returned by the function follows the rule:
far field:
between near and far field limits:
near field:
.
A list of two values is returned:
kd |
the numeric value k*d used to take a decision |
d |
a character string giving the help decision. |
This function works for air-borne sound only.
Jerome Sueur [email protected]
# 1 kHz near field at 1 cm from the source field(f=1000,d=0.01) # playing with distance from source and sound frequency op<-par(bg="lightgrey") D<-seq(0.01,0.5,by=0.01); nD<-length(D) F<-seq(100,1000,by=25); nF<-length(F) a<-matrix(numeric(nD*nF),nrow=nD) for(i in 1:nF) a[,i]<-field(f=F[i],d=D)$kd matplot(x=D,y=a,type="l",lty=1,col= spectro.colors(nF), xlab="Distance from the source (m)", ylab="k*d") title("Variation of the product k*d with distance and frequency") text(x=c(0.4,0.15),y=c(0.02,1), c("Near Field","Far Field"),font=2) legend(x=0.05,y=1.4,c("100 Hz","1000 Hz"),lty=1, col=c(spectro.colors(nF)[1],spectro.colors(nF)[nF]),bg="grey") abline(h=0.1) par(op)
# 1 kHz near field at 1 cm from the source field(f=1000,d=0.01) # playing with distance from source and sound frequency op<-par(bg="lightgrey") D<-seq(0.01,0.5,by=0.01); nD<-length(D) F<-seq(100,1000,by=25); nF<-length(F) a<-matrix(numeric(nD*nF),nrow=nD) for(i in 1:nF) a[,i]<-field(f=F[i],d=D)$kd matplot(x=D,y=a,type="l",lty=1,col= spectro.colors(nF), xlab="Distance from the source (m)", ylab="k*d") title("Variation of the product k*d with distance and frequency") text(x=c(0.4,0.15),y=c(0.02,1), c("Near Field","Far Field"),font=2) legend(x=0.05,y=1.4,c("100 Hz","1000 Hz"),lty=1, col=c(spectro.colors(nF)[1],spectro.colors(nF)[nF]),bg="grey") abline(h=0.1) par(op)
This function is a FIR filter that filters out a selected frequency section of a time wave (low-pass, high-pass, low-stop, high-stop, bandpass or bandstop frequency filter).
fir(wave, f, channel = 1, from = NULL, to = NULL, bandpass = TRUE, custom = NULL, wl = 512, wn = "hanning", rescale=FALSE, listen = FALSE, output = "matrix")
fir(wave, f, channel = 1, from = NULL, to = NULL, bandpass = TRUE, custom = NULL, wl = 512, wn = "hanning", rescale=FALSE, listen = FALSE, output = "matrix")
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
from |
start frequency (in Hz) where to apply the filter. |
to |
end frequency (in Hz) where to apply the filter. |
bandpass |
if |
custom |
a vector describing the frequency response of a custom filter.
This can be manually generated or obtained with |
wl |
window length of the impulse filter (even number of points). |
wn |
window name, see |
rescale |
a logical, if |
listen |
a logical, if |
output |
character string, the class of the object to return, either
|
This function is based on the reverse of the Fourier Transform
(fft
) and on a convolution (convolve
) between the
wave to be filtered and the impulse filter.
A new wave is returned. The class
of the returned object is set with the argument output
.
Jerome Sueur
Stoddard, P. K. (1998). Application of filters in bioacoustics. In: Hopp, S. L., Owren, M. J. and Evans, C. S. (Eds), Animal acoustic communication. Springer, Berlin, Heidelberg,pp. 105-127.
ffilter
, bwfilter
, preemphasis
, lfs
, afilter
a<-noisew(f=8000,d=1) # low-pass b<-fir(a,f=8000,to=1500) spectro(b,f=8000) # high-pass c<-fir(a,f=8000,from=2500) spectro(c,f=8000) # band-pass d<-fir(a,f=8000,from=1000,to=2000) spectro(d,f=8000) # band-stop e<-fir(a,f=8000,from=1500,to=2500,bandpass=FALSE) spectro(e,f=8000) # custom filter manually generated myfilter1<-rep(c(rep(0,32),rep(1,32)),4) g<-fir(a,f=8000,custom=myfilter1) spectro(g,f=8000) # custom filter generated using spec() data(tico) myfilter2<-spec(tico,f=22050,at=0.7,wl=512,plot=FALSE) b<-noisew(d=1,f=22050) h<-fir(b,f=22050,custom=myfilter2) spectro(h,f=22050)
a<-noisew(f=8000,d=1) # low-pass b<-fir(a,f=8000,to=1500) spectro(b,f=8000) # high-pass c<-fir(a,f=8000,from=2500) spectro(c,f=8000) # band-pass d<-fir(a,f=8000,from=1000,to=2000) spectro(d,f=8000) # band-stop e<-fir(a,f=8000,from=1500,to=2500,bandpass=FALSE) spectro(e,f=8000) # custom filter manually generated myfilter1<-rep(c(rep(0,32),rep(1,32)),4) g<-fir(a,f=8000,custom=myfilter1) spectro(g,f=8000) # custom filter generated using spec() data(tico) myfilter2<-spec(tico,f=22050,at=0.7,wl=512,plot=FALSE) b<-noisew(d=1,f=22050) h<-fir(b,f=22050,custom=myfilter2) spectro(h,f=22050)
This function computes the Fourier analysis of the instantaneous frequency of a time wave. This allows to detect periodicity in frequency modulation.
fma(wave, f, channel = 1, threshold = NULL, plot = TRUE, ...)
fma(wave, f, channel = 1, threshold = NULL, plot = TRUE, ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
threshold |
amplitude threshold for signal detection (in % ). |
plot |
logical, if |
... |
other |
This function is based on ifreq
and spec
.
The instantaneous frequency of wave
is first computed and the spectrum of this
frequency modulation is then processed. All env
and spec
arguments can be
set up.
If plot
is FALSE
, fma
returns a numeric vector
corresponding to the computed spectrum.
If peaks
is not NULL
, fma
returns a list with
two elements:
spec |
the spectrum computed |
peaks |
the peaks values (in kHz). |
Jerome Sueur [email protected]
# a sound with a 1 kHz sinusoid FM a<-synth(d=1, f=8000, cf=1500, fm=c(1000,1000,0,0,0), output="Wave") fma(a)
# a sound with a 1 kHz sinusoid FM a<-synth(d=1, f=8000, cf=1500, fm=c(1000,1000,0,0,0), output="Wave") fma(a)
This function searches for peaks of a frequency spectrum.
fpeaks(spec, f = NULL, nmax = NULL, amp = NULL, freq = NULL, threshold = NULL, mel =FALSE, plot = TRUE, title = TRUE, xlab = NULL, ylab = "Amplitude", labels = TRUE, digits = 2, legend = TRUE, collab = "red", ...)
fpeaks(spec, f = NULL, nmax = NULL, amp = NULL, freq = NULL, threshold = NULL, mel =FALSE, plot = TRUE, title = TRUE, xlab = NULL, ylab = "Amplitude", labels = TRUE, digits = 2, legend = TRUE, collab = "red", ...)
spec |
a data set resulting of a spectral analysis obtained
with |
f |
sampling frequency of |
nmax |
maximal number of peaks detected. Overrides |
amp |
amplitude slope parameter, a numeric vector of length 2. Refers to the amplitude slopes of the peak. The first value is the left slope and the second value is the right slope. Only peaks with higher slopes than threshold values will be kept. See details. |
freq |
frequency threshold parameter (in Hz). If the frequency difference of two successive peaks is less than this threshold, then the peak of highest amplitude will be kept only. See details. |
threshold |
amplitude threshold parameter. Only peaks above this threshold will be considered. See details. |
mel |
a logical, if |
plot |
logical, if |
title |
logical, if |
xlab |
label of the x-axis. |
ylab |
label of the y-axis. |
labels |
logical, if |
digits |
if |
legend |
logical, if |
collab |
labels color. |
... |
other |
Here are some details regarding the different selection
parameters:
nmax
: this parameter is to be used if you wish to get a
specific number of peaks. The peaks selected are those with the
highest slopes. It then does not work in conjunction with the other parameters.
freq
: this parameter allows to remove from the selection
successive peaks with a small frequency difference. Imagine you have two
successive peaks at 1200 Hz and 1210 Hz and at 0.5
and 0.25 in amplitude. If you set freq
to 50 Hz, then only the first
peak will be kept.
amp
: this parameter allows to remove from the selection
peaks with low slopes. You can make the selection on both slopes or on
a single one. Imagine you have an asymetric peak with a 0.01 left slope and a
0.02 right slope. The peak will be discarded for the following
settings: both values higher than 0.02 (e.g. amp =
c(0.03,0.04)
), the first value higher than 0.01 (e.g. amp =
c(0.02,0.001)
), the second value higher than 0.02 (e.g. amp =
c(0.001,0.03)
). If you do not want apply the selection
on one of the slope use 0. For instance, a selection on the left slope
only will be achieved with: amp = c(0.02,0)
.
threshold
: this parameter can be used to do a rough
selection on the spectrum. Peaks with an amplitude value (not a slope)
lower than this threshold will be automatically discarded. This can be
useful when you want to remove peaks of a low-amplitude background noise.
A two-column matrix, the first column corresponding to the frequency values (x-axis) and the second column corresponding to the amplitude values (y-axis) of the peaks.
You can also use fpeaks
with other kind of spectrum, for
instance a cepstral spectrum. See examples.
Jerome Sueur and Amandine Gasc
data(tico) spec <- meanspec(tico, f=22050, plot=FALSE) specdB <- meanspec(tico, f=22050, dB="max0", plot=FALSE) # all peaks fpeaks(spec) # 10 highest peaks fpeaks(spec, nmax=10) # highest peak (ie dominant frequency) fpeaks(spec, nmax=1) # peaks that are separated by more than 500 Hz fpeaks(spec, freq=500) # peaks with a left slope higher than 0.1 fpeaks(spec, amp=c(0.1,0)) # peaks with a right slope higher than 0.1 fpeaks(spec, amp=c(0,0.1)) # peaks with left and right slopes higher than 0.1 fpeaks(spec, amp=c(0.1,0.1)) # peaks above a 0.5 threshold fpeaks(spec, threshold=0.5) # peaks of a dB spectrum with peaks showing slopes higher than 3 dB fpeaks(specdB, amp=c(3,3)) # comparing different parameter settings meanspec(tico, f=22050) col <- c("#ff000090","#0000ff75","#00ff00") cex <- c(2,1.25,1.5) pch <- c(19,17,4) title(main="Peak detection \n (spectrum with values between 0 and 1)") res1 <- fpeaks(spec, plot = FALSE) res2 <- fpeaks(spec, amp=c(0.02,0.02), plot =FALSE) res3 <- fpeaks(spec, amp=c(0.02,0.02), freq=200, plot = FALSE) points(res1, pch=pch[1], col=col[1], cex=cex[1]) points(res2, pch=pch[2], col=col[2], cex=cex[2]) points(res3, pch=pch[3], col=col[3], cex=cex[3]) legend("topright", legend=c("all peaks","amp", "amp & freq"), pch=pch, pt.cex=cex, col=col, bty="n") # example with a cepstral spectrum data(sheep) res <- ceps(sheep,f=8000,at=0.4,wl=1024,plot=FALSE) fpeaks(res, nmax=4, xlab="Quefrency (s)") # melscale require(tuneR) mel <- melfcc(sheep, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) melspec.mean <- apply(mel$aspectrum, MARGIN=2, FUN=mean) melspec.mean <- melspec.mean/max(melspec.mean) # [0,1] scaling fpeaks(melspec.mean, nmax=4, f=8000, mel=TRUE) fpeaks(melspec.mean, freq=4, f=8000, mel=TRUE) # freq in Hz! fpeaks(melspec.mean, threshold=0.3, f=8000, mel=TRUE) fpeaks(melspec.mean, amp=c(0.1,0.1), f=8000, mel=TRUE)
data(tico) spec <- meanspec(tico, f=22050, plot=FALSE) specdB <- meanspec(tico, f=22050, dB="max0", plot=FALSE) # all peaks fpeaks(spec) # 10 highest peaks fpeaks(spec, nmax=10) # highest peak (ie dominant frequency) fpeaks(spec, nmax=1) # peaks that are separated by more than 500 Hz fpeaks(spec, freq=500) # peaks with a left slope higher than 0.1 fpeaks(spec, amp=c(0.1,0)) # peaks with a right slope higher than 0.1 fpeaks(spec, amp=c(0,0.1)) # peaks with left and right slopes higher than 0.1 fpeaks(spec, amp=c(0.1,0.1)) # peaks above a 0.5 threshold fpeaks(spec, threshold=0.5) # peaks of a dB spectrum with peaks showing slopes higher than 3 dB fpeaks(specdB, amp=c(3,3)) # comparing different parameter settings meanspec(tico, f=22050) col <- c("#ff000090","#0000ff75","#00ff00") cex <- c(2,1.25,1.5) pch <- c(19,17,4) title(main="Peak detection \n (spectrum with values between 0 and 1)") res1 <- fpeaks(spec, plot = FALSE) res2 <- fpeaks(spec, amp=c(0.02,0.02), plot =FALSE) res3 <- fpeaks(spec, amp=c(0.02,0.02), freq=200, plot = FALSE) points(res1, pch=pch[1], col=col[1], cex=cex[1]) points(res2, pch=pch[2], col=col[2], cex=cex[2]) points(res3, pch=pch[3], col=col[3], cex=cex[3]) legend("topright", legend=c("all peaks","amp", "amp & freq"), pch=pch, pt.cex=cex, col=col, bty="n") # example with a cepstral spectrum data(sheep) res <- ceps(sheep,f=8000,at=0.4,wl=1024,plot=FALSE) fpeaks(res, nmax=4, xlab="Quefrency (s)") # melscale require(tuneR) mel <- melfcc(sheep, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) melspec.mean <- apply(mel$aspectrum, MARGIN=2, FUN=mean) melspec.mean <- melspec.mean/max(melspec.mean) # [0,1] scaling fpeaks(melspec.mean, nmax=4, f=8000, mel=TRUE) fpeaks(melspec.mean, freq=4, f=8000, mel=TRUE) # freq in Hz! fpeaks(melspec.mean, threshold=0.3, f=8000, mel=TRUE) fpeaks(melspec.mean, amp=c(0.1,0.1), f=8000, mel=TRUE)
Generates different Fourier Transform windows.
ftwindow(wl, wn = "hamming", correction = c("none", "amplitude", "energy"))
ftwindow(wl, wn = "hamming", correction = c("none", "amplitude", "energy"))
wl |
window length |
wn |
window name: |
correction |
a character vector of length 1 to apply an amplitude ("amplitude") or an energy ("energy") correction to the FT window. By default no correction is applied ("none"). |
A vector of length wl
.
Try the example to see windows shape.
Jerome Sueur [email protected]
Harris, F.J., 1978. On the use of windows for harmonic analysis with the discrete Fourier Transform. Proceedings of the IEEE, 66(1): 51-83.
covspectro
, dfreq
, meanspec
,
spec
, spectro
, spectro3D
a<-ftwindow(512) b<-ftwindow(512,wn="bartlett") c<-ftwindow(512,wn="blackman") d<-ftwindow(512,wn="flattop") e<-ftwindow(512,wn="hanning") f<-ftwindow(512,wn="rectangle") all<-cbind(a,b,c,d,e,f) matplot(all,type="l",col=1:6,lty=1:6) legend(legend=c("hamming","bartlett","blackman","flattop","hanning","rectangle"), x=380,y=0.95,col=1:6,lty=1:6,cex=0.75)
a<-ftwindow(512) b<-ftwindow(512,wn="bartlett") c<-ftwindow(512,wn="blackman") d<-ftwindow(512,wn="flattop") e<-ftwindow(512,wn="hanning") f<-ftwindow(512,wn="rectangle") all<-cbind(a,b,c,d,e,f) matplot(all,type="l",col=1:6,lty=1:6) legend(legend=c("hamming","bartlett","blackman","flattop","hanning","rectangle"), x=380,y=0.95,col=1:6,lty=1:6,cex=0.75)
This function estimates the fundamental frequency through a short-term cepstral transform.
fund(wave, f, channel = 1, wl = 512, ovlp = 0, fmax = f/2, threshold = NULL, at = NULL, from = NULL, to = NULL, plot = TRUE, xlab = "Time (s)", ylab = "Frequency (kHz)", ylim = c(0, f/2000), pb = FALSE, ...)
fund(wave, f, channel = 1, wl = 512, ovlp = 0, fmax = f/2, threshold = NULL, at = NULL, from = NULL, to = NULL, plot = TRUE, xlab = "Time (s)", ylab = "Frequency (kHz)", ylim = c(0, f/2000), pb = FALSE, ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
wl |
if |
ovlp |
overlap between two successive windows (in %). |
fmax |
the maximum frequency to detect (in Hz). |
threshold |
amplitude threshold for signal detection (in %). |
at |
position where the estimate the fundamental frequency (in s) |
.
from |
start position where to compute the fundamental frequency (in s). |
to |
end position to compute the fundamental frequency (in s). |
plot |
logical, if |
xlab |
title of the time axis (s). |
ylab |
title of the frequency axis (Hz). |
ylim |
the range of frequency values. |
pb |
if |
... |
other |
When plot
is FALSE
, fund
returns a two-column matrix, the first column corresponding to time in seconds (x-axis) and the second column corresponding to
to fundamental frequency in kHz (y-axis).
NA corresponds to pause sections in wave
(see
threshold
).
No plot is produced when using at
.
This function is based on ceps
.
Jerome Sueur [email protected].
Oppenheim, A.V. and Schafer, R.W. 2004. From frequency to quefrency: a history of the cepstrum. Signal Processing Magazine IEEE, 21: 95-106.
data(sheep) # estimate the fundamental frequency at a single position fund(sheep, f=8000, fmax=300, at=1, plot=FALSE) # track the fundamental frequency along time fund(sheep,f=8000,fmax=300,type="l") # with 50% overlap between successive sliding windows, time zoom and # amplitude filter (threshold) fund(sheep,f=8000,fmax=300,type="b",ovlp=50,threshold=5,ylim=c(0,1),cex=0.5) # overlaid on a spectrogram spectro(sheep,f=8000,ovlp=75,zp=16,scale=FALSE,palette=reverse.gray.colors.2) par(new=TRUE) fund(sheep,f=8000,fmax=300,type="p",pch=24,ann=FALSE, xaxs="i",yaxs="i",col="black",bg="red",threshold=6)
data(sheep) # estimate the fundamental frequency at a single position fund(sheep, f=8000, fmax=300, at=1, plot=FALSE) # track the fundamental frequency along time fund(sheep,f=8000,fmax=300,type="l") # with 50% overlap between successive sliding windows, time zoom and # amplitude filter (threshold) fund(sheep,f=8000,fmax=300,type="b",ovlp=50,threshold=5,ylim=c(0,1),cex=0.5) # overlaid on a spectrogram spectro(sheep,f=8000,ovlp=75,zp=16,scale=FALSE,palette=reverse.gray.colors.2) par(new=TRUE) fund(sheep,f=8000,fmax=300,type="p",pch=24,ann=FALSE, xaxs="i",yaxs="i",col="black",bg="red",threshold=6)
Generate gammatone filter in the time domain (impulse response).
gammatone(f, d, cfreq, n = 4, a = 1, p = 0, output = "matrix")
gammatone(f, d, cfreq, n = 4, a = 1, p = 0, output = "matrix")
f |
sampling frequency (in Hz). |
d |
duration (in s). |
cfreq |
center frequency (in Hz). |
n |
filter order (no unit). |
a |
amplitude (linear scale, no unit). |
p |
initial phase (in radians). |
output |
character string, the class of the object to return, either
|
The gammatone function in the time domain (impulse response) is
obtained with:
with a the amplitude, t time, n the filter order, cf the center frequency, the initial phase.
The parameter is the equivalent rectangular
bandwidth (ERB) bandwidth which varies according to the center
frequency
following:
A wave is returned. The class of the returned object is set with the argument output
.
Use the FFT based function, as spec
or
meanspec
, to get the filter in the frequency domain. See examples.
Jerome Sueur
Holdsworth J, Nimmo-Smith I, Patterson R, Rice P (1988) Implementing a gammatone filter bank. Annex C of the SVOS Final Report: Part A: The Auditory Filterbank, 1, 1-5.
## gammatone filter in the time domain (impulse response) f <- 44100 d <- 0.05 res <- gammatone(f=f, d=d, cfreq=440, n=4) ## time display oscillo(res, f=f) ## frequency display spec(res, f=f) ## generate and plot a bank of 32 filters from 500 to 10000 Hz n <- 32 cfreq <- round(seq(500, 10000, length.out=n)) res <- matrix(NA, nrow=f*d/2, ncol=n) for(i in 1:n){ res[,i] <- spec(gammatone(f=f, d=d, cfreq=cfreq[i]), f=f, dB="max0", plot=FALSE)[,2] } x <- seq(0,f/2,length.out=nrow(res))/1000 plot(x=x, y=res[,1], xlim=c(0,14), ylim=c(-60,0), type="l", col=2, las=1, xlab="Frequency (kHz)", ylab="Relative amplitude (dB)") for(i in 2:n) lines(x, res[,i], col=2) ## use the frequency domain to filter a white noise input ## here around the center frequency 2000 Hz res <- gammatone(f=f, d=d, cfreq=2000, n=4) gspec <- spec(res, f=f, plot=FALSE)[,2] nw <- noisew(f=44100, d=1) nwfilt <- fir(nw, f=44100, wl=length(gspec)*2, custom=gspec) spectro(nwfilt, f=f)
## gammatone filter in the time domain (impulse response) f <- 44100 d <- 0.05 res <- gammatone(f=f, d=d, cfreq=440, n=4) ## time display oscillo(res, f=f) ## frequency display spec(res, f=f) ## generate and plot a bank of 32 filters from 500 to 10000 Hz n <- 32 cfreq <- round(seq(500, 10000, length.out=n)) res <- matrix(NA, nrow=f*d/2, ncol=n) for(i in 1:n){ res[,i] <- spec(gammatone(f=f, d=d, cfreq=cfreq[i]), f=f, dB="max0", plot=FALSE)[,2] } x <- seq(0,f/2,length.out=nrow(res))/1000 plot(x=x, y=res[,1], xlim=c(0,14), ylim=c(-60,0), type="l", col=2, las=1, xlab="Frequency (kHz)", ylab="Relative amplitude (dB)") for(i in 2:n) lines(x, res[,i], col=2) ## use the frequency domain to filter a white noise input ## here around the center frequency 2000 Hz res <- gammatone(f=f, d=d, cfreq=2000, n=4) gspec <- spec(res, f=f, plot=FALSE)[,2] nw <- noisew(f=44100, d=1) nwfilt <- fir(nw, f=44100, wl=length(gspec)*2, custom=gspec) spectro(nwfilt, f=f)
This function returns a ggplot object to draw a spectrogram
with the package ggplot2. This is an alternative to spectro
.
ggspectro(wave, f, tlab = "Time (s)", flab = "Frequency (kHz)", alab = "Amplitude\n(dB)\n", ...)
ggspectro(wave, f, tlab = "Time (s)", flab = "Frequency (kHz)", alab = "Amplitude\n(dB)\n", ...)
wave |
an R object. |
f |
sampling frequency of |
tlab |
label of the time axis. |
flab |
label of the frequency axis. |
alab |
label of the amplitude axis. |
... |
other non-graphical arguments to be passed to spectro
( |
This function return the fist layer (data and aesthetic
mapping) of a ggplot2 plot.
See the example section to understand how to build a spectrogram and consult ggplot2 help to get what you
exactly need.
There is no way to plot the oscillogram as spectro does.
A ggpot layer.
This function requires ggplot2 package.
Jerome Sueur
Wickham H (2009) – ggplot2: elegant graphics for data analysis. UseR! Springer.
## Not run: require(ggplot2) ## first layer v <- ggspectro(tico, ovlp=50) summary(v) ## using geom_tile ## v + geom_tile(aes(fill = amplitude)) + stat_contour() ## coordinates flip (interest?) v + geom_tile(aes(fill = amplitude)) + stat_contour() + coord_flip() ## using stat_contour ## # default (not nice at all) v + stat_contour(geom="polygon", aes(fill=..level..)) # set up to 30 color levels with the argument bins (vv <- v + stat_contour(geom="polygon", aes(fill=..level..), bins=30)) # change the limits of amplitude and NA values as transparent vv + scale_fill_continuous(name="Amplitude\n(dB)\n", limits=c(-30,0), na.value="transparent") # Black-and-white theme (vv + scale_fill_continuous(name="Amplitude\n(dB)\n", limits=c(-30,0), na.value="transparent", low="white", high="black") + theme_bw()) # Other colour scale (close to spectro() default output) v + stat_contour(geom="polygon", aes(fill=..level..), bins=30) + scale_fill_gradientn(name="Amplitude\n(dB)\n", limits=c(-30,0), na.value="transparent", colours = spectro.colors(30)) ## End(Not run)
## Not run: require(ggplot2) ## first layer v <- ggspectro(tico, ovlp=50) summary(v) ## using geom_tile ## v + geom_tile(aes(fill = amplitude)) + stat_contour() ## coordinates flip (interest?) v + geom_tile(aes(fill = amplitude)) + stat_contour() + coord_flip() ## using stat_contour ## # default (not nice at all) v + stat_contour(geom="polygon", aes(fill=..level..)) # set up to 30 color levels with the argument bins (vv <- v + stat_contour(geom="polygon", aes(fill=..level..), bins=30)) # change the limits of amplitude and NA values as transparent vv + scale_fill_continuous(name="Amplitude\n(dB)\n", limits=c(-30,0), na.value="transparent") # Black-and-white theme (vv + scale_fill_continuous(name="Amplitude\n(dB)\n", limits=c(-30,0), na.value="transparent", low="white", high="black") + theme_bw()) # Other colour scale (close to spectro() default output) v + stat_contour(geom="polygon", aes(fill=..level..), bins=30) + scale_fill_gradientn(name="Amplitude\n(dB)\n", limits=c(-30,0), na.value="transparent", colours = spectro.colors(30)) ## End(Not run)
This function estimates the total entropy of a time wave.
H(wave, f, channel = 1, wl = 512, envt="hil", msmooth = NULL, ksmooth = NULL)
H(wave, f, channel = 1, wl = 512, envt="hil", msmooth = NULL, ksmooth = NULL)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
wl |
window length for spectral entropy analysis
(even number of points). See |
envt |
the type of envelope to be used: either "abs" for absolute
amplitude envelope or "hil" for Hilbert amplitude envelope. See |
msmooth |
a vector of length 2 to smooth the amplitude envelope with a
mean sliding window. The first component is the window length
(in number of points). The second component is the overlap between
successive windows (in %). See |
ksmooth |
This function computes the product between the values obtained with
sh
and th
functions.
This then gives a global (time and frequency) estimation of signal entropy.
The frequency mean spectrum and the amplitude envelope needed for computing
respectively sh
and th
are automatically generated.
They can be controlled through wl
and smooth
arguments respectively.
See examples below and examples in sh
and th
for implications on the results.
A single value varying between 0 and 1 is returned. The value has no unit.
The entropy of a noisy signal will tend towards 1 whereas the entropy of a pure tone signal will tend towards 0.
Jerome Sueur [email protected]
Sueur, J., Pavoine, S., Hamerlynck, O. & Duvail, S. (2008) - Rapid acoustic survey for biodiversity appraisal. PLoS ONE, 3(12): e4065.
data(orni) H(orni,f=22050) # changing the spectral parameter (wl) H(orni,f=22050,wl=1024) # changing the temporal parameter (msmooth) H(orni,f=22050,msmooth=c(20,0))
data(orni) H(orni,f=22050) # changing the spectral parameter (wl) H(orni,f=22050,wl=1024) # changing the temporal parameter (msmooth) H(orni,f=22050,msmooth=c(20,0))
This function returns the analytic signal of a time wave through Hilbert transform.
hilbert(wave, f, channel = 1, fftw = FALSE)
hilbert(wave, f, channel = 1, fftw = FALSE)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
fftw |
if |
The analytic signal is useful to get the amplitude envelope
(see argument henv
of oscillo
and the instantaneous
phase or frequency (see ifreq
) of a time wave.
hilbert
returns the analytic signal as a complex matrix.
The imaginary part of this matrix is the Hilbert transform.
To get the Hilbert component only, use Im(Hilbert(wave))
.
Jonathan Lees [email protected]. Implementation of 'fftw' argument by Jean Marchal and Francois Fabianek.
Mbu Nyamsi, R. G., Aubin, T. & Bremond, J. C. 1994 On the extraction of some time dependent parameters of an acoustic signal by means of the analytic signal concept. Its application to animal sound study. Bioacoustics, 5: 187-203.
a<-synth(f=8000, d=1, cf=1000) aa<-hilbert(a, f=8000)
a<-synth(f=8000, d=1, cf=1000) aa<-hilbert(a, f=8000)
This function returns the instantaneous frequency (and/or phase) of a time wave through the computation of the analytic signal (Hilbert transform).
ifreq(wave, f, channel = 1, phase = FALSE, threshold = NULL, plot = TRUE, xlab = "Time (s)", ylab = NULL, ylim = NULL, type = "l", ...)
ifreq(wave, f, channel = 1, phase = FALSE, threshold = NULL, plot = TRUE, xlab = "Time (s)", ylab = NULL, ylim = NULL, type = "l", ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
phase |
if |
threshold |
amplitude threshold for signal detection (in % ). |
plot |
logical, if |
xlab |
title of the x axis. |
ylab |
title of the y axis. |
ylim |
the range of y values. |
type |
if |
... |
other |
The instantaneous phase is the argument of the
analytic signal obtained throught the Hilbert transform.
The instantaneous phase is then unwrapped and derived against time to
get the instantaneous frequency.
There may be some edge effects at both start and end of the time wave.
If plot
is FALSE
, ifreq
returns a list of two components:
f |
a two-column matrix, the first column corresponding to time in seconds (x-axis) and the second column corresponding to instantaneous frequency in kHz (y-axis). |
p |
a two-column matrix, the first column corresponding to time in seconds (x-axis) and the second column corresponding to wrapped instantaneous phase in radians (y-axis). |
This function is based on the analytic signal obtained with the
Hilbert transform (see hilbert
).
The function requires the package signal.
The matrix describing the instantaneous phase has one more row than the
one describing the instantaneous frequency.
Jerome Sueur [email protected]
Mbu Nyamsi, R. G., Aubin, T. & Bremond, J. C. 1994 On the extraction of some time dependent parameters of an acoustic signal by means of the analytic signal concept. Its application to animal sound study. Bioacoustics, 5: 187-203.
# generate a sound with sine and linear frequency modulations a<-synth(d=1, f=8000, cf=1500, fm=c(200,10,1000,0,0)) # plot on a single graphical device the instantaneous frequency and phase op<-par(mfrow=c(2,1)) ifreq(a,f=8000,main="Instantaneous frequency") ifreq(a,f=8000,phase=TRUE,main="Instantaneous phase") par(op)
# generate a sound with sine and linear frequency modulations a<-synth(d=1, f=8000, cf=1500, fm=c(200,10,1000,0,0)) # plot on a single graphical device the instantaneous frequency and phase op<-par(mfrow=c(2,1)) ifreq(a,f=8000,main="Instantaneous frequency") ifreq(a,f=8000,phase=TRUE,main="Instantaneous phase") par(op)
This function returns a wave object from a complex STFT matrix by computing the inverse of the short-term Fourier transform (STFT)
istft(stft, f, wl, ovlp=75, wn="hanning", output = "matrix")
istft(stft, f, wl, ovlp=75, wn="hanning", output = "matrix")
stft |
a complex matrix resulting of a short-term Fourier transform. |
f |
sampling frequency of the original |
wl |
FFT window length for the analysis (even number of points). |
ovlp |
overlap between successive FFT windows (in %, by default 75%, see the Details section). |
wn |
character string specifying the FFT window name, see |
output |
character string, the class of the object to return, either
|
The function is based on the inverse of the FFT (see fft
) and on
the overlap add (OLA) method.
The overlap percentage must satisfy the Perfect Reconstruction OLA-constraint. For
the most windows, this constraint is:
with n being a positive integer.
A default value is set to 75%. We suggest not to change it.
A new wave is returned. The class of the returned object is set with the argument output
.
The stft
input data must be complex.
This function is used by ffilter
, lfs
to
respectively filter in frequency and shift in frequency a sound.
The function can be used to reconstruct or modify a sound. See examples.
Original Matlab code by Hristo Zhivomirov (Technical University of Varna, Bulgaria), translated and adapted to R by Jerome Sueur
## Not run: # STFT and iSTFT parameters wl <- 1024 ovlp <- 75 # reconstruction of the tico sound from the stft complex data matrix data(tico) data <- spectro(tico, wl=wl, ovlp=ovlp, plot=FALSE, norm=FALSE, dB=NULL, complex=TRUE)$amp res <- istft(data, ovlp=ovlp, wn="hanning", wl=wl, f=22050, out="Wave") spectro(res) # a strange frequency filter n <- noisew(d=1, f=44100) data <- spectro(n, f=44100, wl=wl, ovlp=ovlp, plot=FALSE, norm=FALSE, dB=NULL, complex=TRUE)$amp data[64:192, 6:24] <- 0 nfilt <- istft(data, f=8000, wl=wl, ovlp=ovlp, output="Wave") spectro(nfilt, wl=wl, ovlp=ovlp) ## End(Not run)
## Not run: # STFT and iSTFT parameters wl <- 1024 ovlp <- 75 # reconstruction of the tico sound from the stft complex data matrix data(tico) data <- spectro(tico, wl=wl, ovlp=ovlp, plot=FALSE, norm=FALSE, dB=NULL, complex=TRUE)$amp res <- istft(data, ovlp=ovlp, wn="hanning", wl=wl, f=22050, out="Wave") spectro(res) # a strange frequency filter n <- noisew(d=1, f=44100) data <- spectro(n, f=44100, wl=wl, ovlp=ovlp, plot=FALSE, norm=FALSE, dB=NULL, complex=TRUE)$amp data[64:192, 6:24] <- 0 nfilt <- istft(data, f=8000, wl=wl, ovlp=ovlp, output="Wave") spectro(nfilt, wl=wl, ovlp=ovlp) ## End(Not run)
Compare two distributions (e.g. two frequency spectra) by computing the Itakuro-Saito distance
itakura.dist(spec1, spec2, scale=FALSE)
itakura.dist(spec1, spec2, scale=FALSE)
spec1 |
any distribution, especially a spectrum obtained with |
spec2 |
any distribution, especially a spectrum obtained with
|
scale |
a logical, if |
The Itakura-Saito (I-S) distance is a
non-symmetric measure of the difference between two probability
distributions. It is here adapted for frequency spectra. The distance
is asymmetric, ie computing the I-S distance between spec1 and spec2 is
not the same as computing it between spec2 and spec1. A symmetry can be
obtained by calculating the mean between the two directions.
The distance is obtained following:
The function returns a list of three items:
D1 |
The I-S distance of 'spec2' with respect to 'spec1' (i.e. D(spec1 || spec2)) |
D2 |
The I-S distance of 'spec1' with respect to 'spec2' (i.e. D(spec2 || spec1)) |
D |
The symmetric distance (i.e. D = 0.5*(D1+D2)) |
If scale = TRUE
the distance is divided by the length of spec1
(or spec2
).
The function works for both Hz and (htk-)mel scales.
Jerome Sueur, improved by Laurent Lellouch
kl.dist
, ks.dist
, logspec.dist
, simspec
, diffspec
# Comparison of two spectra data(tico) tico1 <- spec(tico, at=0.65, plot=FALSE) tico2 <- spec(tico, at=1.1, plot=FALSE) itakura.dist(tico1, tico2) itakura.dist(tico1, tico2, scale=TRUE)
# Comparison of two spectra data(tico) tico1 <- spec(tico, at=0.65, plot=FALSE) tico2 <- spec(tico, at=1.1, plot=FALSE) itakura.dist(tico1, tico2) itakura.dist(tico1, tico2, scale=TRUE)
Compare two distributions (e.g. two frequency spectra) by computing the Kullback-Leibler distance
kl.dist(spec1, spec2, base = 2)
kl.dist(spec1, spec2, base = 2)
spec1 |
any distribution, especially a spectrum obtained with |
spec2 |
any distribution, especially a spectrum obtained with
|
base |
the logarithm base used to compute the distance. See |
The Kullback-Leibler distance or relative entropy is a
non-symmetric measure of the difference between two probability
distributions. It is here adapted for frequency spectra. The distance
is asymmetric, ie computing the K-L distance between spec1 and spec2 is
not the same as computing it between spec2 and spec1. A symmetry can be
obtained by calculating the mean between the two directions.
The distance is obtained following:
The function returns a list of three items:
D1 |
The K-L distance of 'spec2' with respect to 'spec1' (i.e. D(spec1 || spec2)) |
D2 |
The K-L distance of 'spec1' with respect to 'spec2' (i.e. D(spec2 || spec1)) |
D |
The symmetric K-L distance (i.e. D = 0.5*(D1+D2)) |
The base of the logarithm can be changed using the argument
base
. When sets to base 2, the information is measured in units of
bits. When sets to base e, the information is measured in
nats.
The function works for both Hz and (htk-)mel scales.
Jerome Sueur, improved by Laurent Lellouch
Kullback, S., Leibler, R.A. (1951). On information and sufficiency. Annals of Mathematical Statistics, 22: 79-86
ks.dist
, logspec.dist
, simspec
, diffspec
# Comparison of two spectra data(tico) tico1 <- spec(tico, at=0.65, plot=FALSE) tico2 <- spec(tico, at=1.1, plot=FALSE) kl.dist(tico1, tico2) # log2 (binary logarithm) kl.dist(tico1, tico2, base=exp(1)) # ln (natural logarithm)
# Comparison of two spectra data(tico) tico1 <- spec(tico, at=0.65, plot=FALSE) tico2 <- spec(tico, at=1.1, plot=FALSE) kl.dist(tico1, tico2) # log2 (binary logarithm) kl.dist(tico1, tico2, base=exp(1)) # ln (natural logarithm)
This function compares two distributions (e.g. two frequency spectra) by computing the Kolmogorov-Smirnov distance
ks.dist(spec1, spec2, f = NULL, mel = FALSE, plot = FALSE, type = "l", lty = c(1, 2), col = c(2, 4), flab = NULL, alab = "Cumulated amplitude", flim = NULL, alim = NULL, title = TRUE, legend = TRUE, ...)
ks.dist(spec1, spec2, f = NULL, mel = FALSE, plot = FALSE, type = "l", lty = c(1, 2), col = c(2, 4), flab = NULL, alab = "Cumulated amplitude", flim = NULL, alim = NULL, title = TRUE, legend = TRUE, ...)
spec1 |
any distribution, especially a spectrum obtained with |
spec2 |
any distribution, especially a spectrum obtained with
|
f |
sampling frequency of waves used to obtain |
mel |
a logical, if |
plot |
logical, if |
type |
if |
lty |
a vector of length 2 for the line type of |
col |
a vector of length 2 for the colour of |
flab |
title of the frequency axis. |
alab |
title of the amplitude axis. |
flim |
the range of frequency values. |
alim |
range of amplitude axis. |
title |
logical, if |
legend |
logical, if |
... |
other |
The Kolmogorov distance is the maximal distance between the
cumulated spectra. The function returns this distance and the
corresponding frequency. This is an adaptation of the statistic
computed by the non-parametric Kolmogorov-Smirnov test (see ks.test
).
The function returns a list of two items
D |
the Kolomogorov-Smirnov distance |
F |
the frequency (in KHz) where the Kolmogorov-Smirnov distance was found |
There is no p-value associated to the K-S distance.
If no frequency is provided, only the distance D.
Jerome Sueur, improved by Laurent Lellouch
kl.dist
, simspec
,
diffspec
, logspec.dist
, diffcumspec
, itakura.dist
## Comparison of two spectra and plot of the cumulated spectra with the K-S distance data(tico) tico1 <- spec(tico, at=0.65, plot=FALSE) tico2 <- spec(tico, at=1.1, plot=FALSE) ks.dist(tico1, tico2, plot=TRUE) ## mel scale require(tuneR) data(orni) orni.mel <- melfcc(orni, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) orni.mel.mean <- apply(orni.mel$aspectrum, MARGIN=2, FUN=mean) tico.mel <- melfcc(tico, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) tico.mel.mean <- apply(tico.mel$aspectrum, MARGIN=2, FUN=mean) ks.dist(orni.mel.mean, tico.mel.mean, f=22050, mel=TRUE, plot=TRUE)
## Comparison of two spectra and plot of the cumulated spectra with the K-S distance data(tico) tico1 <- spec(tico, at=0.65, plot=FALSE) tico2 <- spec(tico, at=1.1, plot=FALSE) ks.dist(tico1, tico2, plot=TRUE) ## mel scale require(tuneR) data(orni) orni.mel <- melfcc(orni, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) orni.mel.mean <- apply(orni.mel$aspectrum, MARGIN=2, FUN=mean) tico.mel <- melfcc(tico, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) tico.mel.mean <- apply(tico.mel$aspectrum, MARGIN=2, FUN=mean) ks.dist(orni.mel.mean, tico.mel.mean, f=22050, mel=TRUE, plot=TRUE)
This function linearly shifts all the frequency content of a time wave.
lfs(wave, f, channel = 1, shift, wl = 1024, ovlp = 75, wn = "hanning", fftw = FALSE, output = "matrix")
lfs(wave, f, channel = 1, shift, wl = 1024, ovlp = 75, wn = "hanning", fftw = FALSE, output = "matrix")
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
shift |
positive or negative frequency shift to apply (in Hz). |
wl |
window length for the analysis (even number of points, by default = 1024). |
ovlp |
overlap between successive FFT windows (in %, by default 75%). |
wn |
window name, see |
fftw |
if |
output |
character string, the class of the object to return, either
|
A short-term Fourier transform is first applied to the signal
(see spectro
), then the frequency shift is applied and the new
signal is eventually generated using the reverse of the Fourier Transform
(istft
).
There is therefore neither temporal modifications nor
amplitude modifications.
If plot
is FALSE
, a new wave is returned. The class
of the returned object is set with the argument output
.
Jerome Sueur [email protected] and Thierry Aubin [email protected]
Hopp, S. L., Owren, M. J. and Evans, C. S. (Eds) 1998. Animal acoustic communication. Springer, Berlin, Heidelberg.
data(orni) a<-lfs(orni,f=22050,shift=1000) spectro(a,f=22050) # to be compared with the original signal spectro(orni,f=22050)
data(orni) a<-lfs(orni,f=22050,shift=1000) spectro(a,f=22050) # to be compared with the original signal spectro(orni,f=22050)
Play a sound wave
listen(wave, f, channel=1, from = NULL, to = NULL, choose = FALSE)
listen(wave, f, channel=1, from = NULL, to = NULL, choose = FALSE)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
from |
start of play (in s). |
to |
end of play (in s). |
choose |
logical, if |
This function is based on play
but allows to read
one-colum matrix, data.frame, time-series and Sample objects.
Jerome Sueur [email protected] but the original
play
function is by Uwe Ligges (package tuneR).
## NOT RUN # data(tico) # listen(tico,f=22050) # listen(tico,f=22050,from=0.5,to=1.5) # listen(noise(d=1,f=8000,Wave=TRUE)) ## change f to play the sound a different speed # data(sheep) ## normal # listen(sheep,f=8000) ## two times faster # listen(sheep,f=8000*2) ## two times slower # listen(sheep,f=8000/2)
## NOT RUN # data(tico) # listen(tico,f=22050) # listen(tico,f=22050,from=0.5,to=1.5) # listen(noise(d=1,f=8000,Wave=TRUE)) ## change f to play the sound a different speed # data(sheep) ## normal # listen(sheep,f=8000) ## two times faster # listen(sheep,f=8000*2) ## two times slower # listen(sheep,f=8000/2)
This functions searches for local peaks of a frequency spectrum
localpeaks(spec, f = NULL, bands = 10, mel = FALSE, plot = TRUE, xlab = NULL, ylab = "Amplitude", labels = TRUE, ...)
localpeaks(spec, f = NULL, bands = 10, mel = FALSE, plot = TRUE, xlab = NULL, ylab = "Amplitude", labels = TRUE, ...)
spec |
a data set resulting of a spectral analysis obtained
with |
f |
sampling frequency of |
bands |
a numeric vector. If vector of length 1, then sets the number of bands dividing in equal parts the spectrum. If of length > 1, then takes the values as kHz limits of the bands dividing the spectrum. These bands can be of different size. See details and examples. |
mel |
a logical, if |
plot |
logical, if |
xlab |
label of the x-axis. |
ylab |
label of the y-axis. |
labels |
logical, if |
... |
other |
The function proceed as follows
divides the spectrum in bands. The limits of the bands are set
with the argument bands
. There are two options:
you set a number of bands with equal size by giving a single
value to bands
. For instance, setting bands
to a value
of 10 will slice the spectrum in 10 equal parts and return 10 local
peaks.
you set the limits of the bands. This is achieve by giving a
numeric vector to bands
. The limits can follow a regular or
irregular series. For instance attributing the vector c(0,2,4,8) will
generate the following bands [0,2[, [2,4[, [4,8] kHz. Be aware that
the last value should not exceed half the sampling frequency used to
obtain the spectrum spec
.
uses the function fpeaks
with the argument
nmax
set to 1.
A two-column matrix, the first column corresponding to the frequency values (x-axis) and the second column corresponding to the amplitude values (y-axis) of the peaks.
Jerome Sueur
data(sheep) spec <- meanspec(sheep, f=8000) # a specific number of bands with all the same size localpeaks(spec, bands=5) # bands directly specified with a regular sequence localpeaks(spec, bands=seq(0,8/2,by=0.5)) # bands directly specified with an irregular sequence localpeaks(spec, bands=c(0,0.5,1,1.5,3,4)) # Amaj octave bands, note that there is no peak detection # in the higher part of the spectrum as sequence stops at 3520 Hz localpeaks(spec, bands=octaves(440, below=3, above=3)/1000) # melscale require(tuneR) mel <- melfcc(sheep, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) melspec.mean <- apply(mel$aspectrum, MARGIN=2, FUN=mean) melspec.mean <- melspec.mean/max(melspec.mean) # [0,1] scaling localpeaks(melspec.mean, f=8000, bands=8)
data(sheep) spec <- meanspec(sheep, f=8000) # a specific number of bands with all the same size localpeaks(spec, bands=5) # bands directly specified with a regular sequence localpeaks(spec, bands=seq(0,8/2,by=0.5)) # bands directly specified with an irregular sequence localpeaks(spec, bands=c(0,0.5,1,1.5,3,4)) # Amaj octave bands, note that there is no peak detection # in the higher part of the spectrum as sequence stops at 3520 Hz localpeaks(spec, bands=octaves(440, below=3, above=3)/1000) # melscale require(tuneR) mel <- melfcc(sheep, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) melspec.mean <- apply(mel$aspectrum, MARGIN=2, FUN=mean) melspec.mean <- melspec.mean/max(melspec.mean) # [0,1] scaling localpeaks(melspec.mean, f=8000, bands=8)
Compare two distributions (e.g. two frequency spectra) by computing the log-spectral distance
logspec.dist(spec1, spec2, scale=FALSE)
logspec.dist(spec1, spec2, scale=FALSE)
spec1 |
any distribution, especially a spectrum obtained with |
spec2 |
any distribution, especially a spectrum obtained with
|
scale |
a logical, if |
The distance is computed according to:
If scale = TRUE
the distance is divided by the length of spec1
(or spec2
).
A numeric vector of length 1 returning the D distance.
The function works for both Hz and (htk-)mel scales.
The distance is symmetric.
Jerome Sueur, improved by Laurent Lellouch
ks.dist
, kl.dist
,
itakura.dist
, simspec
, diffspec
# Comparison of two spectra data(tico) tico1 <- spec(tico, at=0.65, plot=FALSE) tico2 <- spec(tico, at=1.1, plot=FALSE) logspec.dist(tico1, tico2) logspec.dist(tico1, tico2, scale=TRUE)
# Comparison of two spectra data(tico) tico1 <- spec(tico, at=0.65, plot=FALSE) tico2 <- spec(tico, at=1.1, plot=FALSE) logspec.dist(tico1, tico2) logspec.dist(tico1, tico2, scale=TRUE)
A spectrogram computed over several survey files obtained with a Wildlife Acoustics SongMeter recorder
lts(dir, f, wl = 512, wn = "hanning", ovlp = 0, rmoffset = TRUE, FUN = mean, col = spectro.colors(30), fftw = FALSE, norm = FALSE, verbose = TRUE, tlab = "Time", ntann = NULL, flab = "Frequency (kHz)", recorder = c("songmeter", "audiomoth"), plot = TRUE, ...)
lts(dir, f, wl = 512, wn = "hanning", ovlp = 0, rmoffset = TRUE, FUN = mean, col = spectro.colors(30), fftw = FALSE, norm = FALSE, verbose = TRUE, tlab = "Time", ntann = NULL, flab = "Frequency (kHz)", recorder = c("songmeter", "audiomoth"), plot = TRUE, ...)
dir |
a character vector, the path to the directory where the .wav files are stored or directly the names of the .wav files to be processed. |
f |
sampling frequency of |
wl |
window length for the analysis (even number of points) (by default = 512). |
wn |
window name, see |
ovlp |
overlap between two successive windows (in %). |
rmoffset |
a logical to sepcify whether DC offset should be
removed. By default |
FUN |
the function to apply to compute the successive frequency spectra, by
default |
col |
a list of colors or the color palette with a number of colors |
fftw |
if |
norm |
a logical, to specify if each mean
spectrum should be normalised between 0 and 1 (default |
verbose |
a logical, if |
tlab |
label of the time axis. |
ntann |
a numeric of length 1, the number of axis annotations (all annotations by default). |
flab |
label of the frequency axis. |
recorder |
the type of automatic recorder used, either a Wildlife SongMeter or a Open Audio deveices Audiomoth. |
plot |
logical, if |
... |
other |
The function reads each .wav file and computes its mean spectrum with
meanspec
. The successive mean spectra are then
concatenated into a single image with the function
image
.
The parameters wl
, ovlp
, and wn
are those of the
function meanspec
.
This function returns a list of three items:
time |
a numeric vector corresponding to the time axis. |
freq |
a numeric vector corresponding to the frequency axis. |
amp |
a numeric or a complex matrix corresponding to the amplitude values.
Each column is a Fourier transform of length |
Jerome Sueur
spectro
, meanspec
,
image
,
spectro3D
, ggspectro
,
songmeter
, audiomoth
## Not run: ## if 'dir' contains a set of files recorded with a Wildlife Acoustics # songmeter recorder then a direct way to obtain # the spectrogram of all .wav files is dir <- "pathway-to-directory-containing-wav-files" lts(dir) # to normalise each mean spectrum lts(dir, norm=TRUE) # to change the STFT parameters used to obtain each mean spectrum lts(dir, wl=1024, wn="hamming", ovlp=50) # to change the colors and the number of time labels and to make it quiet lts(dir, col=cm.colors(20), ntann=10, verbose=FALSE) ## direct use of files names stored in the working directory files <- c("S4A09154_20190213_150000.wav", "S4A09154_20190213_153000.wav", "S4A09154_20190213_160000.wav", "S4A09154_20190213_163000.wav", "S4A09154_20190213_170000.wav", "S4A09154_20190213_173000.wav", "S4A09154_20190213_180000.wav", "S4A09154_20190213_183000.wav", "S4A09154_20190213_190000.wav", "S4A09154_20190213_193000.wav") lts(files) ## End(Not run)
## Not run: ## if 'dir' contains a set of files recorded with a Wildlife Acoustics # songmeter recorder then a direct way to obtain # the spectrogram of all .wav files is dir <- "pathway-to-directory-containing-wav-files" lts(dir) # to normalise each mean spectrum lts(dir, norm=TRUE) # to change the STFT parameters used to obtain each mean spectrum lts(dir, wl=1024, wn="hamming", ovlp=50) # to change the colors and the number of time labels and to make it quiet lts(dir, col=cm.colors(20), ntann=10, verbose=FALSE) ## direct use of files names stored in the working directory files <- c("S4A09154_20190213_150000.wav", "S4A09154_20190213_153000.wav", "S4A09154_20190213_160000.wav", "S4A09154_20190213_163000.wav", "S4A09154_20190213_170000.wav", "S4A09154_20190213_173000.wav", "S4A09154_20190213_180000.wav", "S4A09154_20190213_183000.wav", "S4A09154_20190213_190000.wav", "S4A09154_20190213_193000.wav") lts(files) ## End(Not run)
This function computes an acoustic index based on the median of the amplitude envelope.
M(wave, f, channel = 1, envt = "hil", plot = FALSE, ...)
M(wave, f, channel = 1, envt = "hil", plot = FALSE, ...)
wave |
an |
f |
sampling frequency of wave (in Hz). Does not need to be
specified if embedded in |
channel |
channel of the R object, by default left channel (1). |
envt |
the type of envelope to be used: either |
plot |
logical, if TRUE returns a plot of the amplitude envelope of wave (by default |
... |
other env parameters, in particular smoothing parameters. See |
This amplitude index M is computed according to:
with
where A(t) is the amplitude envelope and depth is the signal digitization depth in number of bits.
A numeric vector of length 1 between 0 and 1, without unit.
Jerome Sueur and Marion Depraetere
Depraetere M, Pavoine S, Jiguet F, Gasc A, Duvail S, Sueur J (2012) Monitoring animal diversity using acoustic indices: implementation in a temperate woodland. Ecological Indicators, 13, 46-54.
data(tico) M(tico) # smoothing the amplitude may change slightly the result M(tico, msmooth=c(500,50), plot=TRUE)
data(tico) M(tico) # smoothing the amplitude may change slightly the result M(tico, msmooth=c(500,50), plot=TRUE)
This function calculates the mean of dB values
meandB(x, level="IL")
meandB(x, level="IL")
x |
a numeric vector or a numeric matrix. |
level |
intensity level ( |
The mean of dB values is not linear. See examples.
A numeric vector of length 1 is returned.
Jerome Sueur and Zev Ross
Hartmann, W. M. 1998 Signals, sound and sensation. New York: Springer.
sddB
, moredB
, convSPL
, dBweight
meandB(c(89,90,95))
meandB(c(89,90,95))
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.
meanspec(wave, f, channel = 1, wl = 512, wn = "hanning", ovlp = 0, fftw = FALSE, norm = TRUE, PSD = FALSE, PMF = FALSE, FUN = mean, correction = "none", dB = NULL, dBref = NULL, from = NULL, to = NULL, identify = FALSE, col = "black", cex = 1, plot = 1, flab = "Frequency (kHz)", alab = "Amplitude", flim = NULL, alim = NULL, type ="l", ...)
meanspec(wave, f, channel = 1, wl = 512, wn = "hanning", ovlp = 0, fftw = FALSE, norm = TRUE, PSD = FALSE, PMF = FALSE, FUN = mean, correction = "none", dB = NULL, dBref = NULL, from = NULL, to = NULL, identify = FALSE, col = "black", cex = 1, plot = 1, flab = "Frequency (kHz)", alab = "Amplitude", flim = NULL, alim = NULL, type ="l", ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
wl |
length of the window for the analysis (even number of points, by default = 512). |
wn |
window name, see |
ovlp |
overlap between two successive analysis windows (in %). |
fftw |
if |
norm |
if |
PSD |
if |
PMF |
if |
FUN |
the function to apply on the rows of the STFT matrix, by
default |
correction |
a character vector of length 1 to apply an
amplitude ("amplitude") or an energy ("energy") correction
to the FT window. This argument is useful only when one wish to obtain
absolute values that is when |
dB |
a character string specifying the type dB to return: "max0" for a maximum dB value at 0, "A", "B", "C", "D", and "ITU" for common dB weights. |
dBref |
a dB reference value when |
from |
start mark where to compute the spectrum (in s). |
to |
end mark where to compute the spectrum (in s). |
identify |
to identify frequency and amplitude values on the plot with the help of a cursor. |
col |
colour of the spectrum. |
cex |
pitch size. |
plot |
if |
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 |
... |
other |
See examples of spec
. This function is based on fft
.
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:
freq |
the frequency of the points chosen on the spectrum |
amp |
the relative amplitude of the points chosen on the spectrum |
The argument peaks
is no more available
(version > 1.5.6). See the function fpeaks
for peak(s) detection.
The argument fftw
can be used to try to speed up process
time. When set to TRUE
, the Fourier transform is computed
through the function FFT
of the package fftw
. This package is a
wrapper around the fastest Fourier transform of the free C subroutine
library FFTW (http://www.fftw.org/). FFT should be then installed on your OS.
Jerome Sueur [email protected]
spec
,fpeaks
,
localpeaks
, dynspec
,
corspec
, diffspec
, simspec
, fft
.
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) # log scale on frequency axis meanspec(orni, f=22050, log="x") # median spectrum meanspec(orni,f=22050, FUN=median) # variance spectrum meanspec(orni,f=22050, FUN=var)
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) # log scale on frequency axis meanspec(orni, f=22050, log="x") # median spectrum meanspec(orni,f=22050, FUN=median) # variance spectrum meanspec(orni,f=22050, FUN=var)
This function converts Hertz data in Mel data.
mel(x, inverse = FALSE)
mel(x, inverse = FALSE)
x |
a value in Hertz (or in Mel if |
inverse |
logical, if |
Hertz to mel conversion is computed according to:
with m in Mel and f in Hertz.
Mel to Hertz conversion (when inverse
is TRUE
)
is therefore computed according to:
with f in Hertz and m in Mel.
A corresponding R object is returned.
The Mel scale is a perceptual scale of pitches judged by listeners to be equal in distance from one another. The name Mel comes from the word melody to indicate that the scale is based on pitch comparisons. The reference point between this scale and normal frequency measurement is defined by equating a 1000 Hz tone, 40 dB above the listener's threshold, with a pitch of 1000 mels.
Jerome Sueur [email protected]
Stevens, S. S., Volkman, J. and Newman, E. B. 1937. A scale for the measurement of psychological magnitude pitch. Journal of the Acoustical Society of America, 8: 185-190.
x<-seq(0,10000,by=50) y<-mel(x) plot(x,y,type="l",xlab = "f (hertz)", ylab = "f (mel)", main = "Mel scale", col="red")
x<-seq(0,10000,by=50) y<-mel(x) plot(x,y,type="l",xlab = "f (hertz)", ylab = "f (mel)", main = "Mel scale", col="red")
This functions returns graphically and numerically the Mel-filters used to compute MFCC.
melfilterbank(f = 44100, wl = 1024, minfreq = 0, maxfreq = f/2, m = 20, palette, alpha = 0.5, plot = FALSE)
melfilterbank(f = 44100, wl = 1024, minfreq = 0, maxfreq = f/2, m = 20, palette, alpha = 0.5, plot = FALSE)
f |
sammpling frequency (in Hz). |
wl |
the Fourier window length (in number of samples). |
minfreq |
the minimum (or lower) frequency of the filter bank (in Hz). |
maxfreq |
the maximum (or upper) frequency of the filter bank (in Hz). |
m |
the total number of filters. |
palette |
an optional colour palette if |
alpha |
alpha-transparency when a colour palette is used. |
plot |
if |
A list of 3 items:
central.freq |
the kHz central frequencies of the filters, |
freq |
the kHz frequency scale, |
amp |
the amplitude of the filters, scaled between 0 and 1. |
These triangular filters are used for computing MFCCs.
Jerome Sueur
Sharan RV & Moir TJ (2016) Applications and advancements in automatic sound recognition. Neurocomputing.
## default values melfilterbank(plot=TRUE) ## with color surfaces melfilterbank(palette=cm.colors, plot=TRUE) ## values changed res <- melfilterbank(f=16000, wl=512, minfreq=300, plot=TRUE) ## plot the 1st filter only plot(res$freq, res$amp[,1], type="l", xlab="Frequency (kHz)", ylab="Amplitude") ## plot the last filter only plot(res$freq, res$amp[,ncol(res$amp)], type="l", xlab="Frequency (kHz)", ylab="Amplitude") ## get the kHz central frequencies of the succesive filters res$central.freq
## default values melfilterbank(plot=TRUE) ## with color surfaces melfilterbank(palette=cm.colors, plot=TRUE) ## values changed res <- melfilterbank(f=16000, wl=512, minfreq=300, plot=TRUE) ## plot the 1st filter only plot(res$freq, res$amp[,1], type="l", xlab="Frequency (kHz)", ylab="Amplitude") ## plot the last filter only plot(res$freq, res$amp[,ncol(res$amp)], type="l", xlab="Frequency (kHz)", ylab="Amplitude") ## get the kHz central frequencies of the succesive filters res$central.freq
This function converts microphone sensitivity from mV/Pa to dB.
micsens(x, sref = 1, inverse = FALSE)
micsens(x, sref = 1, inverse = FALSE)
x |
a measured sensitivity in mV/Pa (or in dB if |
sref |
the sensitivity reference (by default equals to 1 V/Pa) |
inverse |
logical, if |
The sensitivity S in dB is calculated according to:
with s the measured sensitivity in mv/Pa and sref the reference sensitivity (by default 1 mV/Pa).
A numeric value in dB re 1V/Pa with default settings,
in mV/Pa if inverse
is set to FALSE
.
Jerome Sueur [email protected]
# conversion of a sensitivity of 2 mV/Pa micsens(2) # conversion of a sensitivity of -54 dB re 1V/Pa micsens(-54,inverse=TRUE)
# conversion of a sensitivity of 2 mV/Pa micsens(2) # conversion of a sensitivity of -54 dB re 1V/Pa micsens(-54,inverse=TRUE)
This functions calculates the sum of dB values
moredB(x, level="IL")
moredB(x, level="IL")
x |
a numeric vector or numeric matrix. |
level |
intensity level ( |
The addition of dB values is not linear. See examples.
A numeric vector of length 1.
Jerome Sueur
Hartmann, W. M. 1998 Signals, sound and sensation. New York: Springer.
meandB
, sddB
, convSPL
, dBweight
# two sources of 60 dB give an intensity level of 63 dB moredB(c(60,60)) # addition of three sources moredB(c(89,90,95))
# two sources of 60 dB give an intensity level of 63 dB moredB(c(60,60)) # addition of three sources moredB(c(89,90,95))
This functions replaces a time wave or a section of a time wave by 0 values. For a time wave describing a sound, this corresponds in muting the sound or a section of it.
mutew(wave, f, channel = 1, from = NULL, to = NULL, choose = FALSE, plot = TRUE, output = "matrix", ...)
mutew(wave, f, channel = 1, from = NULL, to = NULL, choose = FALSE, plot = TRUE, output = "matrix", ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
from |
start of the silence section (in s). |
to |
end of the silence section (in s). |
choose |
logical, if |
plot |
logical, if |
output |
character string, the class of the object to return, either
|
... |
other |
By default, from
and from
are NULL
,
this results in completely muting wave
.
If plot
is FALSE
, a new wave is returned. The class
of the returned object is set with the argument output
.
Jerome Sueur [email protected]
oscillo
, addsilw
, cutw
,
deletew
,fadew
, pastew
,
revw
, zapsilw
data(tico) mutew(tico,f=22050,from=0.5,to=0.9)
data(tico) mutew(tico,f=22050,from=0.5,to=0.9)
This function computes the Normalized Difference Soundscape Index as described by Kasten et al. (2012).
NDSI(x, anthropophony = 1, biophony = 2:8, max = FALSE)
NDSI(x, anthropophony = 1, biophony = 2:8, max = FALSE)
x |
a two-column numeric matrix computed with |
anthropophony |
a numeric vector defining the frequency band(s) of the anthropophony (in kHz). |
biophony |
a numeric vector defining the frequency band(s) of the biophony (in kHz). |
max |
a logical, if |
NDSI aims at estimating the level of anthropogenic disturbance on the soundscape by
computing the ratio of human-generated (anthropophony) to biological
(biophony) acoustic components found in field collected sound
samples. In terms of frequency, the anthropophony is defined as the [1-2[
kHz frequency bin and the biophony as the [2-8[ kHz frequency bins of a
soundscape frequency spectrum (see soundscapespec
).
NDSI is computed according to:
NDSI varies between -1 and +1, where +1 indicates a signal containing
no anthropophony.
A numeric vector of length 1 giving the NDSI value.
Jerome Sueur
Kasten, E.P., Gage, S.H., Fox, J. & Joo, W. (2012). The remote
environmental assessment laboratory's acoustic library: an archive for
studying soundscape ecology. Ecological Informatics, 12, 50-67.
## Note that 'tico' is not a soundscape recording... data(tico) spec <- soundscapespec(tico, plot=FALSE) NDSI(spec) NDSI(spec, max=TRUE)
## Note that 'tico' is not a soundscape recording... data(tico) spec <- soundscapespec(tico, plot=FALSE) NDSI(spec) NDSI(spec, max=TRUE)
This function generates noise.
noisew(f, d, type="unif", listen = FALSE, output = "matrix")
noisew(f, d, type="unif", listen = FALSE, output = "matrix")
f |
sampling frequency of the signal to be generated (in Hz) |
d |
duration of the signal to be generated. |
type |
a character string to specify the type of noise, either "unif" or "gaussian". |
listen |
if |
output |
character string, the class of the object to return, either
|
Uniform noise is generated using runif
and gaussian noise is based on rnorm
A new wave is returned. The class of the returned object is set with the argument output
.
Jerome Sueur [email protected]
# add noise to a synthetic signal a<-noisew(d=1,f=8000) b<-synth(f=8000,d=1,cf=2000,plot=FALSE) c<-a+b spectro(c,f=8000)
# add noise to a synthetic signal a<-noisew(d=1,f=8000) b<-synth(f=8000,d=1,cf=2000,plot=FALSE) c<-a+b spectro(c,f=8000)
This function computes the frequency of a musical note (Equal temperament)
notefreq(note, ref = 440, octave = 3)
notefreq(note, ref = 440, octave = 3)
note |
a numerical or a character vector. See |
ref |
a numerical vector of length 1 for the reference frequency. |
octave |
a numerical vector of length for the octave number. |
The frequency is computed according to:
with:
ref = reference frequency,
octave = octave number, and
note = rank of the note along the scale.
The frequency in Hz is returned.
The note can be given in two ways. The first solution is to give the rank of the note along the scale (e.g. rank 10 for A) or to give its names in characters with the following notation: C, D, E, F, G, A, B.
Jerome Sueur
# Some notes frequency (use apply-like functions when dealing with character strings) sapply(c("C", "A", "Gb"), notefreq) # C major scale plot n <- 1:12 freq <- notefreq(n) names <- c("C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B") plot(n, freq, pch=19, cex=1.5, xlab = "Note name", ylab = "Frequency (Hz)", xaxt="n", las=1, main="Third octave") axis(side=1, at=n, labels=names) abline(h=freq, col="lightgrey") # C major scale sound f <- 2000 # sampling rate s <- NULL for (i in 1:length(freq)) { tmp <- synth(d=0.5, f=f, cf=freq[i]) s <- pastew(s, tmp, at="start", f) } spectro(s, f, ovlp=75)
# Some notes frequency (use apply-like functions when dealing with character strings) sapply(c("C", "A", "Gb"), notefreq) # C major scale plot n <- 1:12 freq <- notefreq(n) names <- c("C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B") plot(n, freq, pch=19, cex=1.5, xlab = "Note name", ylab = "Frequency (Hz)", xaxt="n", las=1, main="Third octave") axis(side=1, at=n, labels=names) abline(h=freq, col="lightgrey") # C major scale sound f <- 2000 # sampling rate s <- NULL for (i in 1:length(freq)) { tmp <- synth(d=0.5, f=f, cf=freq[i]) s <- pastew(s, tmp, at="start", f) } spectro(s, f, ovlp=75)
This functions returns the frequency values of the octaves below and above a specific frequency
octaves(x, below = 3, above = 3)
octaves(x, below = 3, above = 3)
x |
a numeric vector, frequency of the note in Hz or kHz. |
below |
the number of octaves below |
above |
the number of octaves above |
A numeric vector with the octave series in frequency (Hz or kHz
depending on x
unit).
Jerome Sueur
names <- c("C","D","E","F","G","A","B") values <- c(261.63, 293.66, 329.64, 349.23, 392, 440, 493.88) res <- sapply(values, FUN=octaves)/1000 op <- par(las=1,mfrow=c(2,1)) par(mar=c(0,4,1,1)) matplot(x=1:7, y=res, t="o", pch=names, xlab="", ylab="Frequency (kHz) [linear scale]", col=rainbow(7), xaxt="n") par(mar=c(4.5,4,0,1)) matplot(x=1:7, y=res, t="o", pch=names, xlab="Octave", ylab="Frequency (kHz) [log scale]", col=rainbow(7), ylog=TRUE, log="y") par(op)
names <- c("C","D","E","F","G","A","B") values <- c(261.63, 293.66, 329.64, 349.23, 392, 440, 493.88) res <- sapply(values, FUN=octaves)/1000 op <- par(las=1,mfrow=c(2,1)) par(mar=c(0,4,1,1)) matplot(x=1:7, y=res, t="o", pch=names, xlab="", ylab="Frequency (kHz) [linear scale]", col=rainbow(7), xaxt="n") par(mar=c(4.5,4,0,1)) matplot(x=1:7, y=res, t="o", pch=names, xlab="Octave", ylab="Frequency (kHz) [log scale]", col=rainbow(7), ylog=TRUE, log="y") par(op)
Recording of a calling song section of the Mediterranean cicada Cicada orni.
data(orni)
data(orni)
A Wave object.
Duration = 0.719 s. Sampling frequency = 22050 Hz.
Recording by Jerome Sueur.
data(orni) oscillo(orni,f=22050)
data(orni) oscillo(orni,f=22050)
This graphical function displays a time wave as an oscillogram in a single or multi-frame plot. The envelope of the wave can also be shown.
oscillo(wave, f, channel = 1, from = NULL, to = NULL, fastdisp = FALSE, scroll = NULL, zoom = FALSE, k=1, j=1, cex, labels = TRUE, tlab = "Time (s)", alab = "Amplitude", byrow = TRUE, identify = FALSE, nidentify = NULL, plot = TRUE, colwave = "black", coltitle = "black", cextitle = 1.2, fonttitle = 2, collab = "black", cexlab = 1, fontlab = 1, colline = "black", colaxis = "black", cexaxis = 1, fontaxis = 1, coly0 = "lightgrey", tcl = 0.5, title = FALSE, xaxt="s", yaxt="n", type="l", bty = "l")
oscillo(wave, f, channel = 1, from = NULL, to = NULL, fastdisp = FALSE, scroll = NULL, zoom = FALSE, k=1, j=1, cex, labels = TRUE, tlab = "Time (s)", alab = "Amplitude", byrow = TRUE, identify = FALSE, nidentify = NULL, plot = TRUE, colwave = "black", coltitle = "black", cextitle = 1.2, fonttitle = 2, collab = "black", cexlab = 1, fontlab = 1, colline = "black", colaxis = "black", cexaxis = 1, fontaxis = 1, coly0 = "lightgrey", tcl = 0.5, title = FALSE, xaxt="s", yaxt="n", type="l", bty = "l")
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
from |
start of the oscillogram (in s). |
to |
end of the oscillogram (in s). |
fastdisp |
faster graphic display for long |
scroll |
a numeric of length 1 allowing to move along the time wave using a slider panel. This numeric corresponds to the number of successive windows dividing the time wave. |
zoom |
time zoom in with start and end points chosen on the oscillogram with a cursor. |
k |
number of horizontal sections (by default =1). |
j |
number of vertical sections (by default =1). |
cex |
pitch size if |
labels |
if |
tlab |
label of time axis. |
alab |
label of amplitude axis. |
byrow |
logical, if |
identify |
returns the time and amplitude coordinates of points chosen with a cursor on the oscillogram. |
nidentify |
a numeric vector of length 1, specifies the number of
points to identified on |
plot |
logical, if |
colwave |
colour of the oscillogram or of the envelope. |
coltitle |
if |
cextitle |
character size for the title. |
fonttitle |
font for the title. |
cexlab |
character size for axes labels. |
fontlab |
font for axes labels. |
collab |
colour of axes labels. |
colline |
colour of axes line. |
colaxis |
colour of the axis annotation. |
fontaxis |
font of axis annotation. |
cexaxis |
magnification for axis annotation. |
coly0 |
colour of the y=0 line. |
tcl |
length of tick marks. |
title |
|
xaxt |
equivalent to |
yaxt |
equivalent to |
type |
type of plot, by default |
bty |
the type of box to be drawn around the oscillogram. |
Data are returned as one-column matrix if plot
is FALSE
.
identify
returns a two-column matrix with the time and
amplitude coordinates of points successively chosen on the oscillogram.
zoom
is similar to but more visual than from
and/or to
.
zoom
and identify
do work with a single-frame window only
(i. e. with k
= 1 and j
= 1).
Press ‘Stop’ button of the tools bar after choosing the appropriate
points on the oscillogram.
Jerome Sueur [email protected] and Caroline Simonis [email protected].
dynoscillo
, oscilloST
,
oscilloEQ
, cutw
, pastew
,
timer
data(tico) # a simple oscillogram of a bird song oscillo(tico) # zoom in op<-par(mfrow=c(4,1),mar=c(4.5,4,2,2)) oscillo(tico,22050,cexlab=0.75) oscillo(tico,22050,from=0.5,to=0.9,cexlab=0.75) oscillo(tico,22050,from=0.65,to=0.75,cexlab=0.75) oscillo(tico,22050,from=0.68,to=0.70,cexlab=0.75) par(op) # the same divided in four lines oscillo(tico,f=22050,k=4,j=1) # the same divided in different numbers of lines and columns oscillo(tico,f=22050,k=4,j=4) oscillo(tico,f=22050,k=2,j=2,byrow=TRUE) oscillo(tico,f=22050,k=2,j=2,byrow=FALSE) # overplot of oscillographic and envelope representations oscillo(tico,f=22050) par(new=TRUE) env(tico,f=22050,colwave=2) # full colour modifications in a two-frame oscillogram op<-par(bg="grey") oscillo(tico,f=22050,k=4,j=1,title=TRUE,colwave="black", coltitle="yellow",collab="red",colline="white", colaxis="blue",coly0="grey50") par(op) # change the title data(orni) oscillo(orni,f=22050,title="The song of a famous cicada") # move along the signal using scroll ## Not run: require(rpanel) oscillo(tico,f=22050,scroll=8) ## End(Not run)
data(tico) # a simple oscillogram of a bird song oscillo(tico) # zoom in op<-par(mfrow=c(4,1),mar=c(4.5,4,2,2)) oscillo(tico,22050,cexlab=0.75) oscillo(tico,22050,from=0.5,to=0.9,cexlab=0.75) oscillo(tico,22050,from=0.65,to=0.75,cexlab=0.75) oscillo(tico,22050,from=0.68,to=0.70,cexlab=0.75) par(op) # the same divided in four lines oscillo(tico,f=22050,k=4,j=1) # the same divided in different numbers of lines and columns oscillo(tico,f=22050,k=4,j=4) oscillo(tico,f=22050,k=2,j=2,byrow=TRUE) oscillo(tico,f=22050,k=2,j=2,byrow=FALSE) # overplot of oscillographic and envelope representations oscillo(tico,f=22050) par(new=TRUE) env(tico,f=22050,colwave=2) # full colour modifications in a two-frame oscillogram op<-par(bg="grey") oscillo(tico,f=22050,k=4,j=1,title=TRUE,colwave="black", coltitle="yellow",collab="red",colline="white", colaxis="blue",coly0="grey50") par(op) # change the title data(orni) oscillo(orni,f=22050,title="The song of a famous cicada") # move along the signal using scroll ## Not run: require(rpanel) oscillo(tico,f=22050,scroll=8) ## End(Not run)
A multipanel plot of a time wave displaying the oscillogram of a bank of frequency filters like in an 'equalizer'.
oscilloEQ(wave, f, channel = 1, flim = NULL, colwave = 1, xlab = "Time (s)", ylab = "Frequency band (kHz)", cexlab = 1, collab = 1, fontlab = 1, savedir = ".", plot = TRUE, ...)
oscilloEQ(wave, f, channel = 1, flim = NULL, colwave = 1, xlab = "Time (s)", ylab = "Frequency band (kHz)", cexlab = 1, collab = 1, fontlab = 1, savedir = ".", plot = TRUE, ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
flim |
a numeric vector giving the ordered limites of the frequency filters to be applied. By default, 1 kHz frequency filters. |
colwave |
colour of the oscillogram. |
xlab |
label of the x axis. |
ylab |
label of the y axis. |
cexlab |
character size for axes labels. |
collab |
color for axes labels. |
fontlab |
font for axes labels. |
savedir |
the path were the |
plot |
a logical, if |
... |
other |
The function applies a bank of filters as delimited with the argument
flim
.
If plot
is TRUE
, then the function displays the wave on a multiframe plot
so that the time*amplitude dynamics of each frequency filter can
be estimated. The filtered waves are generated using the function fir
.
If plot
is FALSE
, then the corresponding waves are saved
as separated .wav
file. Each file corresponds to a frequency
filter.
If plot
is FALSE
then a series of .wav
files are saved. Each file
corresponds to a frequency filter.
Jerome Sueur
data(peewit) ## default 1 kHz frequency filter oscilloEQ(peewit) ## change de frequency filter limits oscilloEQ(peewit, flim=c(0, 4, 8, 10)) oscilloEQ(peewit, flim=seq(2, 10, by=0.5)) ## play with colors oscilloEQ(peewit, colwave=c(1,2)) oscilloEQ(peewit, colwave=heat.colors) blue.gray <- colorRampPalette(c("darkblue", "lightgrey")) oscilloEQ(peewit, colwave=blue.gray) ## save files instead of visualizing them ## Not run: oscilloEQ(peewit, plot=FALSE) ## End(Not run)
data(peewit) ## default 1 kHz frequency filter oscilloEQ(peewit) ## change de frequency filter limits oscilloEQ(peewit, flim=c(0, 4, 8, 10)) oscilloEQ(peewit, flim=seq(2, 10, by=0.5)) ## play with colors oscilloEQ(peewit, colwave=c(1,2)) oscilloEQ(peewit, colwave=heat.colors) blue.gray <- colorRampPalette(c("darkblue", "lightgrey")) oscilloEQ(peewit, colwave=blue.gray) ## save files instead of visualizing them ## Not run: oscilloEQ(peewit, plot=FALSE) ## End(Not run)
This graphical function displays a stereo (2 channels) time wave as an oscillogram in a two-frame plot. The envelope of the wave can also be shown.
oscilloST(wave1, wave2 = NULL, f, from = NULL, to = NULL, fastdisp = FALSE, identify = FALSE, plot = TRUE, colwave1 = "black", colwave2 = "blue", coltitle = "black", collab = "black", cexlab = 1, fontlab = 1, colaxis = "black", cexaxis = 1, coly01 = "grey47", coly02 = "black", title = FALSE, bty = "l")
oscilloST(wave1, wave2 = NULL, f, from = NULL, to = NULL, fastdisp = FALSE, identify = FALSE, plot = TRUE, colwave1 = "black", colwave2 = "blue", coltitle = "black", collab = "black", cexlab = 1, fontlab = 1, colaxis = "black", cexaxis = 1, coly01 = "grey47", coly02 = "black", title = FALSE, bty = "l")
wave1 |
a first R object. |
wave2 |
a second R object. |
f |
sampling frequency of |
from |
start of the oscillogram (in s). |
to |
end of the oscillogram (in s). |
fastdisp |
faster graphic display for long |
identify |
returns the time coordinate of points chosen with a cursor on the bottom oscillogram. |
plot |
logical, if |
colwave1 |
colour of the oscillogram or of the envelope of |
colwave2 |
colour of the oscillogram or of the envelope of |
coltitle |
if |
collab |
colour of axes title. |
cexlab |
character size for axes title. |
fontlab |
font for axes title. |
colaxis |
colour of the axes |
cexaxis |
mangification for axes annotation. |
coly01 |
colour of the y=0 line of |
coly02 |
colour of the y=0 line of |
title |
logical, if |
bty |
the type of box to be drawn around the oscillogram. |
Data are returned as two-column matrix if plot
is FALSE
.
identify
returns a numeric object with the time coordinate
of points successively chosen on the bottom oscillogram.
Jerome Sueur and Caroline Simonis.
oscillo
, oscilloEQ
, dynoscillo
a<-synth(f=8000,d=1,cf=2000,am=c(50,10),plot=FALSE) b<-synth(f=8000,d=1,cf=1000,fm=c(0,0,2000,0,0),plot=FALSE) oscilloST(a,b,f=8000)
a<-synth(f=8000,d=1,cf=2000,am=c(50,10),plot=FALSE) b<-synth(f=8000,d=1,cf=1000,fm=c(0,0,2000,0,0),plot=FALSE) oscilloST(a,b,f=8000)
This function pastes a first time wave to a second one. The time wave to be pasted, the time wave to be completed and the resulting time wave can be displayed in a three-frame oscillographic plot.
pastew(wave1, wave2, f, channel = c(1,1), at = "end", join = FALSE, tjunction = 0, choose = FALSE, plot = FALSE, marks = TRUE, output = "matrix", ...)
pastew(wave1, wave2, f, channel = c(1,1), at = "end", join = FALSE, tjunction = 0, choose = FALSE, plot = FALSE, marks = TRUE, output = "matrix", ...)
wave1 |
a first R object. |
wave2 |
a second R object. |
f |
sampling frequency of |
channel |
channel of the R objects, by default left channel (1) for each object. |
at |
|
join |
if |
tjunction |
a numeric vector to remove clicks at the junction of ‘wave1’ and ‘wave2’. The value specifies the duration in seconds where the real vales will be replaced by a linear interpolation. This duration should be a few milliseconds. |
choose |
logical, if |
plot |
logical, if |
marks |
logical, if |
output |
character string, the class of the object to return, either
|
... |
other |
If plot
is TRUE
returns a two-frame plot with three waves:
(1) the wave to be pasted (wave1
),
(2) the wave to be completed (wave2
),
(3) the resulting wave.
If plot
is FALSE
, a new wave is returned. The class
of the returned object is set with the argument output
.
Jerome Sueur, improved by Laurent Lellouch
oscillo
, addsilw
, cutw
,
deletew
, fadew
, mutew
, revw
, repw
, timelapse
, zapsilw
data(tico) # double a data set describing a bird song a<-pastew(tico,tico,f=22050) oscillo(a,f=22050) # a direct way to see what has been pasted pastew(tico,tico,f=22050,plot=TRUE) # cut a section and then paste it at the beginning a<-cutw(tico, f=22050, from=0.5, to=0.9) pastew(a,tico,f=22050,at="start",plot=TRUE) # or paste it at a specific location pastew(a,tico,f=22050,at=1.4,plot=TRUE) # setting the argument 'join' to TRUE might be useful # to smooth pasting when some phase problem occur # generate two sine waves a <- synth(cf=50, f=400, d=0.1) b <- synth(cf=100, f=400, d=0.1) # paste it with 'join' turned to FALSE # there is a click at the junction between the two waves pastew(a, b, f=400, plot=TRUE) # that can be removed by setting 'join' to TRUE pastew(a, b, f=400, join=TRUE, plot=TRUE) # or by using the argument 'tjunction' pastew(a, b, f=400, tjunction=0.01, plot=TRUE)
data(tico) # double a data set describing a bird song a<-pastew(tico,tico,f=22050) oscillo(a,f=22050) # a direct way to see what has been pasted pastew(tico,tico,f=22050,plot=TRUE) # cut a section and then paste it at the beginning a<-cutw(tico, f=22050, from=0.5, to=0.9) pastew(a,tico,f=22050,at="start",plot=TRUE) # or paste it at a specific location pastew(a,tico,f=22050,at=1.4,plot=TRUE) # setting the argument 'join' to TRUE might be useful # to smooth pasting when some phase problem occur # generate two sine waves a <- synth(cf=50, f=400, d=0.1) b <- synth(cf=100, f=400, d=0.1) # paste it with 'join' turned to FALSE # there is a click at the junction between the two waves pastew(a, b, f=400, plot=TRUE) # that can be removed by setting 'join' to TRUE pastew(a, b, f=400, join=TRUE, plot=TRUE) # or by using the argument 'tjunction' pastew(a, b, f=400, tjunction=0.01, plot=TRUE)
Recording of a song emitted by a peewit (lapwing) male Vanellus vanellus
data(peewit)
data(peewit)
A Wave object.
Duration = 0.706 s. Sampling frequency = 22050 hz.
Recording by Thierry Aubin.
data(peewit) oscillo(peewit,f=22050)
data(peewit) oscillo(peewit,f=22050)
Recording of a calling song section emitted by the European tree cricket Oecanthus pellucens.
data(pellucens)
data(pellucens)
A Wave object.
Duration = 3.309 s. Sampling frequency = 11025 hz.
Recording by Jerome Sueur.
data(pellucens) oscillo(pellucens,f=11025)
data(pellucens) oscillo(pellucens,f=11025)
This function returns a 2D or 3D representation of a time wave according to its first, second and possibly third derivatives.
phaseplot(wave, f, channel = 1, dim = 3, plot = TRUE, type = "l", xlab = "1st derivative", ylab = "2nd derivative", zlab = "3rd derivative", ...)
phaseplot(wave, f, channel = 1, dim = 3, plot = TRUE, type = "l", xlab = "1st derivative", ylab = "2nd derivative", zlab = "3rd derivative", ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
dim |
a vector of lenght 1, the number of dimensions of the plot. Can be either 2 or 3. |
plot |
logical, if |
type |
type of plot that should be drawn. See |
xlab |
title of the x axis. |
ylab |
title of the y axis. |
zlab |
title of the z axis. |
... |
other |
If plot
is FALSE
then a 2 or 3 column matrix is
returned. The position of the column is related to the order of the
derivative (i. e. first colum = first derivative.
Phase-phase plot can be used to test non-linearity.
Jerome Sueur
For use of such plots see: Rice AN, Land BR, Bass AH (2011) - Nonlinear acoustic complexity in a fish 'two-voice' system. Proceedings of the Royal Society B, in press.
## Not run: require(rgl) data(tico) phaseplot(tico) ## End(Not run) s <- synth(d=0.05, f=44100, cf=440, out="Wave") n <- noisew(d=0.05, f=44100, out="Wave") par(mfrow=c(2,1)) phaseplot(s, dim=2) phaseplot(n, dim=2)
## Not run: require(rgl) data(tico) phaseplot(tico) ## End(Not run) s <- synth(d=0.05, f=44100, cf=440, out="Wave") n <- noisew(d=0.05, f=44100, out="Wave") par(mfrow=c(2,1)) phaseplot(s, dim=2) phaseplot(n, dim=2)
This functions returns a 2D representation of a time wave against a delayed version of itself.
phaseplot2(wave, f, channel = 1, tau = 1, type = "l", xlab = "x(t)", ylab = paste("x(t+", tau, ")", sep = ""), ...)
phaseplot2(wave, f, channel = 1, tau = 1, type = "l", xlab = "x(t)", ylab = paste("x(t+", tau, ")", sep = ""), ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
tau |
the time delay to apply in number of samples. |
type |
type of plot that should be drawn. See |
xlab |
title of the x axis. |
ylab |
title of the y axis. |
... |
other |
The principle consists in displaying in a single x-y graph the
original time wave with a delayed version of itself. The delay is
controlled with the argument tau
that needs to be specified in
number of samples. The conversion of tau
in second is obtained by calculating
tau/f
, with f
the sampling frequency.
Nothing is returned except an x-y plot.
Phase-phase plot can be used to test non-linearity.
Jerome Sueur
Kantz H, Schreiber T (2003) Non linear time series analysis. Cambridge University Press.
s <- synth(d=0.05, f=44100, cf=440, out="Wave") n <- noisew(d=0.05, f=44100, out="Wave") par(mfrow=c(2,1)) phaseplot2(s) phaseplot2(n)
s <- synth(d=0.05, f=44100, cf=440, out="Wave") n <- noisew(d=0.05, f=44100, out="Wave") par(mfrow=c(2,1)) phaseplot2(s) phaseplot2(n)
This function works as a playlist, ie it plays back a list of sound files.
playlist(directory, sample = FALSE, loop = 1)
playlist(directory, sample = FALSE, loop = 1)
directory |
a character vector indicating the path to the directory where sound files to played are saved. |
sample |
a logical, if |
loop |
a numeric vector of length 1, number of loops. |
The success of using this function depends on the wave player in use. This works particularly well with SoX under Linux. The type of files (.mp3, .wav, .ogg etc) depends on the wave player as well)
None. Listen and enjoy!
The function is mainly based on play
Jérôme Sueur
## Not run: playlist("MyMusic", sample = TRUE, loop=2) ## End(Not run)
## Not run: playlist("MyMusic", sample = TRUE, loop=2) ## End(Not run)
A pre-emphasis frequency filter for speech
preemphasis(wave, f, channel = 1, alpha = 0.9, plot = FALSE, output = "matrix", ...)
preemphasis(wave, f, channel = 1, alpha = 0.9, plot = FALSE, output = "matrix", ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
alpha |
time constant, see |
plot |
a logical, if |
output |
character string, the class of the object to return,
either |
... |
other arguments to be passed to |
The function applies a pre-emphasis filter usually applied in speech analysis. The filter is a kind of high-pass frequency filter that amplifies the high-frequency content of the sample. The filter is defined with:
where alpha is a time constant usually set between 0.9 and 1.
The frequency response of the filter is obtained with:
A new wave is returned. The class of the returned object is set with the argument output
.
Jerome Sueur
bwfilter
, combfilter
, ffilter
, fir
,lfs
, afilter
data(sheep) fc <- 150 f <- [email protected] alpha <- exp(-2*pi*fc/f) res <- preemphasis(sheep, alpha=alpha, output="Wave")
data(sheep) fc <- 150 f <- sheep@samp.rate alpha <- exp(-2*pi*fc/f) res <- preemphasis(sheep, alpha=alpha, output="Wave")
This function generates a rectangle pulse.
pulsew(dbefore, dpulse, dafter, f, plot = FALSE, output = "matrix", ...)
pulsew(dbefore, dpulse, dafter, f, plot = FALSE, output = "matrix", ...)
dbefore |
duration of the silent period before the pulse |
dpulse |
duration of the pulse to generate |
dafter |
duration of silent period after the pulse |
f |
sampling frequency of the signal to be generated (in Hz) |
plot |
logical, if |
output |
character string, the class of the object to return, either
|
... |
other |
If plot
is FALSE
, a new wave is returned. The class
of the returned object is set with the argument output
.
Jerome Sueur [email protected]
pulsew(dbefore=0.5,dpulse=0.1,dafter=0.3,f=8000,plot=TRUE)
pulsew(dbefore=0.5,dpulse=0.1,dafter=0.3,f=8000,plot=TRUE)
This function estimates the frequency pureness of a time wave by returning the resonant quality factor Q at a specific dB level.
Q(spec, f = NULL, level = -3, mel = FALSE, plot = TRUE, colval = "red", cexval = 1, fontval = 1, flab = NULL, alab = "Relative amplitude (dB)", type = "l", ...)
Q(spec, f = NULL, level = -3, mel = FALSE, plot = TRUE, colval = "red", cexval = 1, fontval = 1, flab = NULL, alab = "Relative amplitude (dB)", type = "l", ...)
spec |
a data set resulting of a spectral analysis obtained
with |
f |
sampling frequency of the wave used to obtain |
level |
frequency bandwidth set by an amplitude value relative
to |
mel |
a logical, if |
plot |
logical, if |
colval |
colour of plotting Q. |
cexval |
character size of plotting Q. |
fontval |
font of plotting Q. |
flab |
title of the frequency axis. |
alab |
title of the amplitude axis. |
type |
if |
... |
other |
A high Q value indicates a highly resonant system.
A list is returned with the following four items:
Q |
a numeric vector of length 1 returning the Q factor (no units) |
dfreq |
a numeric vector of length 1 the dominant frequency (kHz) |
fmin |
a numeric vector of length 1 returning the minimum frequency of the -dB level bandwidth (kHz) |
fmax |
a numeric vector of length 1 returning the minimum frequency of the -dB level bandwidth (kHz) |
bwd |
a numeric vector of length 1 returning the bandwidth,
i. e. |
This function is based on an linear interpolation of the spectrum so that the result should be considered as an estimation, not an exact measure.
Jerome Sueur, improved by Laurent Lellouch
# bird song data(tico) t<-spec(tico,f=22050,at=1.1,plot=FALSE,dB="max0") op<-par(mfrow=c(2,1),las=1) Q(t,type="l") Q(t,type="l",xlim=c(3.8,4.2),ylim=c(-60,0)) title("zoom in") par(op) # cricket, changing the dB level data(pellucens) p<-spec(pellucens,f=11025,at=0.5,plot=FALSE,dB="max0") op<-par(mfrow=c(3,1)) Q(p,type="l",xlim=c(1.8,2.6),ylim=c(-70,0)) title("level = - 3 (default value)",col.main="red") Q(p,type="l",level=-6, xlim=c(1.8,2.6),ylim=c(-70,0),colval="blue") title("level = - 6",col.main="blue") Q(p,type="l",level=-9, xlim=c(1.8,2.6),ylim=c(-70,0),colval="green") title("level = - 9",col.main="green") par(op)
# bird song data(tico) t<-spec(tico,f=22050,at=1.1,plot=FALSE,dB="max0") op<-par(mfrow=c(2,1),las=1) Q(t,type="l") Q(t,type="l",xlim=c(3.8,4.2),ylim=c(-60,0)) title("zoom in") par(op) # cricket, changing the dB level data(pellucens) p<-spec(pellucens,f=11025,at=0.5,plot=FALSE,dB="max0") op<-par(mfrow=c(3,1)) Q(p,type="l",xlim=c(1.8,2.6),ylim=c(-70,0)) title("level = - 3 (default value)",col.main="red") Q(p,type="l",level=-6, xlim=c(1.8,2.6),ylim=c(-70,0),colval="blue") title("level = - 6",col.main="blue") Q(p,type="l",level=-9, xlim=c(1.8,2.6),ylim=c(-70,0),colval="green") title("level = - 9",col.main="green") par(op)
Read audio markers as exported by Audacity.
read.audacity(file, format)
read.audacity(file, format)
file |
A .txt file produced by Audacity when exporting time or time x frequency markers. |
format |
The format of the file name that will appear in the
value, that is in the first column of the data frame returned. if
|
Audacity opens the possibility to annotate sound files with a
marker channel. These markers can be exported as .txt files. The
function read.audacity
import such .txt files whether they
contain time markers or time x frequency markers.
A data.frame
. The size of the data.frame
differs
whether the .txt file contains time markers or time x frequency
markers.
For time markers, the data.frame
contains 4 columns:
file
returning the name of the input file either with
the full path or with the base name only (see argument format
),
label
the text label,
t1
the start time in seconds,
t2
the end time in seconds.
For time x frequency markers, the data.frame
contains 6
columns:
file
returning the name of the input file either with
the full path or with the base name only (see argument format
),
label
the text label,
t1
the start time in seconds,
t2
the end time in seconds,
f1
the lower frequency in Hz,
f2
the upper frequency in Hz.
Jerome Sueur
Audacity is a free software
distributed under the terms of the GNU General Public License.
Web site: https://www.audacityteam.org/
## Not run: ## If 'markers.txt' is an export of Audacity markers x <- read.audacity("markers.txt") ## End(Not run)
## Not run: ## If 'markers.txt' is an export of Audacity markers x <- read.audacity("markers.txt") ## End(Not run)
This function repeats a time wave
repw(wave, f, channel = 1, times = 2, join = FALSE, plot = FALSE, output= "matrix", ...)
repw(wave, f, channel = 1, times = 2, join = FALSE, plot = FALSE, output= "matrix", ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
times |
a numeric of length 1 describing the number of times the wave has to be repeated. |
join |
if |
plot |
logical, if |
output |
character string, the class of the object to return, either
|
... |
other |
If plot
is FALSE
, a new wave is returned. The class
of the returned object is set with the argument output
.
Jerome Sueur [email protected]
oscillo
, addsilw
, cutw
,
deletew
, fadew
, mutew
,
pastew
, revw
, zapsilw
data(tico) repw(tico,f=22050,plot=TRUE) # use 'join' for smooth pasting par(mfrow=c(2,1)) a <- synth(cf=50, f=400, d=0.1) repw(a, f=400, plot=TRUE) title(main="join is FALSE") points(x=0.1, y=0, cex=2, col=2) repw(a, f=400, join=TRUE, plot=TRUE) title(main="join is TRUE") points(x=0.1, y=0, cex=2, col=2)
data(tico) repw(tico,f=22050,plot=TRUE) # use 'join' for smooth pasting par(mfrow=c(2,1)) a <- synth(cf=50, f=400, d=0.1) repw(a, f=400, plot=TRUE) title(main="join is FALSE") points(x=0.1, y=0, cex=2, col=2) repw(a, f=400, join=TRUE, plot=TRUE) title(main="join is TRUE") points(x=0.1, y=0, cex=2, col=2)
This function resamples (down- or over-samples) a time wave. This corresponds to a sampling frequency change.
resamp(wave, f, g, channel = 1, output="matrix")
resamp(wave, f, g, channel = 1, output="matrix")
wave |
an R object. |
f |
sampling frequency of |
g |
new sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
output |
character string, the class of the object to return, either
|
If plot
is FALSE
, a new wave is returned. The class
of the returned object is set with the argument output
.
Resampling might change frequency properties of the time wave.
Jerome Sueur [email protected]
data(peewit) # downsampling a<-resamp(peewit,f=22050,g=11025) # oversampling b<-resamp(peewit,f=22050,g=44100)
data(peewit) # downsampling a<-resamp(peewit,f=22050,g=11025) # oversampling b<-resamp(peewit,f=22050,g=44100)
Reverse the wave along the time axis.
revw(wave, f, channel = 1, env = TRUE, ifreq = TRUE, plot = FALSE, output = "matrix", ...)
revw(wave, f, channel = 1, env = TRUE, ifreq = TRUE, plot = FALSE, output = "matrix", ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
env |
logical, if |
ifreq |
logical, if |
plot |
logical, if |
output |
character string, the class of the object to return, either
|
... |
other |
If plot
is TRUE
returns an oscillogram of the reversed
wave. The amplitude and the instantaneous frequency can be independently reversed
thanks to the arguments env
and ifreq
. See the examples.
If plot
is FALSE
, a new wave is returned. The class
of the returned object is set with the argument output
.
Jerome Sueur [email protected]
Beeman, K. 1998. Digital signal analysis, editing and synthesis in Hopp, S. L., Owren, M. J. and Evans, C. S. (Eds) 1998. Animal acoustic communication, pp. 59-103. Springer, Berlin, Heidelberg.
oscillo
, addsilw
, deletew
,
fadew
, pastew
, mutew
data(tico) # simple reverse revw(tico,f=22050,plot=TRUE) # envelope reverse only revw(tico,f=22050,ifreq=FALSE, plot=TRUE) # instantaneous frequency reverse only revw(tico,f=22050,env=FALSE, plot=TRUE)
data(tico) # simple reverse revw(tico,f=22050,plot=TRUE) # envelope reverse only revw(tico,f=22050,ifreq=FALSE, plot=TRUE) # instantaneous frequency reverse only revw(tico,f=22050,env=FALSE, plot=TRUE)
This functions removes the amplitude modulation of a time wave through the Hilbert amplitude envelope.
rmam(wave, f, channel = 1, plot = FALSE, listen = FALSE, output = "matrix", ...)
rmam(wave, f, channel = 1, plot = FALSE, listen = FALSE, output = "matrix", ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
plot |
logical, if |
listen |
if |
output |
character string, the class of the object to return, either
|
... |
other |
The new time wave is obtained by dividing the original time wave by its Hilbert amplitude envelope.
If plot
is FALSE
, a new wave is returned. The class
of the returned object is set with the argument output
.
Jerome Sueur [email protected]
Mbu Nyamsi, R. G., Aubin, T. & Bremond, J. C. 1994 On the extraction of some time dependent parameters of an acoustic signal by means of the analytic signal concept. Its application to animal sound study. Bioacoustics, 5: 187-203.
# generate a new sound with amplitude modulation a<-synth(f=8000, d=1, cf=1500, am=c(50,10)) # remove the amplitude modulation and plot the result rmam(a,f=8000,plot=TRUE)
# generate a new sound with amplitude modulation a<-synth(f=8000, d=1, cf=1500, am=c(50,10)) # remove the amplitude modulation and plot the result rmam(a,f=8000,plot=TRUE)
This function removes background noise by smoothing
rmnoise(wave, f, channel = 1, output = "matrix", ...)
rmnoise(wave, f, channel = 1, output = "matrix", ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
output |
character string, the class of the object to return, either
|
... |
other |
This function is based on smooth.spline
. You can
use the arguments of the later to modify the smoothing.
A new wave is returned. The class
of the returned object is set with the argument output
.
Low frequency noise might not be removed out properly.
Jerome Sueur [email protected]
# synthesis of a 440 Hz sound with background noise n <- noisew(d=1,f=8000) s <- synth(d=1,f=8000,cf=440) ns <- n+s # remove noise (but low frequency content still there) a <- rmnoise(ns,f=8000)
# synthesis of a 440 Hz sound with background noise n <- noisew(d=1,f=8000) s <- synth(d=1,f=8000,cf=440) ns <- n+s # remove noise (but low frequency content still there) a <- rmnoise(ns,f=8000)
This function removes the offset of a time wave.
rmoffset(wave, f, channel = 1, FUN = mean, plot = FALSE, output = "matrix", ...)
rmoffset(wave, f, channel = 1, FUN = mean, plot = FALSE, output = "matrix", ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
FUN |
a function used to apply the offset correction. See Details. |
plot |
logical, if |
output |
character string, the class of the object to return, either
|
... |
other |
The offset is removed by substracting the wave by its mean
(argument FUN
). But other function can be used. For instance, it
can be more approriate to use the median to remove the
offtset and transients. See Examples.
If plot
is FALSE
, a new wave is returned. The class
of the returned object is set with the argument output
.
Jerome Sueur [email protected]
data(tico) # artifically generates an offset tico2<-tico+0.1 # see the wave with an offset oscillo(tico2, f=22050) # remove the offset with the mean (by default) rmoffset(tico2, f=22050, plot=TRUE) # remove the offset with the median rmoffset(tico2, f=22050, FUN=median, plot=TRUE)
data(tico) # artifically generates an offset tico2<-tico+0.1 # see the wave with an offset oscillo(tico2, f=22050) # remove the offset with the mean (by default) rmoffset(tico2, f=22050, plot=TRUE) # remove the offset with the median rmoffset(tico2, f=22050, FUN=median, plot=TRUE)
This function computes the root mean square or quadratic mean.
rms(x, ...)
rms(x, ...)
x |
an R object |
... |
further arguments passed to mean |
The Root Mean Square or quadratic mean is computed according to:
A numeric vector of length 1
Jerome Sueur [email protected]
# simple rms rms(1:10) # rms of a normalized envelope data(sheep) env <- env(sheep, f=8000) rms(env)
# simple rms rms(1:10) # rms of a normalized envelope data(sheep) env <- env(sheep, f=8000) rms(env)
This function computes the roughness or total curvature of a curve, i.e. of a time wave or of a spectrum
roughness(x, std = FALSE)
roughness(x, std = FALSE)
x |
a vector |
std |
a logical, if set to |
Roughness or total curvature is the integrated squared second
derivative :
.
A vector of length 1.
The value has not unit.
Jerome Sueur
Ramsay JO, Silverman BW (2005) Functional data analysis. Springer, Berlin.
data(tico) spec <- meanspec(tico, plot=FALSE)[,2] roughness(spec)
data(tico) spec <- meanspec(tico, plot=FALSE)[,2] roughness(spec)
This function computes the rugosity of a time wave or time series
rugo(x, ...)
rugo(x, ...)
x |
a vector |
... |
other |
The formula has been slightly modified from Mezquida & Martinez (2009:
826) to fit with the classical definition of the root-mean-square
(see rms
).
The rugosity is then computed as following:
for a vector x
of length n.
A vector of length 1.
The rugosity of a noisy signal will tend to be higher than that of
a pure tone signal, all other things being equal.
Jerome Sueur
Mezquida DA, Martinez JL (2009) - Platform for bee-hives monitoring based on sound analysis. A perpetual warehouse for swarm's daily activity. Spanish Journal of Agricultural Research 7, 824-828.
data(tico) ; tico <-tico@left # rugosity of the original recording normalised rugo(tico/max(tico)) # synthesis of white noise with the same duration as tico noise <- noisew(d=length(tico)/22050, f=22050) # tico is normalised to get similar amplitude with the noise tico.norm <- tico/max(tico) # addition of noise to tico tico.noisy <- tico.norm + 0.5*noise # new rugosity (higher) on normalised signal rugo(tico.noisy/max(tico.noisy))
data(tico) ; tico <-tico@left # rugosity of the original recording normalised rugo(tico/max(tico)) # synthesis of white noise with the same duration as tico noise <- noisew(d=length(tico)/22050, f=22050) # tico is normalised to get similar amplitude with the noise tico.norm <- tico/max(tico) # addition of noise to tico tico.noisy <- tico.norm + 0.5*noise # new rugosity (higher) on normalised signal rugo(tico.noisy/max(tico.noisy))
Save sound data as .wav file
savewav(wave, f, channel = 1, filename = NULL, rescale = NULL, ...)
savewav(wave, f, channel = 1, filename = NULL, rescale = NULL, ...)
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
filename |
name of the new file. (by default the name of
|
rescale |
a numeric vector of length 2 giving the lower (negative value) and upper (positive value) amplitude limits of the .wav file to be exported. |
... |
other arguments to be passed to |
.
This function uses three functions from the package tuneR:
Wave
, normalize
and writeWave
.
The file automatically owerwrites an existing file
with the same name.
The amplitude (volume) of the .wav file is normalized by defaults but can be changed with the argument
rescale
. See examples
Jerome Sueur [email protected], Ethan C. Brown for the argument 'rescale'
require(tuneR) a<-synth(f=8000,d=2,cf=2000,plot=FALSE) # the name of the file is automatically the name of the object # here: "a.wav" savewav(a,f=22050) unlink("a.wav") # if you wish to change the name, use the 'file' argument savewav(a,f=22050,file="b.wav") unlink("b.wav") # if you wish to change the amplitude of the file, use the argument 'rescale' # this will turn down the volume of a 16 bit sound # which amplitude was originally ranging between -2^15 and +2^15 savewav(a, f=22050, file="c.wav", rescale=c(-1500,1500)) unlink("c.wav")
require(tuneR) a<-synth(f=8000,d=2,cf=2000,plot=FALSE) # the name of the file is automatically the name of the object # here: "a.wav" savewav(a,f=22050) unlink("a.wav") # if you wish to change the name, use the 'file' argument savewav(a,f=22050,file="b.wav") unlink("b.wav") # if you wish to change the amplitude of the file, use the argument 'rescale' # this will turn down the volume of a 16 bit sound # which amplitude was originally ranging between -2^15 and +2^15 savewav(a, f=22050, file="c.wav", rescale=c(-1500,1500)) unlink("c.wav")
This function converts a numeric times seris into a series of letters with a specific length and alphabet.
SAX(x, alphabet_size, PAA_number, breakpoints = "gaussian", collapse = NULL)
SAX(x, alphabet_size, PAA_number, breakpoints = "gaussian", collapse = NULL)
x |
a numeric vector. |
alphabet_size |
a numeric vector of length 1 setting the size of the alphabet. |
PAA_number |
a numeric vector of length 1 setting the number of elements (subsequences) of the Piecewise Aggregate Approximation (PAA). |
breakpoints |
either a character vector ("gaussian", "quantiles")
or a numeric vector specifying the sorted values of the breakpoints
along the distribution of |
collapse |
a character vector of length 1, specifying the way to
collapse the output letters, see |
The SAX method has been developed to reduce the dimensionality of a numerical series into a short chain of characters. SAX follows a two-step process: (1) Piecewise Aggregate Approximation (PAA) and (2) conversion a PAA sequence into a series of letters.
PAA consists in a Z-normalisation, a segmentation of the series of
length n into w segments, and the computation of each segment average.
The conversion of the PAA into a series of letters is achieved by attributing with
equiprobability each value of the PAA to a letter in reference to a
Gaussian distribution. This process therefore assumes that the
distribution of the numeric series x
follows a Gaussian
distribution. To relax the constraints of normality we here added the possibility to directly work
on the quantiles of the original data distribution or to specify particular breakpoints along the
distribution of x
. See the examples.
A character vector of length (when collapse
is
NULL
) or number of character (when collapse
is
not NULL
) corresponding to PAA_number
argument.
SAX has been used recently to search similar times series in a soundcape data base (Kasten et al., 2012).
Laurent Lellouch. An improvement added by Pavel Senin.
Kasten, E.P., Gage, S.H., Fox, J. & Joo, W. (2012). The remote environmental assessment laboratory's acoustic library: an archive for studying soundscape ecology. Ecological Informatics, 12, 50 - 67.
Lin, J., Keogh, E., Lonardi, S., Chiu, B., June (2003). A symbolic representation of time series with implications for streaming algorithms. Proceedings of the 8th ACM SIGMOD Workshop on Research Issues in Data Mining and Knowledge Discovery. San Diego, California, USA.
discrets
, symba
, soundscapespec
data(tico) spec <- soundscapespec(tico, plot=FALSE)[,2] SAX(spec, alphabet = 5, PAA = 10) # change breakpoints SAX(spec, alphabet = 5, PAA = 10, breakpoints="quantiles") SAX(spec, alphabet = 5, PAA = 10, breakpoints=c(0, 0.5, 0.75, 1)) SAX(spec, alphabet = 5, PAA = 10, breakpoints=c(0, 0.33, 0.66, 1)) # different output formats SAX(spec, alphabet = 5, PAA = 10, collapse="") SAX(spec, alphabet = 5, PAA = 10, collapse="-")
data(tico) spec <- soundscapespec(tico, plot=FALSE)[,2] SAX(spec, alphabet = 5, PAA = 10) # change breakpoints SAX(spec, alphabet = 5, PAA = 10, breakpoints="quantiles") SAX(spec, alphabet = 5, PAA = 10, breakpoints=c(0, 0.5, 0.75, 1)) SAX(spec, alphabet = 5, PAA = 10, breakpoints=c(0, 0.33, 0.66, 1)) # different output formats SAX(spec, alphabet = 5, PAA = 10, collapse="") SAX(spec, alphabet = 5, PAA = 10, collapse="-")
Computes and displays a chord diagram of a set of audio files or of a set segments extracted from a single audio file.
scd(input, f, sl, wl = 512, wn = "hanning", ovlp = 0, flim = NULL, rmoffset = TRUE, threshold = NULL, HCA = TRUE, grid.col = terrain.colors, names, plot = TRUE, verbose = TRUE, ...)
scd(input, f, sl, wl = 512, wn = "hanning", ovlp = 0, flim = NULL, rmoffset = TRUE, threshold = NULL, HCA = TRUE, grid.col = terrain.colors, names, plot = TRUE, verbose = TRUE, ...)
input |
a character vector, either (i) the path to the directory where
.wav files are stored, (ii) directly the names of the .wav files to be
processed, or (iii) a single .wav file to be segmented by the
duration set with the argument |
f |
sampling frequency of |
sl |
segment length in duration if |
wl |
window length for the analysis spectral (even number of points) (by default = 512). |
wn |
window name for the spectral analysis, see
|
ovlp |
overlap between two successive windows (in %) for the spectral analysis. |
flim |
a numeric vector of length 2 to select a frequency band (in kHz). |
rmoffset |
a logical to sepcify whether DC offset should be
removed. By default |
threshold |
a numeric value in ]0,1[ to be applied to the similarity distance. All similairty distances below this threshold will not depicted. |
HCA |
logical, if |
grid.col |
name of color palette to color the sectors and
the links). By default |
names |
names of the sectors, if empty then the names of the .wav files or the time stamps of the segments. |
plot |
logical, if |
verbose |
logical, if |
... |
other |
The soundscape chord diagram (SCD) aims at representing similarities
between audio files or audio segments extracted from a single audio file. The
mean frequency spectrum of each file/segment is computed using a
STFT. These frequency spectra are then (1) pairwised compared using a
similarity distance (see function diffcumspec
, and (2)
automatically clustered with a hierarchical cluster analysis (HCA) (see function
HCPC
of FactoMiner
). The
resulting similarity matrix is then given as an input to the function
chordDiagram
. The width of the sectors and the links are
based on the spectral similarity matrix. The color of the sectors and the links
follow the HCA classification.
THe function returns a list of two items:
m |
spectral similarity matrix |
resHCA |
the classification result of the HCA, if |
The function call the function HCPC
of the package
FactoMineR
and the function chordDiagram
of the
package circlize
.
Adèle de Baudouin, Jérôme Sueur
de Baudouin, A, Couprie P, Michaud F, Haupert S, Sueur J – Similarity visualization of nature and music soundscapes, in prep.
## Not run: ## 1 ## # if 'dir' contains a set of files recorded with a Wildlife Acoustics # songmeter recorder or an Audiomoth then a direct way to obtain # the soundscape chord diagram (SCD) of all .wav files is dir <- "pathway-to-directory-containing-wav-files" scd(dir) # to change the STFT parameters used to obtain each mean spectrum lts(dir, wl=1024, wn="hamming", ovlp=50) # to select only high similarities, here above 0.6 scd(dir, threshold=0.6) # to change the colors scd(dir, grid.col=colorRampPalette(c("darkblue", "yellow", "grey"))) # to name manually the sectors scd(dir, names=as.character(0:23)) # to name automatically the sectors from the name of songmeter files # here according to hour of recording scd(dir, names=as.character(songmeter(files)$hour)) ## 2 ## # to directly use files names stored in the working directory files <- c("S4A09154_20190213_150000.wav", "S4A09154_20190213_153000.wav", "S4A09154_20190213_160000.wav", "S4A09154_20190213_163000.wav", "S4A09154_20190213_170000.wav", "S4A09154_20190213_173000.wav", "S4A09154_20190213_180000.wav", "S4A09154_20190213_183000.wav", "S4A09154_20190213_190000.wav", "S4A09154_20190213_193000.wav") scd(files) ## 3 ## # to use of single files which is segmented in successive time segments # lasting each 60 s file <- "a-very-nice-soundscape.wav") scd(file, sl = 60) ## End(Not run)
## Not run: ## 1 ## # if 'dir' contains a set of files recorded with a Wildlife Acoustics # songmeter recorder or an Audiomoth then a direct way to obtain # the soundscape chord diagram (SCD) of all .wav files is dir <- "pathway-to-directory-containing-wav-files" scd(dir) # to change the STFT parameters used to obtain each mean spectrum lts(dir, wl=1024, wn="hamming", ovlp=50) # to select only high similarities, here above 0.6 scd(dir, threshold=0.6) # to change the colors scd(dir, grid.col=colorRampPalette(c("darkblue", "yellow", "grey"))) # to name manually the sectors scd(dir, names=as.character(0:23)) # to name automatically the sectors from the name of songmeter files # here according to hour of recording scd(dir, names=as.character(songmeter(files)$hour)) ## 2 ## # to directly use files names stored in the working directory files <- c("S4A09154_20190213_150000.wav", "S4A09154_20190213_153000.wav", "S4A09154_20190213_160000.wav", "S4A09154_20190213_163000.wav", "S4A09154_20190213_170000.wav", "S4A09154_20190213_173000.wav", "S4A09154_20190213_180000.wav", "S4A09154_20190213_183000.wav", "S4A09154_20190213_190000.wav", "S4A09154_20190213_193000.wav") scd(files) ## 3 ## # to use of single files which is segmented in successive time segments # lasting each 60 s file <- "a-very-nice-soundscape.wav") scd(file, sl = 60) ## End(Not run)
This function estimates the standard deviation of dB values
sddB(x, level = "IL")
sddB(x, level = "IL")
x |
a numeric vector. |
level |
intensity level ( |
The standard deviation of dB values is not linear. The function is an estimation not an exact computation which is not possible.
A numeric vector of length 1.
Jérôme Sueur
Wikipedia, https://en.wikipedia.org/wiki/Propagation_of_uncertainty
meandB
, moredB
,
convSPL
, dBweight
sddB(c(89,90,95)) sddB(c(89,90,95), level="SPL")
sddB(c(89,90,95)) sddB(c(89,90,95), level="SPL")
See quantitative data at a glance
seedata(data, na.rm = FALSE, col = "grey")
seedata(data, na.rm = FALSE, col = "grey")
data |
a numeric vector describing quantitative data. |
na.rm |
logical, if |
col |
main color. |
The red curves depict the corresponding Normal law (same mean and sd as data
).
A multi-plot graphic is returned.
Caroline Simonis [email protected] and Jerome Sueur [email protected].
seedata(rnorm(1000))
seedata(rnorm(1000))
seewave provides functions for analysing, manipulating, displaying, editing and synthesizing time waves (particularly sound). This package processes in particular time analysis (oscillograms and envelopes), spectral content, resonance quality factor, entropy, cross correlation and autocorrelation, zero-crossing, frequency coherence, dominant frequency, analytic signal, 2D and 3D spectrograms.
Package: | seewave |
Type: | Package |
Version: | 2.2.3 |
Date: | 2023-10-15 |
License: | GPL version 2 or newer |
Contributors : | Pierre Aumond, Ethan C. Brown, |
Adèle de Baudouin, | |
Guillaume Corbeau, Camille Desjonqueres, | |
Marion Depraetere, Francois Fabianek, | |
Amandine Gasc, Sylvain Haupert, | |
Eric Kasten, Laurent Lellouch, | |
Stefanie LaZerte, Jonathan Lees, | |
Jean Marchal, Thibaut Marin-Cudraz, | |
Andre Mikulec, Sandrine Pavoine, | |
David Pinaud, Luis J. Villanueva-Rivera | |
Zev Ross, Carl G. Witthoft, | |
Hristo Zhivomirov | |
Acknowledgments: | Marianna Anichini, Andrey Anikin, Michel Baylac, |
Charlotte Cure, Denis Dupeyron, | |
Kurt Fristrup, Arnold Fertin, | |
Sylvain Haupert, Kurt Hornik, | |
Yannick Jadoul, Emiliano A. Laca, | |
Uwe Ligges, Duncan Murdoch, Morgane Papin, | |
Emmanuel Paradis, Daniel Ridley-Ellis, | |
Brian Ripley, Jesse Ross, | |
Zev Ross, Pavel Senin, David Savage, | |
Arvind Sowmyan, Simon Urbanek | |
Maria A. Wis, George Zhang | |
Webpage: | https://rug.mnhn.fr/seewave/ |
Discussion group : | https://groups.google.com/g/seewave |
Source reference: | Sueur J, Aubin T, Simonis C (2008) - seewave: a free modular tool for sound analysis and synthesis. |
Bioacoustics, 18: 213-226. | |
Book: | Sueur J (2018) - Sound analysis and synthesis with R. Springer. |
Jerome Sueur <[email protected]>
Thierry Aubin
Caroline Simonis
Maintainer: Jerome Sueur <[email protected]>
This function sets the amplitude envelope of a time wave to another one
setenv(wave1, wave2, f, channel = c(1,1), envt="hil", msmooth = NULL, ksmooth = NULL, plot = FALSE, listen = FALSE, output = "matrix", ...)
setenv(wave1, wave2, f, channel = c(1,1), envt="hil", msmooth = NULL, ksmooth = NULL, plot = FALSE, listen = FALSE, output = "matrix", ...)
wave1 |
a first R object. |
wave2 |
a second R object. |
f |
sampling frequency of |
channel |
channel of the R objects, by default left channel (1) for each object. |
envt |
the type of envelope to be used for |
msmooth |
a vector of length 2 to smooth the amplitude envelope of |
ksmooth |
kernel smooth via |
plot |
if |
listen |
if |
output |
character string, the class of the object to return, either
|
... |
other |
wave1
and wave2
can have different duration (length)
Smoothing the envelope with smooth
or ksmooth
can significantly
change the value returned.
If plot
is FALSE
, a new wave is returned. The class
of the returned object is set with the argument output
.
Jerome Sueur [email protected]
data(tico) a<-synth(d=1,f=22050,cf=1000) # apply 'tico' ammplitude envelope to 'a' that has a square amplitude envelope setenv(a,tico,f=22050,plot=TRUE) # the same but with smoothing the envelope setenv(a,tico,f=22050,ksmooth=kernel("daniell",50),plot=TRUE)
data(tico) a<-synth(d=1,f=22050,cf=1000) # apply 'tico' ammplitude envelope to 'a' that has a square amplitude envelope setenv(a,tico,f=22050,plot=TRUE) # the same but with smoothing the envelope setenv(a,tico,f=22050,ksmooth=kernel("daniell",50),plot=TRUE)
This function estimates the flatness of a frequency spectrum.
sfm(spec)
sfm(spec)
spec |
a data set resulting of a spectral analysis obtained
with |
SFM is calculated as the ratio between the geometric mean and the
arithmetic mean :
with:
y = relative amplitude of the i frequency,
and N = number of frequencies.
A single value varying between 0 and 1 is returned. The value has no unit.
The SFM of a noisy signal will tend towards 1 whereas
the SFM of a pure tone signal will tend towards 0.
See sh
for another measure of signal noisiness/pureness.
Jerome Sueur [email protected]
a<-synth(f=8000,d=1,cf=2000,plot=FALSE) speca<-spec(a,f=8000,at=0.5,plot=FALSE) sfm(speca) # [1] 0 b<-noisew(d=1,f=8000) specb<-spec(b,f=8000,at=0.5,plot=FALSE) sfm(specb) # [1] 0.8233202
a<-synth(f=8000,d=1,cf=2000,plot=FALSE) speca<-spec(a,f=8000,at=0.5,plot=FALSE) sfm(speca) # [1] 0 b<-noisew(d=1,f=8000) specb<-spec(b,f=8000,at=0.5,plot=FALSE) sfm(specb) # [1] 0.8233202
This function computes the Shannon or Renyi entropy of a frequency spectrum
sh(spec, alpha = "shannon")
sh(spec, alpha = "shannon")
spec |
a data set resulting of a spectral analysis obtained
with |
alpha |
a character string, by default |
. Shannon spectral entropy is calculated according to:
. Simpson or Gini-Simpson spectral entropy (or index) is computed according to:
. Renyi spectral entropy of order alpha is calucalted according to:
with
y = relative amplitude of the i frequency,
and N = number of frequencies.
A numeric vector of length 1 is returned. The value has no unit.
The Shannon entropy scaled between 0 and 1 is also known as Pielou's evenness index
The Shannon spectral entropy of a noisy signal will tend towards 1 whereas the Shannon spectral entropy of a pure tone signal will tend towards 0. See Han et al. for details regarding the Renyi entropy.
Jerome Sueur and Laurent Lellouch
Han, NC, Muniandy SV, Dayou J (2011) Acoustic classification of
Australian anurans based on hybrid spectral-entropy approach. Applied
Acoustics.
Nunes RR, Almeida de MP, Sleigh JW (2004) -
Spectral entropy: a new method for anesthetic adequacy.
Revista Brasileira de Anestesiologia, 54, 413-422.
Renyi A (1961) - On measures of information and entropy. Proceedings
of the 4th Berkeley Symposium on Mathematics, Statistics and
Probability 1960. pp. 547-561.
Simpson EH (1949) - Measurement of diversity. Nature, 163, 688.
a<-synth(f=8000,d=1,cf=2000,plot=FALSE) speca<-spec(a,f=8000,at=0.5,plot=FALSE) ## Shannon spectral entropy sh(speca) # [1] 0.2336412 b<-noisew(d=1,f=8000) specb<-spec(b,f=8000,at=0.5,plot=FALSE) sh(specb) # close to 1 ## Renyi spectral entropy sh(speca, alpha=2) sh(speca, alpha=3)
a<-synth(f=8000,d=1,cf=2000,plot=FALSE) speca<-spec(a,f=8000,at=0.5,plot=FALSE) ## Shannon spectral entropy sh(speca) # [1] 0.2336412 b<-noisew(d=1,f=8000) specb<-spec(b,f=8000,at=0.5,plot=FALSE) sh(specb) # close to 1 ## Renyi spectral entropy sh(speca, alpha=2) sh(speca, alpha=3)
Recording of a sheep bleat.
data(sheep)
data(sheep)
A Wave object.
Duration = 2.47 s. Sampling frequency = 8000 hz.
Recording by Frederic Sebe.
data(sheep) oscillo(sheep,f=8000)
data(sheep) oscillo(sheep,f=8000)
This function estimates the similarity between two frequency spectra.
simspec(spec1, spec2, f = NULL, mel = FALSE, norm = FALSE, PMF = FALSE, plot = FALSE, type = "l", lty =c(1, 2, 3), col = c(2, 4, 1), flab = NULL, alab = "Amplitude (percentage)", flim = NULL, alim = NULL, title = TRUE, legend = TRUE, ...)
simspec(spec1, spec2, f = NULL, mel = FALSE, norm = FALSE, PMF = FALSE, plot = FALSE, type = "l", lty =c(1, 2, 3), col = c(2, 4, 1), flab = NULL, alab = "Amplitude (percentage)", flim = NULL, alim = NULL, title = TRUE, legend = TRUE, ...)
spec1 |
a first data set resulting of a spectral analysis obtained
with |
spec2 |
a first data set resulting of a spectral analysis obtained
with |
f |
sampling frequency of waves used to obtain |
mel |
a logical, if |
norm |
a logical, if |
PMF |
a logical, if |
plot |
logical, if |
type |
if |
lty |
a vector of length 3 for the line type of |
col |
a vector of length 3 for the colour of |
flab |
title of the frequency axis. |
alab |
title of the amplitude axis. |
flim |
the range of frequency values. |
alim |
range of amplitude axis. |
title |
logical, if |
legend |
logical, if |
... |
other |
Spectra similarity is assessed according to:
with S in %.
The similarity index is returned. This value is in %.
When plot
is TRUE
, both spectra and the similarity function are
plotted on the same graph. The similarity index is the mean of this function.
Jerome Sueur, improved by Laurent Lellouch
Deecke, V. B. and Janik, V. M. 2006. Automated categorization of bioacoustic signals: avoiding perceptual pitfalls. Journal of the Acoustical Society of America, 119: 645-653.
spec
, meanspec
, corspec
,
diffspec
, diffenv
, kl.dist
,
ks.dist
, logspec.dist
, itakura.dist
a<-noisew(f=8000,d=1) b<-synth(f=8000,d=1,cf=2000) c<-synth(f=8000,d=1,cf=1000) d<-noisew(f=8000,d=1) speca<-spec(a,f=8000,at=0.5,plot=FALSE) specb<-spec(b,f=8000,at=0.5,plot=FALSE) specc<-spec(c,f=8000,at=0.5,plot=FALSE) specd<-spec(d,f=8000,at=0.5,plot=FALSE) simspec(speca,speca) simspec(speca,specb) simspec(speca,specc,plot=TRUE) simspec(specb,specc,plot=TRUE) #[1] 12.05652 simspec(speca,specd,plot=TRUE) ## mel scale require(tuneR) data(orni) data(tico) orni.mel <- melfcc(orni, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) orni.mel.mean <- apply(orni.mel$aspectrum, MARGIN=2, FUN=mean) tico.mel <- melfcc(tico, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) tico.mel.mean <- apply(tico.mel$aspectrum, MARGIN=2, FUN=mean) simspec(orni.mel.mean, tico.mel.mean, f=22050, mel=TRUE, plot=TRUE)
a<-noisew(f=8000,d=1) b<-synth(f=8000,d=1,cf=2000) c<-synth(f=8000,d=1,cf=1000) d<-noisew(f=8000,d=1) speca<-spec(a,f=8000,at=0.5,plot=FALSE) specb<-spec(b,f=8000,at=0.5,plot=FALSE) specc<-spec(c,f=8000,at=0.5,plot=FALSE) specd<-spec(d,f=8000,at=0.5,plot=FALSE) simspec(speca,speca) simspec(speca,specb) simspec(speca,specc,plot=TRUE) simspec(specb,specc,plot=TRUE) #[1] 12.05652 simspec(speca,specd,plot=TRUE) ## mel scale require(tuneR) data(orni) data(tico) orni.mel <- melfcc(orni, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) orni.mel.mean <- apply(orni.mel$aspectrum, MARGIN=2, FUN=mean) tico.mel <- melfcc(tico, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE) tico.mel.mean <- apply(tico.mel$aspectrum, MARGIN=2, FUN=mean) simspec(orni.mel.mean, tico.mel.mean, f=22050, mel=TRUE, plot=TRUE)
This function tries to smooth with a sum sliding window a time wave, and then to remove residual noise.
smoothw(wave, f, channel = 1, wl, padding=TRUE, output = "matrix")
smoothw(wave, f, channel = 1, wl, padding=TRUE, output = "matrix")
wave |
an R object. |
f |
sampling frequency of |
channel |
channel of the R object, by default left channel (1). |
wl |
window length in number of points (samples). |
padding |
a logical, if |
output |
character string, the class of the object to return,
either |
A window slides along the signal and sums up the sample amplitude values. Zero values are added at the end of the wave to keep wave length (duration).
A new wave is returned. The class of the returned object is set
with the argument output
. If padding
is TRUE
, the
new wave starts and ends up with 0
values to match the size of wave
.
This function should be used with care as this kind of filter may change the frequency content of the sound. See the examples section for an illustration.
Jerome Sueur
# An example to show that smoothw() may change # the frequency content of your sound data(orni) orni2 <- smoothw(orni, wl=2, out="Wave") orni10 <- smoothw(orni, wl=10, out="Wave") orni50 <- smoothw(orni, wl=50, out="Wave") orni100 <- smoothw(orni, wl=100, out="Wave") meanspec(orni) lines(meanspec(orni2, plot=FALSE), col=2) lines(meanspec(orni10, plot=FALSE), col=3) lines(meanspec(orni50, plot=FALSE), col=4) lines(meanspec(orni100, plot=FALSE), col=5) legend("topright", col=1:5, lty=1, legend=c("original","wl=2","wl=10","wl=50","wl=100"))
# An example to show that smoothw() may change # the frequency content of your sound data(orni) orni2 <- smoothw(orni, wl=2, out="Wave") orni10 <- smoothw(orni, wl=10, out="Wave") orni50 <- smoothw(orni, wl=50, out="Wave") orni100 <- smoothw(orni, wl=100, out="Wave") meanspec(orni) lines(meanspec(orni2, plot=FALSE), col=2) lines(meanspec(orni10, plot=FALSE