Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WignerVillerDistriubtion crashes for different signal lenghts #173

Open
chapochn opened this issue Feb 26, 2021 · 3 comments
Open

WignerVillerDistriubtion crashes for different signal lenghts #173

chapochn opened this issue Feb 26, 2021 · 3 comments
Assignees

Comments

@chapochn
Copy link

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 chapochn changed the title WignerVillerDistriubtion crashed signal lenghts WignerVillerDistriubtion crashes for different signal lenghts Feb 26, 2021
@jaidevd
Copy link
Member

jaidevd commented Mar 2, 2021

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

@enzokro
Copy link

enzokro commented Sep 30, 2021

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!

@jaidevd jaidevd self-assigned this Oct 1, 2021
@ajmuelle
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants