FFT

(Engine-Level Function)

Description: Performs a fast Fourier transform between time and frequency domains.
Returns: Numeric
Usage: Script only.
Function Groups: Generic Math
Related to: ArrayOp1 | ArrayOp2
Format: FFT(Array, N, Operation)
Parameters:  
Array
Required. The starting array element. Array may contain time domain samples, complex frequency samples, or amplitude/phase pair samples. Any data passed to FFT in Array will be overwritten by the resulting transform. Arrays may be copied using ArrayOp2 if it is necessary to retain an original. There must be at least N elements in Array (partial transforms are not possible).
N
Required. Any numeric expression giving the number of elements in Array to transform. N must be a positive power of 2 in the range 4 to 4096.
Operation 
Required. Any numeric expression giving the type of transform as follows:

Operation

Transform Type

0

Time samples to frequency complex

1

Time samples to frequency amplitude/phase

2

Time samples to frequency amplitude only

3

Frequency complex to time samples

4

Frequency amplitude/phase to time samples

Note that Operation 2 will set all phase elements to 0 to indicate a loss of phase information. This transform is not reversible because of this loss of phase information.

Comments:

This statement is useful for performing frequency analysis on analog signals (such as motor frequency). In the time domain equal sampling intervals are required, equal frequency spacing in the frequency domain is required. The order of the time domain samples is in chronological order.
The order of complex frequency data is...

real 0, real N/2, real 1, imaginary 1, real 2, imaginary 2, ..., real N/2-1, imaginary N/2-1

Real 0 is the average (D.C.) component in the signal. The second element, real N/2, is the last real component because real 0 and real N/2 are always real (no imaginary component). Real 1 is the real amplitude of the lowest frequency, and imaginary 1 is the imaginary amplitude of the lowest frequency. Real N/2-1 and imaginary N/2-1 are the real and imaginary components of the second highest frequency.

The order of amplitude/phase pairs in Array is:

amplitude 0, amplitude 1, ..., amplitude N/2, phase 1, phase 2, ..., phase N/2 - 1

Amplitude 0 is the average (D.C.) component in the signal. Amplitude 1 is the amplitude of the lowest frequency, amplitude N/2 is the amplitude of the highest frequency. Phase 1 is the phase angle (in radians) of the lowest frequency (the average doesn't have a phase, its frequency is 0). Phase N/2-1 is the phase angle of the second highest frequency.

Note that neither the average (D.C.) component nor the highest frequency have a phase angle or imaginary component. The highest frequency and the sampling is:

fc = 1/2Δ

Where fc is the critical (highest) frequency in Hertz, and Δ is the sampling interval in seconds. The lowest frequency, the number of samples, and the sampling interval are related by the following equation:

fL = 1/NΔ

Where fL is the lowest frequency in Hertz, N is the number of samples, and Δ is the sampling interval in seconds.

All other frequencies are multiplies of the lowest frequency fL.

Caution should be taken, as when VTScada executes a script, no other statements are updated. The FFT statement may take several seconds to execute, depending on the computer and the number of samples. The computation time goes up by N * log2N.

Example:

  If 1 Main;
  [
    FFT(samples[0], 512, 1); 
  ]

Before this statement executes, samples[0] to samples[511] contain the equally spaced time samples of a signal, which will be overwritten by their amplitude/phase transform. After this statement executes, samples[0] will contain the average (D.C.) component of the signal. Samples[1] is the amplitude of fL, the lowest frequency component. Samples[256] is the amplitude of fc, the highest frequency component. Samples[257] will be the phase angle (in radians) of fL. Samples[511] will be the phase angle of fc.