I've now removed the DC component after applying the window function. That makes sense as DC is not of interest and it just leaks in the other bins when a window function is applied.
The (scalar) DC offset is supposed to be subtracted from the
original signal, not from the windowed signal. If you want to subtract it from the windowed signal, you must apply the window function to DC as well, according to the equivalence (CH1 - DC) * window = CH1 * window - DC * window (where CH1 and window are vectors/arrays and DC is a scalar value).
The subtraction is trivial, but you can only subtract an
estimate, and the estimation of the DC value also suffers from leakage. Leakage is not unidirectional, but AC frequencies also leak into the estimated DC value. Only in certain special cases, can you get an accurate estimate, but not in general. The best you can get is a signal whose DC
estimate is zero after subtraction, but this does not mean that you have eliminated the actual DC component of the signal. You may even introduce a DC offset which was not present originally. Of course, for a tiny AC signal riding on a huge DC offset, DC subtraction is a big win, even if there remains a residual offset.
In addition to leakage from DC, the first few of bins also suffer from leakage from negative frequencies. If low frequency components are present in the signal, it is inevitable that their negative frequency counterparts are be present in the Fourier spectrum as well, leaking into the first few positive frequency bins.
EDIT:
I have no idea how to compensate for the error of the first few bins in general, so my conclusion is to consider them unusable. If you need to measure these low frequencies, you can of course increase the measurement window duration by a factor of 5 and discard the first 5 bins. That's the price you pay for getting a spectrum analysis filter with high selectivity, high stopband rejection and low far-distance leakage.
Another question: When you measure with a single edge in the measurement window, what assumptions do you make about the settling time of the DUT? Do you expect/require the DUT to settle completely in the interval between the edge and the end of the measurement window?