I have a bit of code in R that adds noise to an harmonic series according to a normal distribution:

harmonic_data <- c(0.6613882, 1.0730417, 0.1745770
                   , -0.9370355, -0.9045850, 0.2323085)
for (i in 1:length(harmonic_data)){

But now I need to add noise using a Mixture Gaussian with this form:

xx <- seq(-5,5,by=.01)

(With the distribution centered around each value in the harmonic series) I can plot the distribution alright but can't generate one random value from that distribution to add it to the harmonic data. I have tried this:

for (i in 1:length(harmonic_data)){


But it doesn't seem to be doing what I want, the final distribution is a single normal again. I realize this is probably a very basic question but I can't seem to find the answer.

I would greatly appreciate any help. Thanks!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.