tftb
tftb copied to clipboard
WignerVillerDistriubtion crashes for different signal lenghts
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
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?
Thanks for pointing this out, @chapochn - I'll check it out.
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!
For whatever reason, I only seem to encounter this error when the signal length is a prime number greater than 128.