scikit-signal / tftb

A Python module for time-frequency analysis
261 stars 56 forks source link

1j ? #148

Closed merl-dev closed 7 years ago

merl-dev commented 7 years ago

Quite a few methods in frequency_modulated.py contain np.exp(1j * ... And I noticed this in the mfiles of the origina tftb source. Where is j defined? Did I miss something?

jaidevd commented 7 years ago

@merl-dev j isn't a variable. In Python, 1j represents the root of -1. So you can do the following in Python:

>>> 1j
1j
>>> x = 3 + 4j
>>> abs(x)
5.0
>>> type(x)
<class 'complex'>

Actually, any scalar coefficient $c$ followed by j represents that coefficient times the root of -1 (Notice the 4j in the snippet above). If you were to just type j, then Python would complain that the variable isn't defined.

>>> j
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'j' is not defined

HTH

merl-dev commented 7 years ago

lol... sorry it should have clicked! Thanks for your quick response.

jaidevd commented 7 years ago

Oh, turns out that the same is true in MATLAB too, except MATLAB also allows i.

merl-dev commented 7 years ago

I'm starting a Julia port of the tftb... Julia uses im:

The global constant im is bound to the complex number i, representing the principal square root of -1. It was deemed harmful to co-opt the name i for a global constant, since it is such a popular index variable name.

I guess I fell into that hole being less familiar Python and having not written any Matlab in years

jaidevd commented 7 years ago

Wow, are you hosting it on your GitHub profile?

merl-dev commented 7 years ago

It will be once I've completed the core and tests, should take a week or so as I am also traveling