William Simpson <william.a.simpson <at> gmail.com> writes:

> 
> p<-amp*cos(2*pi*freq*(1:n)/n ) + 0.5
> 
> I was wondering if anyone can suggest a way to create a version where
> I get 0s, 1s, and 2s something like a noisy version of this:
> 
> 2                 oooooooo                         oooooo
> 
> 1            ooooo          ooooo         ooooo
> 
> 0  ooooooo                        oooooooo
> 

# It's always polite to add the trivial parts that
# make the example run out of the box
amp = 1
freq = 5
n = 100
p = 0.1

# Well, this is not a noisy version, but one with added spikes
# If that's ok for you, take it
p = amp*cos(2*pi*freq*(1:n)/n ) + 0.5* as.numeric(runif(1:n)<p)
plot(p,type="l")

# Note: the example must be modified for other values of amp
pquant = ((p+1)*3) %/% 3  -1
lines(pquant)

#---------------------

Dieter

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to