Learn R Programming

soundgen (version 3.0.0)

specToMS_1D: Spectrogram to modulation spectrum 1D

Description

Takes a spectrogram and returns the spectrum of each channel. The input can be an ordinary STFT spectrogram or an auditory spectrogram (a signal convolved with a bank of bandpass filters). The difference from specToMS is that, instead of taking a two-dimensional transform of the spectrogram, here the spectra are calculated independently for each frequency bin.

Usage

specToMS_1D(
  spec,
  samplingRate,
  windowLength = 250,
  step = windowLength/2,
  specMethod = c("meanSpectrum", "spectrum")
)

Value

A modulation spectrum - a matrix of real values, with center frequencies of original filters in rows (kHz) and modulation frequencies in columns (Hz).

Arguments

spec

input spectrogram (numeric matrix with frequency in rows and time in columns)

samplingRate

for auditory spectrogram, the sampling rate of input audio; for STFT spectrograms, the number of STFT frames per second

windowLength, step

determine the resolution of modulation spectra (both in ms); this only has an effect if specMethod = "meanSpectrum"

specMethod

calls either meanSpectrum (faster) or spectrum (higher resolution)

Examples

Run this code
data(speechEx, package = 'soundgen')

# auditory spectrogram
as = audSpectrogram(speechEx, from = 0, to = 1,
  envelope = 'hil', nFilters = 24, step = NULL, plot = FALSE)
ms = specToMS_1D(as$filterbank_env, samplingRate = [email protected])
plotMS(log(ms+.01), logWarpX = c(10, 2), quantiles = NULL, ylab = 'kHz')

# ordinary STFT spectrogram
sp = spectrogram(speechEx, from = 0, to = 1, windowLength = 15, step = 0.5,
  output = 'original', plot = FALSE)
ms2 = specToMS_1D(sp, 1000 / 0.5)  # 1000/0.5 frames per s
plotMS(log(ms2+.01), quantiles = NULL, ylab = 'kHz')

if (FALSE) {
# full resolution
ms_spec = specToMS_1D(as$filterbank_env, samplingRate = [email protected],
  specMethod = 'spectrum')
plotMS(log(ms_spec+.01), logWarpX = c(10, 2), quantile = NULL, ylab = 'kHz')
}

Run the code above in your browser using DataLab