Can this library do the inverse CWT?
This would be super handy for audio processing
Not yet, will add it to the list. Are there more people that need this feature?
An ICWT would be very helpful for my research!
yes would be very handy
I see there is great interest in a fast inverse CWT. In #36, I mentioned the difficulties with implementing an inverse CWT, however I will put it on my list for the next major update. Thank you for showing your interest.
Yes it would also help me very much !
Side note, do any of you know any sound processing in the wavelet domain ? If existing in python, it would be fontastic to use with neutone AI audio plugin.
It will be very helpful!
My research is ML which makes CWT data(image) If the fast ICWT exists, I will be able to put it in the learning loop, so I will have a chance to step further.
inverse fcwt will be very helpful ~~~~l
Agreed, I'm also interested in performing the inverse too! Thanks for this great tool!
Likewise, would be interested in the implementation of inverse fCWT.
I've been tinkering a bit to see whether an inverse fCWT was possible and it is actually very easy! I'm still planning to implement this in the next version, but due to other priorities in my PhD, this update is being postponed constantly.
For now, you can sum all real valued rows of the time frequency matrix (wavelet coefficient matrix):
signal = np.real(tfm).sum(axis=0)
Note that we are not normalizing anything yet, so this is not correct if you are really interested in the absolute amplitudes of the signal. However, if you are planning to normalize the signal anyway, this could be a straightforward solution!
The frequency distribution of the reconstructed signal isn't right. Too much high frequency. The quality is great though! Any idea how to correct this other than comparing them and applying an inverse filter?
import fcwt
import numpy as np
import librosa
import matplotlib.pyplot as plt
import soundfile as sf
from scipy.signal import freqz, firwin, lfilter
# Load the audio file
audio_file = "OS_SS_90_drum_loop_swagger.wav" # Replace with your audio file path
signal, fs = librosa.load(audio_file)
f0 = 10 # lowest frequency
f1 = 20000 # highest frequency
fn = 1000 # number of frequencies
# Calculate CWT without plotting...
freqs, out = fcwt.cwt(signal, fs, f0, f1, fn)
new_signal = np.real(out).sum(axis=0)
# Analyze the frequency response
w, h_orig = freqz(signal)
_, h_recon = freqz(new_signal)
# Calculate frequency responses and plot them
w_normalized = w / np.pi * (fs / 2) # Convert to Hz
plt.figure(figsize=(10, 6))
plt.plot(w_normalized, 20 * np.log10(np.abs(h_orig)), label="Original")
plt.plot(w_normalized, 20 * np.log10(np.abs(h_recon)), label="Reconstructed")
plt.xlabel("Frequency [Hz]")
plt.ylabel("Magnitude [dB]")
plt.legend()
plt.grid(True)
plt.show()
Rescaling the output with the inverse of the frequency seems to be mostly correct. Not sure why.
freqs, out = fcwt.cwt(signal, fs, f0, f1, fn)
spectrum = np.real(out)
# rescale spectrum
spectrum *= 1 / (freqs[:, np.newaxis] + 1)
# inverse CQT
new_signal = spectrum.sum(axis=0)
# normalise
new_signal /= np.max(np.abs(new_signal))