Learn R Programming

seewave (version 2.1.0)

stft.ext: Short-term Fourier transform using fftw and libsndfile C libraries

Description

This function performs the short-term Fourier transform externally, i. e. outside R, on an audio .wav file

Usage

stft.ext(file, wl = 512, ovlp = 0, mean = FALSE,
norm = FALSE, dB = FALSE, verbose = FALSE)

Arguments

file

a character string vector of length 1, corresponding to the audio file name. Only .wav files are supported.

wl

a numeric vector of length 1, window length for the analysis (even number of points) (by default = 512).

ovlp

a numeric vector of length 1, overlap between two successive windows (in %).

mean

logical, if TRUE calculates the mean spectrum.

norm

logical, if TRUE the spectrogram matrix and the mean spectrum if mean is TRUE is/are normalized to a maximum of 1.

dB

logical, if TRUE the values are in deciBel with a maximum of 0.

verbose

logical, if TRUE displays audio file meta-information.

Value

If mean is FALSE, the function returns a two-column matrix corresponding to the amplitude values of the spectrogram. Each column is a discrete Fourier transform of length wl.

If mean is TRUE, the function returns a list with two elements:

mean

a vector of length wl/2 corresponding to the mean spectrum

amp

the spectrogram matrix.

See Also

spectro, meanspec, fft.

Examples

Run this code
# NOT RUN {
# tico data
data(tico)
# write a local .wav file
savewav(tico, file="tico.wav")
# spectrogram - not normalised - linear scale - meta-information returned
res <- stft.ext(file="tico.wav", verbose=TRUE)
# spectrogram - normalised - linear scale - no meta-information
res <- stft.ext(file="tico.wav", norm=TRUE)
# spectrogram - dB scale - no meta-information
res <- stft.ext(file="tico.wav", dB=TRUE)
# see how it looks like (no scale)
filled.contour(t(res))
# spectrogram and mean spectrum - normalised - linear scale
res <- stft.ext(file="tico.wav", norm = TRUE, mean = TRUE)
# remove .wav file
unlink("tico.wav")
# }

Run the code above in your browser using DataLab