Removing DC Offset (via removing mean) of input and output signals affects their coherence

I have input $$x$$ and output $$y$$ signals (fs=10 Hz, length N=10800). I have removed DC offset via the following equation: $$x_{normalized} = 100 \frac{(x-\bar x)} {\bar x }$$

where $$\bar x$$ is the mean of x, so as to get a normalised percentage of change

The code for this:

function x_norm = mean_norm(x)
m = nanmean(x);
x_norm = 100*(x-m)/m;
end


I have also attempted other methods such as high-pass filtering and using the detrend(,'constant') function.

I'm taking 1800 sample long epochs (so 3 minutes) at a time and performing system identification to get an estimate of the IR via the inverse FFT of the transfer function $$H$$, which I can then use to convolve with $$x$$ to find predictions of $$y$$.

So $$X_i$$ and $$Y_i$$ can be said to be $$x$$ and $$y$$ data for the epoch $$i$$.

The coherence (calculated using PSDs obtained using Welch's method) between $$X_i$$ and $$Y_i$$ before and after removing DC offset is significantly different to the coherence between them before removing it, and I cannot work out why. There is also a change in the spectra at non zero frequencies, which I did not expect.

What could be causing this change in coherence and spectra? I was under the belief that removing DC offset should not affect it, but perhaps I am wrong.

Thanks!

As an update, I was originally using a Hanning window, and leakage from that was having a big effect on the data. I've now changed to a Rectangular window, which has reduced the differences but there is still some, so it may be that any differences are just due to leakage.

• can you define what you did to compute the coherence? – Marcus Müller Jan 21 at 15:07
• Hi. What is that nanmean() command? What is its output relative to sequence 'x'? – Richard Lyons Jan 21 at 16:08
• Marcus, I calculated coherence from the power spectra obtained through Welch's method. Richard, nanmean(x) simply returns the mean value from an array x and ignores NaNs e.g. nanmean([1 2 3 4 5]) = 3, nanmean([5 6 NaN 7 8]) = 5.2 instead of NaN . I use nanmean instead of mean as sometimes nans are present in my data. Thanks for responding! – Jack Jan 22 at 15:24
• Just second comment, mistake on the nanmean() bit, I meant to point out that it ignores the NaN entirely, so it would be nanmean([5 6 7 8]) = 6.5 but had a momentary lapse. – Jack Jan 22 at 18:32
• @Jack. Hi. I don't have anything useful to say about your coherence processing. But regarding your spectrum analysis: assuming the 'x' sequence contained no NaN-valued samples, then the DFT spectral magnitude samples of your 'x_norm' sequence should be proportional to the DFT spectral magnitudes of your 'x' sequence. And the first (zero-Hz) spectral magnitude sample of your 'x_norm" sequence should be essentially (practically) zero-valued. – Richard Lyons Jan 22 at 23:22