lpsSpectrum: Calculate Linear Prediction smoothed spectrum

View source: R/wrassp_lpsSpectrum.R

lpsSpectrumR Documentation

Calculate Linear Prediction smoothed spectrum

Description

Short-term spectral analysis of the signal in listOfFiles using the Fast Fourier Transform and linear predictive smoothing.

Usage

lpsSpectrum(
  listOfFiles = NULL,
  optLogFilePath = NULL,
  beginTime = 0,
  centerTime = FALSE,
  endTime = 0,
  resolution = 40,
  fftLength = 0,
  windowSize = 20,
  windowShift = 5,
  window = "BLACKMAN",
  order = 0,
  preemphasis = -0.95,
  deemphasize = TRUE,
  toFile = TRUE,
  explicitExt = "lps",
  outputDirectory = NULL,
  assertLossless = NULL,
  logToFile = FALSE,
  keepConverted = FALSE,
  verbose = TRUE
)

Arguments

listOfFiles

vector of file paths to be processed by function

beginTime

the time point (in seconds) of the start of the analysed interval. A NULL or 0 is interpreted as the start of the signal file. If a vector of time points is supplied, the length of that vector needs to correspond with the length of listOfFiles.

centerTime

sets a single-frame analysis time point (in seconds). Overrides beginTime, endTime and windowShift parameters.

endTime

the time point (in seconds) of the end of the analysed interval. A NULL or 0 is interpreted as the end of the signal file. If a vector of time points is supplied, the length of that vector needs to correspond with the length of listOfFiles.

resolution

= : set FFT length to the smallest value which results in a frequency resolution of Hz or better (default: 40.0)

fftLength

= : set FFT length to points (overrules default and 'resolution' option)

windowShift

the amount of time (in ms) that the analysis window will be shifted between analysis frames

window

= the analysis window function type ("BLACKMAN" by default). See AsspWindowTypes for a list of supported window types.

order

= : set prediction order to (default: sampling rate in kHz + 3)

preemphasis

= : set pre-emphasis factor to (default: -0.95)

deemphasize

(default: undo spectral tilt due to pre-emphasis used in LP analysis, i.e. TRUE)

toFile

Should the function write the results to a file, with the (default) file extension (TRUE) or returned as a list of AsspDataObj objects (FALSE)?

explicitExt

the file extension will be used when result files are written (toFile=TRUE), but the file extension can be set to something else using this function argument.

outputDirectory

directory in which output files are stored. Defaults to NULL which means that the result file will be stored in the same directory as the input file.

assertLossless

an optional list of file extensions that the user wants to assert contains losslessly encoded signals data.

logToFile

whether to log commands to a separate logfile in the outputDirectory. Logging will otherwise be in the function-specific logging namespace of logger and will be put wherever this namespace is defined to place its output. See logger::log_appender for details.

verbose

display verbose information about processing steps taken, as well as progress bars.

Details

The results will be will be written to an SSFF formated file with the base name of the input file and extension .lps in a track LPSdB which contains amplitudes (on a dB scale) of all frequencies in the computed spectrum.

The function is a re-write of the wrassp::lpsSpectrum function, but with media pre-conversion, better checking of preconditions such as the input file existance, structured logging, and the use of a more modern framework for user feedback.

The native file type of this function is "wav" files (in "pcm_s16le" format), SUNs "au", NIST, or CSL formats (kay or NSP extension). Input signal conversion, when needed, is done by libavcodec and the excellent av::av_audio_convert wrapper function

Value

The number of successfully written files (if toFile=TRUE), or a vector of AsspDataObj objects (if toFile=FALSE).

Note

This function takes some time to apply but also result in data in a relatively large matrix. It is therefore not usually efficient to store intermediate results in a cache. However, if the number of signals it will be applied to is very large, then caching of results may be warranted.

Author(s)

Raphael Winkelmann

Lasse Bombien

Fredrik Nylén

See Also

dftSpectrum, cssSpectrum, cepstrum; all derived from libassp \insertCites5hsuperassp spectrum function.

Examples

# get path to audio file
path2wav <- list.files(system.file("samples","sustained", package = "superassp"), pattern = glob2rx("a1.wav"), full.names = TRUE)

# calculate linear prediction smoothed spectrum 
res <- lpsSpectrum(path2wav, toFile=FALSE)
resolution <- attr(res,"origFreq") / ncol(res[[1]])

# plot spectral values at midpoint of signal
plot(y=res[["CSS[dB]"]][400,],
    x=seq(1,ncol(res[[1]]),1)* resolution,
    type='l',
    xlab='Frequency (Hz)',
    ylab='Amplitude (dB)')


humlab-speech/superassp documentation built on May 8, 2024, 2:27 p.m.