当前位置:   article > 正文

python+连续小波变换(CWT)_pywt.cwt(y, scales, wavename, 1.0 / sr)

pywt.cwt(y, scales, wavename, 1.0 / sr)
  1. import librosa
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4. import pywt
  5. import librosa.display
  6. wav, sr_ret = librosa.load('E:\PycharmProjects\pythonProject\AudioClassification-Pytorch-master\dataset/audio/fold1/1_001.wav',sr=48000,duration=0.1)
  7. # 连续小波变换
  8. wavename = 'morl'
  9. totalscal = 4
  10. fc = pywt.central_frequency(wavename) # 计算小波函数的中心频率
  11. cparam = 2 * fc * totalscal # 常数c
  12. scales = cparam / np.arange(totalscal, 1, -1) # 为使转换后的频率序列是一等差序列,尺度序列必须取为这一形式(也即小波尺度)
  13. [cwtmatr, frequencies] = pywt.cwt(wav, scales, wavename, 1.0 / sr_ret)
  14. # scatter = Scattering2D(cwtmatr,frequencies)
  15. # features =(scatter,wav)
  16. # print(features.shape)
  17. features = np.array(cwtmatr)
  18. # frames = np.array(frames)
  19. # print(features.shape)
  20. # features = plt.contourf(t, frequencies, abs(cwtmatr))
  21. # features = librosa.stft(y=wav, n_fft=1024, hop_length=None, win_length=None, window='hann')
  22. # features = librosa.amplitude_to_db(np.abs(librosa.stft(y=wav,n_fft=1024, hop_length=None, win_length=None, window='hann')), ref=np.max)
  23. # features = librosa.melspectrogram(y=wav,sr=sr, n_fft=400, n_mels=80, hop_length=160, win_length=400)
  24. # features = librosa.power_to_db(features, ref=1.0, amin=1e-10, top_db=None)
  25. # 归一化
  26. mean = np.mean(features, 0, keepdims=True)
  27. std = np.std(features, 0, keepdims=True)
  28. features = (features - mean) / (std + 1e-5)
  29. features = features.astype('float32')
  30. print(features)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/336114
推荐阅读
相关标签
  

闽ICP备14008679号