- Aim : Pitch Calculation
Issue : The calculated pitch does not match the expected one. For instance, the output is approx. 'D3', however the expected output is 'C5'.
Source Sound : https://freewavesamples.com/1980s-casio-celesta-c5
library("tuneR") library("seewave") #0: Acquisition of sample sound snd_smpl = readWave(paste("~/Music/sample/1980s-Casio-Celesta-C5.wav"), from = 0, to = 1, units = "seconds") dur_smpl = duration(snd_smpl) len_smpl = length(snd_smpl) #1 : Pre-Processing Stage #1.1 : Application of Hanning Window n = 1:len_smpl han_win = 0.5-0.5*cos(2*pi*n/(len_smpl-1)) wind_sig = han_win*snd_smpl@left #2.1 : Auto-Correlation Calculation rev_wind_sig = rev(wind_sig) #Reversing the windowed signal acorr_1 = convolve(wind_sig, rev_wind_sig, type = "open") # Obtaining the 2nd half of the correlation, to simplify calculation n = 2*len_smpl-1 acorr_2 = (1/len_smpl)*acorr_1[len_smpl:n] #2.2 : Note Calculation min_index = which.min(acorr_2) print(min_index) fs = 44100 fo = fs/min_index #To obtain fundamental frequency print(fo) print(notenames(noteFromFF(fo)))
> print(min_index)  37 > fs = 44100 > fo = fs/min_index > print(fo)  1191.892 > print(notenames(noteFromFF(fo)))  "d'''"
The entire calculation is performed in the Time Domain. I'm currently using autocorrelation as a base to understand more about Pitch Detection & Analysis. I've tried to analyse the sample with 'Audacity' and the result is 'C5'. Hence, I'm wondering where actually the issue is. Can you all help me find it?
Also, there are a few but important doubts:
- How small should actually my analysis window be (20ms, 1s,..)?
- Will reinforcement of the Autocorrelation Algorithm with AMDF and other similar algorithms make this Pitch Detection module more robust?