Using Fast Fourier Transform to determine musical notes Hi guys i am doing a course in Digital Filters and Spectral analysis. We are given a coursework/homework, and I have absolutely no idea what to do with it. I come from Maths background, never done any signal processing before, and since I am new to the university I don't really have anyone to ask.

Problem:

In this exercise you are required to use spectral analysis techniques to determine the musical notes played within a short audio sample (with sampling frequency 44.1KHz). The sample will comprise a short sequence of 5 chords, each comprising 3 or 4 different musical notes played concurrently. Each note comprises a fundamental plus a series of harmonics at multiples of the fundamental frequency. All of the notes in this exercise belong to the 12 note equal temperament scale.

Here is some piece of code I scrambled so far:

[x,fs] = audioread('sample1_va18535.wav');
fs % fs is the sampling frequency usually 44.1 KHz
wavplay; % Play audio
N = 4410; % 0.1 seconds at 44.1KHz
N1 = 2205; % 0.05 seconds
n = N1+1:N1+N; % 0.05 – 0.15 seconds
xn = x(n,1); % Select left channel of short clip
wavplay; % Play short clip
t = n/fs; % Time index
plot(t,xn);
xlabel('Time (s)');
ylabel('Amplitude');
window = hamming(N); % Create window
wxn = xn .* window; % Apply window
Xk = fft(wxn); % DFT
k = 0:N-1;
f=k*fs/N; % Frequency in Hz
pause;
plot(f,abs(Xk));
ylabel('Magnitude');
xlabel('Frequency (Hz)');


Now I am pretty sure this is far from over ( I am not even sure if this code is correct).Would anyone be so kind and explain to me how can I generate those frequencies? I know I am required to create a vector of fundamental frequencies and ignore any harmonics.

Here is the file: https://ufile.io/lyge5
Unless your audio data consists of pure sinusoidal note sources, a raw FFT magnitude plot will give you all the harmonics or overtones of pitched musical sounds, as well as any fundamental pitch frequency spectrum (if any).  So, with most common polyphonic music recordings, pitch detection/estimation, if possible, usually involves a significant amount of post-processing of any FFT results.  Not just picking the largest magnitude peaks.

Either Cepstral processing (or computing the Cepstrum), or the Harmonic Product Spectrum algorithm, look for periodic sequences of overtones or harmonic peaks embedded in FFT spectra, which might indicate a source pitch candidate.  (e.g. Look for embedded trains of some number of magnitude peaks at evenly spaced frequency multiples.)  But, especially with polyphony and many common chord types, there will likely be some number of false positives that you will have to figure out how to discount or ignore.

Or, instead of using an FFT, you could also try looking at auto-correlation peaks (or other lag-based partial similarity measures), and see if these peaks correspond to the appropriate pitch range and degree of polyphony.