I'm analysing a lot of short .wav files and for a part of the analysis I want to plot the fundamental frequency only of the file. My signal processing is a bit rusty, but I'm now getting plots that look like they should be correct. I'm just not getting why the y axis scale is off (the F0 is around 300Hz when it should be around 8000Hz). So I want to plot the F0 across the duration of the .wav file like a spectrogram without the intensity information. Can anybody help me out? happy to provide additional info!
from scipy import signal
import numpy as np
import soundfile as sf
y, samplerate = sf.read('audiofile.wav')
chunks = np.array_split(y,int(samplerate/2000))
peaks = []
for chunk in chunks:
# simulated pure signal
t = np.linspace(0, 1, samplerate)
wave = chunk
# compute the magnitude of the Fourier Transform and its corresponding frequency values
freq_magnitudes = np.abs(np.fft.fft(wave))
freq_values = np.fft.fftfreq(samplerate, 1/samplerate)
# find the max. magnitude
max_positive_freq_idx = np.argmax(freq_magnitudes[:samplerate//2 + 1])
peaks.append(freq_values[max_positive_freq_idx])