Learn R Programming

phonTools (version 0.2-2.0)

sinusoid: Create Sinusoids

Description

Create and display one or more sinusoids.

Usage

sinusoid (freqs, amps = rep(1, length(freqs)), dur = 50, 
phases = rep(0, length(freqs)), fs = 10000, sum = FALSE, 
show = FALSE, colors = NULL)

Arguments

freqs
A vector of frequencies, one for each desired sinusoid.
amps
A vector of peak amplitudes, one for each desired sinusoid.
dur
The desired duration of the sinusoids, in milliseconds.
phases
A vector of initial phases, one for each desired sinusoid, expressed in radians.
fs
The desired sampling frequency of the sinusoids.
sum
If TRUE, the sum the generated sinusoids is also found.
show
If TRUE, the generated sinusoids are plotted. If sum is TRUE, a second plot is created to display the sum of the sinusoids.
colors
An optional vector of colors used to plot the individual sinusoids. If the number of colors given is less than the number of frequencies specified, the colors are repeated.

Value

  • A dataframe with the following columns:
  • timeThe time, in milliseconds, at which is sample is taken.
  • waveNA series of columns, each indicating the amplitude of wave N at a given time.
  • sumA column indicating the sum of all of the sinusoids.

Details

A number of sinusoids are generated, and optionally plotted and/or returned. The number of frequencies specified must equal the number of amplitudes and initial phases.

Examples

Run this code
## several waves, and the sum
sum = sinusoid (freqs = c(100,200,300), amps = c(1,3,2), 
sum = TRUE, show = TRUE)

## no sum, different phase shifts
nosum = sinusoid (freqs = c(100,200,300), amps = c(1,3,2), 
phases = c(pi/2, 0, pi/4), sum = FALSE)

Run the code above in your browser using DataLab