sim_sinusoid | R Documentation |
This function is used to simulate and visualise sinusoidal waves with different parameters.
sim_sinusoid( x, f = sin, a = 1, b = NULL, period = 2 * pi, c = 0, d = 0, plot = TRUE, type = "l", return = FALSE, ... )
x |
A numeric vector. |
f |
The sinusoidal function (i.e., sin or cos, see |
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 |
A number which defines the period (i.e., the number of units between successive waves) of the wave. This is silently ignored if |
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 |
type |
A character which defines the type of plot to produce (see |
return |
A logical input which defines whether or not to return the values of the wave. This is |
... |
Other arguments passed to |
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}.
Edward Lavender
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.