sim_sinusoid: Simulate and visualise sinusoidal waves with different...

View source: R/sim_sinusoid.R

sim_sinusoidR Documentation

Simulate and visualise sinusoidal waves with different parameters

Description

This function is used to simulate and visualise sinusoidal waves with different parameters.

Usage

sim_sinusoid(
  x,
  f = sin,
  a = 1,
  b = NULL,
  period = 2 * pi,
  c = 0,
  d = 0,
  plot = TRUE,
  type = "l",
  return = FALSE,
  ...
)

Arguments

x

A numeric vector.

f

The sinusoidal function (i.e., sin or cos, see Trig).

a

A number which defines the amplitude (i.e., the height) of the wave.

b

A number which defines the horizontal stretch parameter. Alternatively, period can be provided.

period

A number which defines the period (i.e., the number of units between successive waves) of the wave. This is silently ignored if b is provided.

c

A number which defines the horizontal shift parameter.

d

A number which defines the vertical shift parameter (i.e., the mean).

plot

A logical input which defines whether or not to plot the simulated wave. This is TRUE by default.

type

A character which defines the type of plot to produce (see plot.default). A line plot (type = "l") is the default.

return

A logical input which defines whether or not to return the values of the wave. This is FALSE by default.

...

Other arguments passed to pretty_plot to customise the plot.

Details

Sinusoidal waves are simulated according to the equation a f(bx + c) + d where the parameters are as defined above and b is related to period by b = \frac{2 π}{period}.

Author(s)

Edward Lavender

Examples

# Simulate some x values with observations every 0.1 units (e.g., 0.1 s)
x <- seq(0, 10, by = 0.1)
# Visualise a sine wave with a period of 2 s
sim_sinusoid(x, period = 10)
# Or, equivalently, a wave with b = (2*pi)/10
sim_sinusoid(x, b = (2*pi)/10)
# Adjust other parameters, such as the amplitude:
sim_sinusoid(x, period = 10, a = 10)
# Adjust the sinusoidal function via f
sim_sinusoid(x, f = cos, period = 10, a = 10)

edwardlavender/Tools4ETS documentation built on Nov. 29, 2022, 7:41 a.m.