from scipy.fft import fft import numpy as np import plotly.express as px heltz = { "C4": 261.6, "D4": 294.3, "E4": 327.0, "F4": 348.8, "G4": 392.4, "A4": 436.0, "B4": 490.5 } def main(): _ = input() A = list(map(int, input().split())) A_fft = fft(A) A_fft_abs = np.abs(A_fft) A_fft_freq = np.fft.fftfreq(44100, d=1/44100) main_frequency = A_fft_freq[np.where(A_fft_abs > np.max(A_fft_abs)/10)] sound_errors = {} for sound_name, freq in heltz.items(): relative_frequency = main_frequency / freq relative_frequency_rounded = np.round(relative_frequency) sound_errors[sound_name] = np.linalg.norm( relative_frequency-relative_frequency_rounded) print(min(sound_errors, key=lambda sound_name: sound_errors[sound_name])) if __name__ == "__main__": main()