user124e
user124e

Reputation: 1

How to get a scaleogram from wavelets

I am trying to plot a scaleogram based on all of my wavelet coefficients, but nothing seems to work.

My coefficients:

current wavelet coefficients

my code:

import torch
import soundfile as sf
import pywt
import matplotlib.pyplot as plt
import numpy as np


file_path = 'audio.wav'


audio_data, sample_rate = sf.read(file_path)


if len(audio_data.shape) > 1:
   audio_data = np.mean(audio_data, axis=1)


audio_tensor = torch.tensor(audio_data)


wavelets = 'db4'
coeffs = pywt.wavedec(audio_tensor.numpy(), wavelets, level=5)


coeffs_torch = [torch.tensor(c) for c in coeffs]


plt.figure(figsize=(12, 8))


plt.subplot(len(coeffs_torch) + 1, 1, 1)
plt.plot(audio_tensor.numpy())
plt.title("Original Audio Signal")


for i, coeff in enumerate(coeffs_torch):
   plt.subplot(len(coeffs_torch) + 1, 1, i + 2)
   plt.plot(coeff.numpy())
   plt.title(f'Wavelet Coefficients - Level {i+1}')






plt.tight_layout()
plt.show()

I tried to change my wavelet function from a discrete to a continuous transformation but it won't run. Any help would be appreciated

Upvotes: 0

Views: 34

Answers (0)

Related Questions