3

I have an audio frame which is a NumPy array of length 16000.

Wave form

When I apply numpy FFT to the audio frame, I get a spectrum that peaks at 0 Hz. I tried different audio frames from the same audio file but all of them seem to have peaks at 0 Hz. enter image description here

Could anyone please help me to understand where I am doing wrongly? Thank you.

Akihero3
  • 365
  • 5
  • 12
  • Aren't the values you are using in `audio_frame` volume levels? – amzon-ex Nov 14 '20 at 18:31
  • yes, it is volume level in audio_frame. – Akihero3 Nov 14 '20 at 19:58
  • 1
    Okay, the primary issue is that your audio signal has a negative offset. That explains the 0Hz peak. Remove the offset first, its strength suppresses those of all others. – amzon-ex Nov 15 '20 at 04:53
  • Does this answer your question? [power spectrum by numpy.fft.fft](https://stackoverflow.com/questions/20074930/power-spectrum-by-numpy-fft-fft) – mkrieger1 Jan 11 '22 at 16:47

1 Answers1

2

There is a bias of around -0.2, right? This is a constant value along with the time. This is to say that there is a strong component at 0 Hz compared with the variation around this constant value. You need only to interpret the results.

Solution: try to subtract the average value from the signal in the time domain. I suppose that, magically, the 0 Hz component will disappear.

Leos313
  • 5,152
  • 6
  • 40
  • 69
  • 1
    I was doing something weird in normalization. It worked when I subtract the mean value from the array! Thanks for your tips! – Akihero3 Nov 15 '20 at 12:21
  • 2
    @Akihero3: Note that subtracting the mean from your signal is exactly the same thing as setting the 0 frequency component to 0 (but more expensive computationally). So just ignore the 0 frequency component. – Cris Luengo Nov 15 '20 at 14:44
  • @CrisLuengo Thank you, do you mean I should not subtract and ignore the first element after FFT is a better solution because of the computational perspective? Also, I still don't get why subtracting mean value from array results in 0 frequency components being 0. Do you know if there is any resource that can help me to understand how it works? – Akihero3 Nov 15 '20 at 15:23
  • 1
    @Akihero3: any text book on the Fourier transform will explain this. This is a basic property of the Fourier transform: the value for the zero-frequency component is equal to the mean (or sum, depending on normalization) of the input signal. This is basically the meaning of the 0-frequency component. What is a signal component with 0 Hz? A constant component. – Cris Luengo Nov 15 '20 at 16:27
  • @CrisLuengo That perfectly makes sense, thank you very much much! – Akihero3 Nov 15 '20 at 16:47
  • normally you do not ignore anything. You just justify everything and, KNOWING what you are doing, you perform the action to obtain what you want. The component at 0 frequenzy it is important. – Leos313 Nov 15 '20 at 18:19
  • 1
    @Leos313 yeah I normalize it before applying FFT as I don't want a constant signal at -0.2 which does not make sense. Thanks for tips! – Akihero3 Nov 15 '20 at 18:25
  • @Akihero3, what happens if you perform an FFT of a constant value? Well, you have a spectrum with only one component at 0 Hz, right? – Leos313 Nov 15 '20 at 18:25
  • @Leos313 yeah, I should only get 0 Hz as there is no variance in the time domain signal if I have a constant value across the frame. – Akihero3 Nov 15 '20 at 18:27