Learn R Programming

soundgen (version 2.7.0)

specToMS: Spectrogram to modulation spectrum

Description

Takes a spectrogram (either complex or magnitude) and returns a MS with proper row and column labels.

Usage

specToMS(spec, windowLength = NULL, step = NULL)

Value

Returns a MS - matrix of complex values of the same dimension as spec, with AM in rows and FM in columns.

Arguments

spec

target spectrogram (numeric matrix, frequency in rows, time in columns)

windowLength

length of FFT window, ms

step

you can override overlap by specifying FFT step, ms (NB: because digital audio is sampled at discrete time intervals of 1/samplingRate, the actual step and thus the time stamps of STFT frames may be slightly different, eg 24.98866 instead of 25.0 ms)

Examples

Run this code
s = soundgen(sylLen = 500, amFreq = 25, amDep = 50,
             pitch = 250, samplingRate = 16000)
spec = spectrogram(s, samplingRate = 16000, windowLength = 25, step = 5, plot = FALSE)
ms = specToMS(spec)
image(x = as.numeric(colnames(ms)), y = as.numeric(rownames(ms)),
      z = t(log(abs(ms))), xlab = 'Amplitude modulation, Hz',
      ylab = 'Frequency modulation, cycles/kHz')
abline(h = 0, lty = 3); abline(v = 0, lty = 3)

Run the code above in your browser using DataLab