Introduction: Pi Digits MIDI Sonification With Visualization
This project transforms the digits of Pi into a musical composition using MIDI. Each digit is mapped to a specific note, and additional harmonies are introduced to create a rich soundscape. The project also includes a visualization of the Pi digits and their corresponding musical notes, providing an engaging way to explore the beauty of mathematics through music.
Supplies
Tools/Materials:
- Python programming environment
- Libraries: mido, matplotlib
Step 1: Step-by-Step Instructions
Step 1: Setup and Libraries
- Title: "Setting Up the Environment"
- Description:
- Begin by setting up your Python environment. Ensure you have Python installed, and then install the necessary libraries using pip:
pip install mido matplotlib
- These libraries will allow to create and manipulate MIDI files and generate visualizations.
Step 2: Generating Pi Digits
- Title: "Generating Pi Digits"
- Description:
- Use Python to generate the digits of Pi. We'll use the first 150 digits for this project.
- This code extracts the digits of Pi and stores them in a list for further processing.
Step 3: Creating the MIDI File
- Title: "Creating the MIDI File"
- Description:
- Create a new MIDI file and add a track for the musical notes.
- Set the instrument to Acoustic Grand Piano and the tempo to 120 BPM.
- Add metadata for better identification.
Step 4: Mapping Pi Digits to Notes
- Title: "Mapping Pi Digits to Musical Notes"
- Description:
- Map each digit of Pi to a MIDI note and add it to the track.
- This code maps each digit to a note, adds dynamic velocity, and introduces harmony every third note.
Step 5: Saving the MIDI File
- Title: "Saving the MIDI File"
- Description:
- Save the MIDI file to your desired location.
- This file can be opened with any MIDI player to listen to the sonification of `Pi`.
Step 6: Visualizing the Data
- Title: "Visualizing the Pi Digits and Notes"
- Description:
- Create a visualization of the Pi digits and their corresponding notes using Matplotlib.
- This visualization helps illustrate the relationship between the digits of Pi and the musical notes they represent.
Attachments
Step 2: References
Designed with the assistance of Mistral AI, showcasing the intersection of mathematics and music through a visually appealing design.




