admin管理员组

文章数量:1279144

I'm trying to perform 6th wavelet transform with python, using libraries as numpy,pandas, matplotlib, pywt (image 1). But I can't do something similar to the graph (image 2) Please, can someone help me? image 1image 2

import numpy as np
import matplotlib.pyplot as plt
import pywt
import pandas as pd


df=pd.read_csv('441664609_22_PDCSAP_SC6.dat',sep=' ',header=None).dropna()
x = df[0]
y = df[1]



def wavelet_transform(x, y):
    
    x1 = np.linspace(min(x), max(x), len(x))
    

    wavelet = 'cmor6-1.5'
    
    
    scales = np.logspace(np.log10(2), np.log10(len(x)//2), num=50)
    
    
    coefficients, freq = pywt.cwt(y, scales, wavelet, sampling_period=np.mean(np.diff(x1)))
    
   
    power = np.abs(coefficients) ** 2

    periods = 1 / freq
    return x1, freq, power, time



time, periods, power, freq = wavelet_transform(x, y)


plt.figure(figsize=(10, 6))
plt.imshow(power, aspect='auto', extent=[time[0], time[-1], periods[-1], periods[0]], cmap='jet')
plt.colorbar(label='Power')
plt.xlabel("Time")
plt.xlabel("Time (days)")
plt.yscale('log')
plt.title("Wavelet Power Spectrum")
plt.show()

I tried everything in the code (I guess), but I never can't do it right, seems so difficult...

本文标签: pythonI can39t do wavelet transformStack Overflow