Learn R Programming

seewave (version 1.4.3)

spectro: 2D-spectrogram of a time wave

Description

This function returns a two-dimension spectrographic representation of a time wave. The function corresponds to short-term Fourier transform. An amplitude contour plot can be overlaid.

Usage

spectro(wave, f, wl = 512, wn = "hanning", zp = 0, ovlp = 0, plot = TRUE,
grid = TRUE, osc = FALSE, scale = TRUE, cont = FALSE,
collevels = seq(-30, 0, 1), palette = spectro.colors,
contlevels = seq(-30, 0, 10), colcont = "black", colgrid = "black",
colaxis = "black", collab="black",
plot.title = title(main = "", xlab = "Time (s)", 
ylab = "Frequency (kHz)"), scalelab = "Amplitude
(dB)",
scalefontlab = 1, scalecexlab =0.75, axisX = TRUE, axisY = TRUE, tlim = NULL,
flim = NULL, flimd = NULL, play=FALSE,
...)

Arguments

wave
data describing a time wave or a Sample object generated loading a wav file with loadSample (package Sound).
f
sampling frequency of wave (in Hz). Does not need to be specified if wave is a Sample object.
wl
window length for the analysis (even number of points). (by default = 512)
zp
zero-padding (even number of points), see Details.
ovlp
overlap between two successive windows (in %).
wn
window name, see ftwindow (by default "hanning").
plot
logical, if TRUE plots the spectrogram (by default TRUE).
grid
logical, if TRUE plots a y-axis grid (by default TRUE).
osc
logical, if TRUE plots an oscillogram beneath the spectrogram (by default FALSE).
scale
logical, if TRUE plots a dB colour scale on the right side of the spectrogram (by default TRUE).
cont
logical, if TRUE overplots contour lines on the spectrogram (by default FALSE).
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 Details.
contlevels
a set of levels which are used to partition the amplitude range for contour overplot (in dB).
colcont
colour for cont plotting.
colgrid
colour for grid plotting.
colaxis
color of the axes.
collab
color of the labels.
plot.title
statements which add titles to the plot.
scalelab
amplitude scale label.
scalefontlab
font of the amplitude scale label.
scalecexlab
cex of the amplitude scale label.
axisX
logical, if TRUE plots time X-axis (by default TRUE).
axisY
logical, if TRUE plots frequency Y-axis (by default TRUE).
tlim
modifications of the time X-axis limits.
flim
modifications of the frequency Y-axis limits.
flimd
dynamic modifications of the frequency Y-axis limits. New wl and ovlp arguments are applied to increase time/frequency resolution.
play
if TRUE the new sound is played back using play from the package Sound (by default FALSE).
...
other contour and oscillo graphical parameters.

Value

  • If plot is FALSE, this function returns a matrix. Each column corresponds to a Fourier transform of length wl.

Details

Following Heisenberg uncertainty principle, the short-term Fourier transform cannot be precised in both time and frequency. The temporal and frequency precisions of the function are actually dependent of the wl value. Choosing a high wl value will increase the frequency resolution but reduce the temporal one, and vice versa. The frequency precision is obtained by calculating the ratio f/wl, and the temporal precision is obtained by calculating the reverse ratio wl/f. This problem can be reduced in some way with zp that adds 0 values on both sides of the analysis window. This increases frequency resolution without altering time resolution. 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. Use locator to identify points.

References

Hopp, S. L., Owren, M. J. and Evans, C. S. (Eds) 1998. Animal acoustic communication. Springer, Berlin, Heidelberg.

See Also

spectro3D, oscillo, dBscale, fft.

Examples

Run this code
data(tico)
data(peewit)
data(pellucens)
data(alauda)
# simple plots
spectro(tico,f=22050)
spectro(tico,f=22050,osc=TRUE)
spectro(tico,f=22050,scale=FALSE)
spectro(tico,f=22050,osc=TRUE, scale=FALSE)
# manipulating wl
op<-par(mfrow=c(2,2))
spectro(tico,f=22050,wl=256,scale=FALSE)
title("wl = 256")
spectro(tico,f=22050,wl=512,scale=FALSE)
title("wl = 512")
spectro(tico,f=22050,wl=1024,scale=FALSE)
title("wl = 1024")
spectro(tico,f=22050,wl=4096,scale=FALSE)
title("wl = 4096")
par(op)
# manipulating ovlp
op<-par(mfrow=c(2,1))
spectro(alauda,f=22050,scale=FALSE)
title("ovlp = 0")
spectro(alauda,f=22050,ovlp=95,scale=FALSE)
title("ovlp = 95")
par(op)
# vertical zoom using flim
spectro(tico,f=22050, ylim=c(2,6))
spectro(tico,f=22050, ylimd=c(2,6))
# a full plot
pellu2<-cutw(pellucens,f=22050,from=1,plot=FALSE)
spectro(pellu2,f=22050,ovlp=85,zp=16,osc=TRUE,
    cont=TRUE,contlevels=seq(-30,0,20),colcont="red",
    lwd=1.5,lty=2,palette=rev.terrain.colors)
# black and white spectrogram 
spectro(pellu2,f=22050,ovlp=85,zp=16,
    palette=rev.gray.colors.1)
# colour modifications
spectro(pellu2,f=22050,ovlp=85,zp=16,
palette=rev.cm.colors,osc=TRUE,colwave="orchid1") 
op<-par(bg="black",col="white")
spectro(pellu2,f=22050,ovlp=85,zp=16,osc=TRUE,palette=rev.heat.colors,
colgrid="white", colwave="white",colaxis="white",collab="white")
par(op)

Run the code above in your browser using DataLab