0
$\begingroup$

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.
  • The x_mean argument 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()

Setting 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?

$\endgroup$
2
  • $\begingroup$ Try not to address / "speak to" specific users in your question; use third-person or focus on subject alone for StackExchange. $\endgroup$ Commented Mar 17, 2023 at 14:53
  • 1
    $\begingroup$ Noted, edited ! $\endgroup$ Commented Mar 17, 2023 at 14:57

1 Answer 1

1
$\begingroup$

It's all correct, but remarks:

  • It's a "hack" not a "fix" to zero input's frequencies, that I did only for a quick demo; you should not do this, it's (1) throwing away information; (2) has bad effects on signal
  • x_mean is needed since CWT can never capture the mean; wavelets are zero-mean by definition (sometimes this is relaxed but it's a bad idea for most purposes)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.