Complex Numbers

 

SPL fully supports complex numbers. SPL defines the constant i to represent image\ebx_-1481668678.gif. For example:

 

x = 1 + 2i

 

y = .5 + i

 

x + y  returns: 1.5 + 3i

x * y  returns: -1.5 + 2i

 

a = {1, 2, 3, 4}

 

fft(a)

 

returns a complex series: {10+0i, -2+2i, -2+0i, -2-2i}

 

Since i defines a complex number, i cannot be used as a global variable. However, i can be declared as a local variable by using the local declaration:

 

ilocal(x)

{

    local a, i;

 

    for (i = 0; i < x; i++)

    {

        x * i;

    }

 

    return(a, a * 1i);

}

 

(a, b) = ilocal(10)

 

a == 90

b == 90i

 

In this case, DADiSP recognizes i as a local variable and 1i as image\ebx_-1481668678.gif. The details of the FOR loop will be described shortly.

 

SPL includes several functions for manipulating complex numbers:

 

 

Function

Description

REAL

Real part of complex number/series

IMAG

Imaginary part of a complex number/series

MAG

Magnitude of a complex number/series

PHASE

Angle of a complex number/series between - and

ANGLE

Angle of a complex number/series between 0 and

CONJ

Complex conjugate of series/number

POLAR

Convert from Cartesian to polar form

 

If an operation entails a combination of real and complex numbers, SPL assumes the imaginary part of the real number is zero.