tftb icon indicating copy to clipboard operation
tftb copied to clipboard

WignerVillerDistriubtion crashes for different signal lenghts

Open chapochn opened this issue 3 years ago • 3 comments

Hello,

This crashes:

import tftb
import numpy as np
signal = np.zeros(13)
wvd = tftb.processing.WignerVilleDistribution(signal)
wvd.run()

and gives: Traceback (most recent call last): File "", line 3, in File "/Users/[...]/opt/anaconda3/envs/tftb/lib/python3.8/site-packages/tftb/processing/cohen.py", line 165, in run self.tfr[tausec, icol] = self.signal[icol + tausec, 0] *
IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed

but this doesn't

import tftb
import numpy as np
signal = np.zeros(12)
wvd = tftb.processing.WignerVilleDistribution(signal)
wvd.run()

Is there are reason for that?

chapochn avatar Feb 26 '21 21:02 chapochn

Thanks for pointing this out, @chapochn - I'll check it out.

jaidevd avatar Mar 02 '21 05:03 jaidevd

Hi all,

Dealing with the same issue. I believe it is due to the logic in the if statement ported from Matlab. Please correct me if I'm wrong, but it seems pytftb ravels() the input signal. If so, then indexing into the second dimension is a leftover from Matlab where the input array has shape [xrow, xcol]. When calculating the auto-WVD xcol will be 1 in Matlab, and for pytftb it will always be one (technically it is squeezed out). So we can fully drop the second indexing.

I believe the logic of the if statement also needs a check. It is a copy of the Matlab logic which introduces the classic/annoying off-by-one error since Matlab indexes start from one. After changing the logic as follows:

Change from this: if (icol <= self.signal.shape[0] - tausec) and (icol >= tausec + 1) To this: if (icol <= self.signal.shape[0] - tausec - 1) and (icol >= tausec)

I avoid any boundary issues.

Lastly (sorry if adding too much here...) we are missing a factor of 1/2 inside the loop:

self.tfr[tausec, icol] = 0.5 * (self.signal[icol + tausec] * \ np.conj(self.signal[icol - tausec]) + \ self.signal[icol - tausec] * conj_signal[icol + tausec])

Thank you!

enzokro avatar Sep 30 '21 21:09 enzokro

For whatever reason, I only seem to encounter this error when the signal length is a prime number greater than 128.

ajmuelle avatar Sep 22 '22 15:09 ajmuelle