«The Sounds of Fibonacci» by henk.lasschuit

on 16 Mar'14 11:37 in mathematicsresearch

Pisano Periods for the numbers 2 to 1000 converted to sounds

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* The sounds of Fibonacci
In the Fibonacci-sequence every term is found by adding the two previous terms:

0, 1, 1, 2, 3, 5, 8, 13.....

If you divide the terms of the Fibonacci-sequence by any given number and note the remainder, you will find a repeating sequence called the Pisano Period (Leonardo Pisano was the real name of Fibonacci):

2: 0, 1, 1, 0, 1, 1, 0, 1, 1, 0...
3: 0, 1, 1, 2, 0, 2, 2, 1, 0, 1, 1, 2, 0, 2, 2, 1...

This is great, because you can simply turn a Pisano Period into sound! For the number 2 the period has a length of 3 and using a sampling rate of 44100 this will result in a tone of 14700 Hz, which is within audible range (if you are young enough). The Pisano Period for the number 1000 is roundabout 1500, which will give you a tone of about 30 Hz, well within audible range.

Any term of the Pisano Period for a given number can be found by adding the two previous terms of that Pisano Period, divide it by the given number en note the remainder. That's nice, because you don't have to work with the enormous numbers of the original Fibonacci-sequence.

Any Pisano period will contain 1 or 2 or 4 zeros.

This idea was inspired by this video:
http://www.youtube.com/watch?v=Nu-lW-Ifyec

The Fibonacci-sequence can be found in the Online Encyclopedia of Integer Sequences:
http://oeis.org/A000045

as well as the sequence of lengths of the Pisano Period for different numbers:
http://oeis.org/A001175

 */
 
 s.boot;
 a=Array.new(14700000);//array for storing 1000 sounds each with a duration of 1/3 of a second
 c=Array.newClear(14700) //array for storing 1 sound with a duration of 1/3 of a second
 c.put(0,0);
 c.put(1,1);
 (
 for (2, 1000, {arg j; // voor j=2 t/m 1000, divisors
	for (2, 14699, {arg i; c=c.put(i, (c[i-1]+c[i-2])%j)});
	 c=2*(c+0.5)/j-1; //normalise, this will but the values conveniently between -1 and 1
 	for (0, 14699, {arg i; a=a.add(c[i])});
 	// a.add(c); will not work: a will contain an array in each cell in stead of a number
 	c.put(0,0); //this is necessary after normalising
 	 c.put(1,1);
 });
 ) //this will take a few seconds
 a=a.add(0); //to avoid glitches when switching the sound of. It also prevents nasty effects when playing the sounds repeatedly	
 b=Buffer.loadCollection(s, a);
 x = { PlayBuf.ar(1, b, BufRateScale.kr(b), loop: 0) };
 x.play;
 x.free;
 b.free; 
 a.free;
raw 2397 chars (focus & ctrl+a+c to copy)
reception
comments
ttsesmetzis user 18 Mar'14 12:39

cool