luphysics / PyMODAlib

Python library containing the algorithms used by PyMODA.
GNU General Public License v3.0
5 stars 4 forks source link

Bispectral analysis #2

Open pavleb opened 3 years ago

pavleb commented 3 years ago

Checking from MODA, bispectral analysis can be implemented straightforward. In its calculation it relies on wavelet_transform.py. For two signals sig1 and sig2, the bispectral analysis requires spectra at frequencies so it becomes B(ω121 + ω2). When performing wavelet transform using wavelet_transform.py the frequencies at which the wavelet coefficients are calculated are selected using fmin and fmax as well as the number of voices nv.

However for bispectral analysis we need also frequencies that are sum of the pairs. What I suggest is the following:

Change the signature of the function wavelet_transform in wavelet_transform.py by adding new parameter sel_freqs = None. This would change two things how this function executes. If sel_freqs is set then the function will ignore fmin and fmax and calculate the wavelet transform at the provided list of frequencies. This is achieved with these two blocks:

if sel_freqs is not None:
      fmin = np.min(sel_freqs)
      fmax = np.max(sel_freqs)
      nv = len(sel_freqs)

and

if sel_freqs is not None:
      freq = sel_freqs
    else:
      freq = 2 ** (
        arange(ceil(nv * np.log2(fmin)), np.floor(nv * np.log2(fmax)) + 1).conj().T / nv
    )

By doing so, we can implement bispectral analysis in no time. I have a prototype working, I can push it in a new branch. I just wanted to double check with you whether such a signature change to wavelet_transform function is acceptable for you. It remains backwards compatible but for my taste it becomes cumbersome. Maybe, we can separate the frequency interval calculation as an auxiliary function and decouple the process.

Please let me know what do you think.

spmccormack commented 3 years ago

Sorry for the late reply, I'm a bit busy at the moment but I'll get back to you at the weekend. Looks like a good idea though, thanks for your time and effort!

spmccormack commented 3 years ago

Ok, sounds great! Feel free to push your branch and I'll be glad to take a look.