I am still pretty new to the whole R-thing.
I have the following aim; I have a sine function that describes a calcium particle number over time: something like y = a * sin (b*t) + c
Since in reality the generation and removal of calcium is described in stochastic events, I would like to add a random noise term to my function (preferably scalable in average noise amplitude).
Something like z = y + random*Amplitude
can you help me out?
Best
In its most general form, the sine wave can be described using the function y=a*sin(bx), where: a is known as the amplitude of the sine wave. b is known as the periodicity.
Sinusoidal Noise is a modular light installation that uses random oscillating patterns to create a larger sense of movement. The work comprises 98 pixels each of which fades on and off at a unique frequency.
To change the frequency of a sine wave generated by the “osc~” object you need to send the frequency in Hz to the hot inlet. To control the phase of a sine wave you can set it on the right inlet of osc~. This will set the phase of the repeating waveform; any new input will reset the phase.
y <- jitter(a*sin(b*t) + c)
using the jitter()
function will add random noise to your function. you can specify the "amount" parameter inside jitter() to control the amplitude.
Here's an approach I would use - I provided two options on how your error might be generated (uniform distribution vs Gaussian distribution):
### Equation: y=a*sin(b*t)+c.unif*amp
# variables
n <- 100 # number of data points
t <- seq(0,4*pi,,100)
a <- 3
b <- 2
c.unif <- runif(n)
c.norm <- rnorm(n)
amp <- 2
# generate data and calculate "y"
set.seed(1)
y1 <- a*sin(b*t)+c.unif*amp # uniform error
y2 <- a*sin(b*t)+c.norm*amp # Gaussian/normal error
# plot results
plot(t, y1, t="l", ylim=range(y1,y2)*c(1,1.2))
lines(t, y2, col=2)
legend("top", legend=c("y1", "y2"), col=1:2, lty=1, ncol=2, bty="n")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With