R:如何产生一个嘈杂的正弦函数

标签 r noise trigonometry stochastic

我对整个R-thing还是很陌生的。

我的目标是:我有一个正弦函数,描述随时间变化的钙颗粒数:
像y = a * sin(b * t)+ c

因为实际上在随机事件中描述了钙的生成和去除,所以我想在函数中添加一个随机噪声项(最好在平均噪声幅度上可扩展)。

z = y + random * Amplitude之类的东西

你能帮我吗?

最好的

最佳答案

这是我将要使用的一种方法-我提供了两个选项来确定错误的产生方式(均匀分布与高斯分布):

### 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")

enter image description here

关于R:如何产生一个嘈杂的正弦函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32111941/

相关文章:

actionscript-3 - atan2函数和轴方向

ios - 为什么 Apple 翻转了 UIBezierPath 的单位圆?

performance - 加速将人 reshape 为 R 中的周期格式数据帧

r - 重叠加入起点和终点

r - 用值过滤因子

android - 在 Android 中查询噪音水平

java - 尝试加载 qdap 包时出现 R 错误

opencv - 处理具有挑战性的图像的想法

python - 一个接一个地计算多个正弦波