0
$\begingroup$

I want to read in a sound file and get the frequency at each time interval of the signal.

I thought that the best way to approach this is by applying FFT to small chunks of the signal. Because FFT needs to be applied to a periodic function I first apply a hamming window to each chunk, as I understand it the hamming window also reduces spectral leakage because unlike the rectangular window is smoothly decreases the signal amplitude to $0$.

Next I apply the FFT function to each sample in each window and store all the results in a 2D array, each array holds the FFT results for the samples in that window. I then find the frequency which corresponds to each FFT value using this function:

def frequencies_from_fft(num_windows, window_size, df):
    window_frequencies = []
    for window in range(num_windows):
        frequencies = []
        for i in range(window_size):
            if i < window_size:
                frequencies.append(df * i)
        window_frequencies.append(frequencies)
    return window_frequencies

Where:

dt = 1 / sampling_frequency
T = dt * num_samples
df = 1 / T

I already halved the window_size before passing the window_samples in the function because the spectrum is reflected about the nyquist frequency so I only want half the frequency values.

I am unsure about what effect overlapping the windows has on the 2D array of frequency values for each sample in each window. The more overlap, the more frequency readings are resolved, but do I need to average the frequency values from the samples in the windows that overlap? I'm really confused. In addition, are all frequency values from the window useful, in which case I would have a frequency value for each sample, or do I only extract the dominant frequency from each window, in which case I would have as many frequency readings as the number of windows?

Thank you.

$\endgroup$
  • $\begingroup$ You are roughly describing something called the short term Fourier transform (STFT). There are python routines that do this and examples on the web that a little Googling will find. Chances are that an example near to what you are looking for will turn up $\endgroup$ – Stanley Pawlukiewicz Jun 25 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.