writeAMWave: Write Amplitude Modulated Waveform

Description Usage Arguments Details Value Author(s) Examples

View source: R/writeAMWave.R

Description

Write a wave file for a synthesized amplitude modulated call

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
writeAMWave(
  fileName,
  outDir,
  signalLength,
  modFrequency,
  frequency,
  sampleRate,
  window = c(0.55, 0.45),
  silence = c(0, 0),
  gainFactor = 0.1
)

createAMWave(
  signalLength,
  modFrequency,
  frequency,
  sampleRate,
  window = c(0.55, 0.45),
  silence = c(0, 0),
  gainFactor = 0.1
)

Arguments

fileName

name of the file to write. If missing, the file be named usign signalLength, modFrequency, frequency, and sampleRate

outDir

directory to write wave files to

signalLength

length of signal to create in seconds

modFrequency

modulation frequency in Hz of the amplitude modulation

frequency

frequency of the AM call

sampleRate

sample rate for the wave file to create

window

window constants for applying the amplitude modulation. See details.

silence

silence to pad before and after signal in seconds

gainFactor

scaling factor between 0 and 1. Low numbers are recommended (default 0.1)

Details

Amplitude modulated signals are modelled as an ideal sinusoid multiplied by a window function. The window function is an offset sinusoid with frequency equal to the modulation frequency:

W = .5 + .45 * sin(2 π mf t)

See example(writeAMWave) for a plot showing how this works.

Value

writeAMWave invisibly returns the file name, createAMWave returns a Wave class object

Author(s)

Taiki Sakai taiki.sakai@noaa.gov

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# Visualisation of modelled AM wave
signal <- sin(2*pi*100*(1:1000)/1000)
window <- .55 + .45 * sin(2*pi*15*(1:1000)/1000)
oldMf <- par()$mfrow
par(mfrow=c(3,1))
plot(signal, type='l')
plot(window, type='l')
plot(window*signal, type='l')
tmpFile <- file.path(tempdir(), 'tempWav.wav')
writeAMWave(tmpFile, signalLength = 1, modFrequency = 1000,
               frequency = 30000, sampleRate = 100000)
file.remove(tmpFile)
amWave <- createAMWave(signalLength = 1, modFrequency = 1000,
                             frequency = 30e3, sampleRate = 100e3)
par(mfrow=oldMf)

PAMmisc documentation built on Oct. 8, 2021, 9:08 a.m.