# 500 Hz tone
sound = cos(2 * pi * 500 * (1:4000) / 16000) + rnorm(4000, 0, .05)
# Spectrum on linear scale
spectrum(sound, samplingRate = 16000, yScale = 'linear')
meanSpectrum(sound, samplingRate = 16000, yScale = 'linear')
# dB scale with custom labels
spectrum(sound, samplingRate = 16000, yScale = 'dB', col = 'blue',
xlab = 'Frequency (kHz)', ylab = 'Amplitude (dB)')
# max0 scale with custom y-limits and extra graphical pars
meanSpectrum(sound, samplingRate = 16000, yScale = 'max0',
xlim = c(0, 2), ylim = c(-50, 5), lty = 2, lwd = 3, col = 'blue')
# Return data without plotting
ms = meanSpectrum(sound, samplingRate = 16000, plot = FALSE)
head(ms)
# If windowLength is longer than the sound, meanSpectrum() = spectrum()
spectrum(sound, 16000)
meanSpectrum(sound, 16000, windowLength = 5000)
if (FALSE) {
# Process all .wav files in a folder
spectrum('~/Downloads/temp', savePlots = TRUE, yScale = 'dB')
}
Run the code above in your browser using DataLab