[R] How to generate pitch strings

Atte Tenkanen attenka at utu.fi
Sun Feb 5 08:13:05 CET 2006


> If I calculate a transition probability matrix, first order markov 12x12
> or second order 144x144 from musical pitch classes (0-11), is it possible
> to generate pitch class strings similar as those original strings using
> those probability matrix with R? If, how?
>
> Atte Tenkanen, Turku, Finland
>

I found this kind of solution:

j=1; a1=c();
Generated_Melody=c(1); #first note as a seed
a1=sample(1:12, size=1, prob=PT_matrix[j,]) # a seed for the loop following

for (i in 1:100){ # length of the generated melody will be 100
	Generated_Melody=c(Generated_Melody,a1)
	a1=sample(1:12, size=1, prob=PT_matrix[a1,])
}

# Generated_Melody=Generated_Melody-1;  # to picht classes
# Generated_Melody=Generated_Melody+59; # or to midi pitches


Atte Tenkanen

PS. Here is my page considering the course in which we use R for music
analysis...
http://musiikintutkimus.blogspot.com/




More information about the R-help mailing list