Skip to content

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

Open
@NyankoSong

Description

@NyankoSong

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions