Time signal FFT different for whole signal than half signal on high frequencies 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?


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 &gt; 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 &gt; 0]
    uk = uk[:len(freqs)]

    return freqs, uk
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. 



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).