简体   繁体   中英

How to generate a white noise matrix of certain amplitude in R?

this is a rather simple question, yet, I struggle to cope with it.

Basically, I want to generate a matrix (2 cols, 10,000 rows). The first column will define a simple sequence (seq(1,10,000,1), the second column should consist of "white noise".

Therefore, I would like to generate a vector (of size 10,000) consisting of white noise. Since the noise should roughly mimic a molecular ion concentration, the noise's values should range between 2e-7 and 1.2e-6.

在此处输入图片说明 Is there an easy way to do this in R?

Many thanks and best wishes!

I added an image below of a calcium signal; of course it would be great to simulate a signal with a similar dynamic but primarily I would like to focus on randomly oscillating dynamics (no defined frequency, minimal changes in amplitudes).

A vector of Gaussian white noise can be generated with rnorm(10000) and you can define a function to set the required range, the following code will generate a vector with the desired range (w.noise):

noise <- rnorm(10000)
scale <- function(noise){(noise-min(noise))/(max(noise)-min(noise))*(1.2e-6-2e-7)+2e-7}
w.noise <- scale(noise)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM