Correction for reduced energy when windowing
See original GitHub issueApplying window weighting (e.g. Hann) to a signal reduces its energy. I think it’s common to want to correct for this. For example, it appears that such a correction is applied by default in scipy.signal.welch
:
import xrft
import numpy as np
import scipy.signal
import xarray as xr
import matplotlib.pyplot as plt
x = xr.DataArray(np.random.normal(0, 1, size=10000),
dims=['t'],
coords=[range(0,10000)])
n_segment = 100
f_scipy, p_scipy = scipy.signal.welch(x.values,
window='hann',
nperseg=n_segment,
noverlap=0,
return_onesided=False)
p_xrft = xrft.xrft.power_spectrum(x.chunk({'t': n_segment}),
dim=['t'],
detrend='constant',
window=True,
chunks_to_segments=True).mean('t_segment')
# Correction tends to 8/3 for infinitely long Hann window
p_xrft_corrected = (1 / np.mean(np.hanning(n_segment)**2))*p_xrft
plt.plot(f_scipy, p_scipy,
label='scipy psd')
plt.plot(p_xrft.freq_t, p_xrft,
color='C2', label='xrft psd')
plt.plot(p_xrft.freq_t, p_xrft_corrected,
linestyle='--', color='C1', label='corrected xrft psd')
plt.ylim(0,1.6)
plt.xlabel('freq')
plt.ylabel('psd')
plt.legend()
Is there an appetite (beyond my own) to have an option to apply such a correction when using window=True
in xrft
?
Issue Analytics
- State:
- Created 3 years ago
- Comments:15 (15 by maintainers)
Top Results From Across the Web
Window Correction Factors - Siemens Communities
To correct for amplitude or energy distortion, each spectral line of a windowed frequency spectrum are multiplied by a fixed factor. This factor ......
Read more >Crosstalk Reduction Using a Dual Energy Window ... - PubMed
In conventional single-photon emission computed tomography, a dual energy window (DEW) subtraction method is used to reduce crosstalk. This ...
Read more >Crosstalk Reduction Using a Dual Energy Window Scatter ...
In conventional single-photon emission computed tomography, a dual energy window (DEW) subtraction method is used to reduce crosstalk.
Read more >Window settings in Triple Energy Window scatter correction ...
Window settings in Triple Energy Window scatter correction. The main window is centered on the peak in the photon energy spectrum of the...
Read more >The influence of triple energy window scatter ... - IOPscience
This technique uses upper and lower scatter energy windows, immediately adjacent to the photopeak window, to estimate the number of ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I agree with this but we’ll keep it for another PR.
Sorry, I forgot to mention that I changed the
_apply_window
function to also return the windows as below: