在MATLAB中,如何根据数据生成随机数?
例如,如果 Ax = 0.0023
,它应该添加一些噪音并产生 newAx = 0.0027
如果Hy = 94.54
,则newHy = 93.42
。最初,我开始按以下方式在 MATLAB 中使用 rand,
newAx = Ax + rand
newAx = 0.9453
这与我拥有的参数 Ax(0.0023)
相差甚远。
如果我必须使用范围,那么在这种情况下我们必须使用 Ax 的最小值和最大值。这也带来了一些问题,比如它与价值观相去甚远。因为我有一个系统,其中 Ax 是在每个时刻逐渐增加的参数。现在,根据 Ax 的值,我必须在每个时刻生成一些随机噪声才能获得几乎接近 Ax 的 newAx 。例如,如果 Ax = 0.0023
生成 newAx = 0.0027
而不是 newAx = 0.4590
我需要创建一个取决于数据本身的随机噪声。
For example if Ax = 0.0023
, it should add some noise to it and produce newAx = 0.0027
If Hy = 94.54
,then newHy = 93.42
. Initially I started using rand in MATLAB in the following manner,
newAx = Ax + rand
newAx = 0.9453
This is very much far from the parameter Ax(0.0023)
which I have.
If I have to use range then in this case we have to use min and max of Ax. That also introduces issues like it is far from the values. As I have a system where Ax is a gradually increasing parameter at every instant of time. Now at every instant depending on the value of Ax I have to generate some random noise to get newAx which is almost close to Ax. Example if Ax = 0.0023
generate newAx = 0.0027
and not newAx = 0.4590
I need to create a random noise which depends on the data itself.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一种方法是使用 RANDN 生成正态分布的噪声值,然后将噪声的标准差缩放为数据值的百分比:
如果
Ax
是要添加噪声的值的向量,您可以这样做:如果您想确保 newAx 保持在特定的值范围内,您可以使用函数 MAX 和 MIN< /a> 像这样:
One way to do this is to use RANDN to generate normally distributed noise values, then scale the standard deviation of the noise to be a percentage of the data value:
And if
Ax
is a vector of values that you want to add noise to, you can do this:If you want to make sure
newAx
stays within a particular range of values, you can use the functions MAX and MIN like so:您想模拟什么样的“噪音”?
rand(1) 给出 0 << 范围内的均匀随机数。 r < 1.“统一”表示每个值的可能性相等,就像滚动单个值一样,完美的死。
换句话说,随机值的范围为 +/- 0.5,以 0.5 为中心。您希望以实际值为中心,并且可能希望根据实际值缩放范围。例如
给你一个范围 -1 < 范围内的均匀随机数。 r < 1.
例如,如果噪声不应超过 1%,则需要使用:
0.01 是我在示例中使用的比例 (1%),1 + ... 以原始值为中心。
许多进程没有均匀分布。随机噪声(例如传感器噪声)的常见分布是正态分布,其中值接近于中心的值比远离中心的值更有可能出现。
Matlab 支持 randn() 进行正态分布。
模拟其他系统的其他分布可以从均匀随机数导出。
What kind of "noise" are you trying to simulate?
rand(1) gives you a uniform random number in the range 0 < r < 1. "Uniform" means each value is equally likely, like rolling a single, perfect die.
In other words, the random value has a range of +/- 0.5, centered around 0.5. You want to center around your actual value, and you might want to scale the range depending on the actual value. e.g.
gives you a uniform random numbers in the range -1 < r < 1.
For example, if the noise should not exceed 1%, you would need to use:
the 0.01 is the scale (1%) I used for the example, the 1 + ... centers around the original value.
Many processes don't have a uniform distribution. A common distribution for random noise (such as sensor noise) is a normal distribution, where values close to the center are more likely than values far from the center.
Matlab supports randn() for normal distribution.
Other distributions which model other systems can be derived from uniform random numbers.