Skip to content Skip to sidebar Skip to footer

Dsp - Get The Amplitude Of All The Frequencies

this question is related to : DSP : audio processing : squart or log to leverage fft? in which I was lost about the right algorithm to choose. Now, Goal : I want to get all the fre

Solution 1:

  • You say "I want to get all the frequencies of my signal, that I get from an audio file." but what you really want is the magnitude of the frequencies.

  • In your code, it looks like (I don't know python) you only read the first 10 samples. Assuming your file is mono, that's fine, but you probably want to look at a larger set of samples, say 1024 samples. Once you do that, of course, you'll want to repeat on the next set of N samples. You may or may not want to overlap the sets of samples, and you may want to apply a window function, but what you've done here is a good start.

  • What sleepyhead says is true. The output of the fft is complex. To find the magnitude of a given frequency, you need to find the length or absolute value of the complex number, which is simply sqrt( r^2 + i^2 ).

Solution 2:

Mathematically Fourier Transform returns complex values as it is transform with the function *exp(-i*omega*t). So the PC gives you spectrum as a complex number corresponding to the cosine and sine transforms. In order to get the amplitude you just need to take the absolute value: np.abs(spectrum). In order to get the power spectrum square the absolute value. Complex representation is valuable as you can get not only amplitude, but also phase of the frequencies - that may be useful in DSP as well.

Solution 3:

If I got it right, you want walk over all data(sound) and capture amplitude, for this make a "while" over the data capturing at each time 1024 samples

data = f.read_frames(1024)

whiledata != '':
    print(data)
    print(np.fft.rfft(data))
    data = f.read_frames(1024)

Post a Comment for "Dsp - Get The Amplitude Of All The Frequencies"