1
$\begingroup$

I have a time signal of u from 0 to 1000 time units. If I chop the signal in two halves and compare the frequency spectrum of both it looks similar, as it should (the signal should be statistically steady from where I start recording it). However if I compare it to the frequency spectrum of the full signal I get a different slope in the high-frequency region.

I do not understand this. If I use the whole signal there should be a change on the low-frequency region rather than the high-frequency one right?

enter image description here This is the code I use compute the frequency spectrum. I think it's okay, but maybe I'm doing something wrong.

def time_spectra(t, u):
    import numpy as np
    from scipy.interpolate import interp1d
    # Re-sample u on a evenly spaced time series (constant dt)
    u_function = interp1d(t, u, kind='cubic')
    t_min, t_max = np.min(t), np.max(t)
    dt = (t_max-t_min)/len(t)
    t_regular = np.arange(t_min, t_max, dt)[:-1] # Skip last one because can be problematic if > than actual t_max
    u_regular = u_function(t_regular)

    # Compute fft and associated frequencies
    uk = np.abs(np.fft.fft(u_regular)) / len(u_regular)
    freqs = np.fft.fftfreq(u_regular.size, d=dt)

    # Take only positive frequencies
    freqs = freqs[freqs > 0]
    uk = uk[:len(freqs)]

    return freqs, uk
$\endgroup$
5
  • $\begingroup$ I think there are two effects at play: one you will have a smaller resolution bandwidth (so the power in each bin will go down by 3dB) and in addition to this spectral leakage? I do not see that you are using a window in your code. Can you repeat with a window on your signal prior to FFT (Blackman or any other high dynamic range window of your choice) - we will still see a difference if the window has a frequency roll-off but possible we reach your signals noise floor first in which case it would be just a 3 dB difference. If this happens I can provide the further details why as an answer. $\endgroup$ Sep 14, 2018 at 11:15
  • $\begingroup$ Thanks for the comment. I will do the windowing, but what is it useful for in this case? Also, why is the bandwidth resolution smaller for the half signals? $\endgroup$
    – b-fg
    Sep 14, 2018 at 11:18
  • $\begingroup$ The bandwidth is wider for half signals. Without a window the bandwidth in Hz is 1/T where T is the time length of your signal (I have another recent answer to another question that goes into the details of this- can add the link later when not on my phone). The rectangular window (which is what you have if you did no other window) has sidelobes (spectral leakage) that roll-off in magnitude slower than any other window, so depending on the actual signal level of adjacent lower power frequencies you may be just seeing the leakage and not the signals. $\endgroup$ Sep 14, 2018 at 11:24
  • $\begingroup$ I suspect the floor has a 3 dB difference due to the change in time length T and the rest due to the change in leakage but repeating with a better window will test that $\endgroup$ Sep 14, 2018 at 11:27
  • $\begingroup$ @Dan, the blackman window did the trick indeed! Thank you very much. Please elaborate an answer so I can accept it :) $\endgroup$
    – b-fg
    Sep 17, 2018 at 3:59

1 Answer 1

1
$\begingroup$

The primary issue is due to using a rectangular window with the floor being the result of spectral leakage.

This is demonstrated in the plot below showing the frequency response (kernel) for the two rectangular windows used; one 500 samples long as red and the other 1000 samples long as blue. The corresponding rectangular window is effectively multiplied by your signal in time, thus convolves with your signal in frequency, resulting in spectral leakage as the spectrum given in the original question. Thus you are seeing the smearing (convolution) of the actual spectrum with this kernal in each case. Using a window with a wider dynamic range (lower sidelobes) such as the Blackman would result in a better view of the actual spectrum to the extent that spectral components now are getting buried under the spectral leakage.

Dirichlet Kernel

For further details on windowing and window choices, please see this post: Why would one use a Hann or Bartlett window?

You will also see a 3 dB difference between two windows if the signal energy is distributed wider than the resolution bandwidth in each case, since the resolution bandwidth for the rectangular window is $1/T$ where T is the length of your waveform. (So when you double the length from 500 to 1000, the resolution bandwidth is half resulting in half the power in each bin (unless a spectral tone occupies one bin in which case you would not see a change).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.