Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- notes = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
- keys = {f"{notes[i % 12]}{int(i / 12)}": 440 * pow(2, (1 / 12) * (i - 57))
- for i in range(9, 8 * 12 + 1)}
- h_freq = 3579545
- print(keys)
- def note_error(note_freq: float):
- x = round(h_freq / note_freq)
- real_freq = h_freq / x
- error_in_cent = np.log2(real_freq / note_freq) * 1200
- return error_in_cent
- errors = {key_name: note_error(freq) for (key_name, freq) in keys.items()}
- print(errors)
- plt.figure(figsize=(18, 6))
- plt.xticks(rotation=90)
- plt.xlabel("key")
- plt.ylabel("error in cents")
- plt.plot(list(errors.keys()), list(errors.values()),
- marker='o', linestyle="dotted")
- plt.axhline(y=0.2, color='red', linestyle="dashed")
- plt.axhline(y=-0.2, color='red', linestyle="dashed")
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement