This is a follow up of my previous question Why is inverse CWT inexact / inaccurate?
Rephrasing its accepted answer in my own words:
- The filterbank's transfer function gives information on what band of frequency is well represented using CWT. In my case, an important part of the spectrum lied in the not-so-well-reconstructed region (low frequencies).
- A quick fix for better reconstruction is to remove this part of the spectrum using regular FFT, and the other part can then be accurately reconstructed via CWT.
x_meanargument implements exactly this, only considering the 0 frequency. Your fix is a generalization of this trick
What I mean by generalization is exemplified in the following code (adapted from the answer):
import numpy as np from numpy.fft import rfft, irfft import matplotlib.pyplot as plt from ssqueezepy import cwt, icwt, Wavelet, padsignal from ssqueezepy.visuals import plot, plotscat wavelet = Wavelet('gmw') nv = 16 n = 100 t = np.linspace(0.,1.,n) x = np.sin(10*t*t) n_cutoff = 3 xf = rfft(x) xf_low = np.copy(xf) xf_low[n_cutoff:] = 0 xf_high = np.copy(xf) xf_high[:n_cutoff] = 0 x_high = irfft(xf_high) x_low = irfft(xf_low) Wx, scales = cwt(x_high, wavelet=wavelet, nv=nv, padtype=None) x_high_inv = icwt(Wx, wavelet=wavelet, scales=scales, nv=nv) x_inv = x_low + x_high_inv plot(x, color='b') plot(x_inv, color='r', title="xadj, xadj_inv | MSE=%.3e" % np.mean((x-x_inv)**2)) plt.show()
n_cutoff = 0 is exactly what I strated with (only the mean is being reconstructed), higher values let me treat a larger part of the spectrum independently.
My question is, is my understanding of the referenced answer correct?