Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lower Power Spectral Density from pywt.cwt Compared to scipy.signal.welch #760

Open
NyankoSong opened this issue Jul 8, 2024 · 0 comments
Labels

Comments

@NyankoSong
Copy link

Hello!

I noticed that the PSD calculated using pywt.cwt with the cmor2.5-1 wavelet is lower than the results obtained using scipy.signal.welch and pycwt.cwt with the morlet wavelet. Due to my limited knowledge in spectral analysis, I am unable to determine the source of this discrepancy.

Any insights or explanations would be greatly appreciated. Thank you!

Data: Ey.csv

import scipy
freq_Ey_welch, psd_Ey_welch = scipy.signal.welch((Ey-Ey.mean()).values.flatten(), fs=1/np.mean(np.diff(Ey.index.to_pydatetime())).total_seconds(), nperseg=len(Ey)/10, scaling='density', average='median')

import pywt
wavelet='cmor2.5-1'
scales = lambda x: 10**np.linspace(np.log10(x.shape[0]/2), np.log10(2), 100)
cwtmatr_Ey, freq_Ey_cwt = pywt.cwt((Ey-Ey.mean()).values.flatten(), scales=scales(Ey), wavelet=wavelet, sampling_period=np.mean(np.diff(Ey.index.to_pydatetime())).total_seconds(), method='fft')
psd_Ey_cwt = np.mean(abs(cwtmatr_Ey)**2, axis=1)*np.mean(np.diff(Ey.index.to_pydatetime())).total_seconds()

import pycwt
wave_Ey, period_Ey, scale_Ey, coi_Ey, fft_Ey, fftfreq_Ey = pycwt.cwt((Ey-Ey.mean()).values.flatten(), np.mean(np.diff(Ey.index.to_pydatetime())).total_seconds(), dj=0.01, wavelet='morlet')
psd_Ey_pycwt = (np.mean(abs(wave_Ey)**2, axis=1)*np.mean(np.diff(Ey.index.to_pydatetime())).total_seconds())[::-1]
freq_Ey_pycwt = 1/period_Ey[::-1]

Comparison Graph

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants