Complex Operation Library

By using the complex operation library, you can perform operations of complex numbers.

Data of the complex type

In the complex operation library, you can use the complex type (Complex) as a data type. Data of the complex type consists of a real part (.real) and an imaginary part (.imag) as shown in the following example.

Dim Num as Complex
Num.real=1.0
Num.imag=2.0

List of procedures

The following table lists the procedures included in the complex operation library.

Procedure name

Function

ComplexSet(x,y)

Sets a complex number.
(Specify a real part and an imaginary part.)

ComplexPolar(x,y)

Sets a complex number.
(Specify an absolute value and a phase angle.)

ComplexSetArray(x)

Converts a variant type or double floating point type array to a complex type array.

ComplexAdd(x,y)

Returns the result of the addition.

ComplexSub(x,y)

Returns the result of the subtraction.

ComplexMul(x,y)

Returns the result of the multiplication.

ComplexDiv(x,y)

Returns the result of the division.

ComplexAbs(x)

Returns the absolute value.

ComplexArg(x)

Returns the phase angle.

ComplexNorm(x)

Returns the square of the absolute value.

ComplexConj(x)

Returns the conjugate complex number.

ComplexCos(x)

Returns the cosine.

ComplexCosh(x)

Returns the hyperbolic cosine.

ComplexSin(x)

Returns the sine.

ComplexSinh(x)

Returns the hyperbolic sine.

ComplexExp(x)

Returns ex.

ComplexLog(x)

Returns the natural logarithm.

ComplexLog10(x)

Returns the common logarithm.

ComplexSqrt(x)

Returns the square root.

Sample Program

:

:

 

Dim Dmy As Long

Dim s21_raw As Variant

Dim s31_raw As Variant

Dim s21_Comp As Complex

Dim s31_Comp As Complex

Dim trAce_ratio_comp As Complex

Dim trAce_ratio(401) As Double

 

SCPI.DISPlay.Split = "D1"

SCPI.DISPlay.WINDow(1).Split = "D12_34"

SCPI.CALCulate(1).PARameter.Count = 2

SCPI.CALCulate(1).PARameter(1).DEFine = "s21"

SCPI.CALCulate(1).PARameter(2).DEFine = "s31"

SCPI.SENSe(1).SWEep.POINts = 201

 

:

:

:

 

SCPI.TRIGger.SEQuence.Source = "bus"

SCPI.TRIGger.SEQuence.SINGle

Dmy = SCPI.IEEE4882.OPC

 

'''' Get corrected data array

SCPI.CALCulate(1).PARameter(1).SELect

s21_raw = SCPI.CALCulate(1).SELected.DATA.SDATa

SCPI.CALCulate(1).PARameter(2).SELect

s31_raw = SCPI.CALCulate(1).SELected.DATA.SDATa

 

For i = 0 To 200

 

'''' Copy corrected data array to the complex data array

'''' to take advantage of complex operation library

s21_Comp = ComplexSet(s21_raw(2 * i), s21_raw(2 * i + 1))

s31_Comp = ComplexSet(s31_raw(2 * i), s31_raw(2 * i + 1))

 

'''' Calculate the ratio of S31 and S21

'''' S31/S21

trAce_ratio_comp = ComplexDiv(s31_Comp, s21_Comp)

 

trAce_ratio(2 * i) = trAce_ratio_comp.real

trAce_ratio(2 * i + 1) = trAce_ratio_comp.imag

 

Next i

 

SCPI.CALCulate(1).PARameter.Count = 4

 

'''' Write "S31/S21" data to corrected data array for the trace 3 (LogMag)

SCPI.CALCulate(1).PARameter(3).SELect

SCPI.CALCulate(1).SELected.Format = "MLOG"

SCPI.CALCulate(1).SELected.DATA.SDATa = trAce_ratio

 

'''' Write "S31/S21" data to corrected data array for the trace 4 (Phase)

SCPI.CALCulate(1).PARameter(4).SELect

SCPI.CALCulate(1).SELected.Format = "PHASe"

SCPI.CALCulate(1).SELected.DATA.SDATa = trAce_ratio

 

:

: