signal

The DolphinDB signal plugin integrates the powerful and high-performance FFTW3 (Fastest Fourier Transform in the West), offering convenient and efficient Fourier transform computations. This plugin includes various signal processing functions, such as discrete sine transform (DST), discrete cosine transform (DCT), and discrete wavelet transform (DWT). Users can load this plugin in DolphinDB and utilize these signal-processing features.

Installation (with installPlugin)

Required server version: DolphinDB 2.00.10 or higher.

Supported OS: Linux x86.

Installation Steps:

(1) Use listRemotePlugins to check plugin information in the plugin repository.

Note: For plugins not included in the provided list, you can install through precompiled binaries or compile from source. These files can be accessed from our GitHub repository by switching to the appropriate version branch.

login("admin", "123456")
listRemotePlugins(, "http://plugins.dolphindb.com/plugins/")

(2) Invoke installPlugin for plugin installation.

installPlugin("signal")

(3) Use loadPlugin to load the plugin before using the plugin methods.

loadPlugin("signal")

Method References

dct

Syntax

dct(X)

Details

The method performs a DCT and returns a DOUBLE sequence of the same length as the input vector.

Parameters

  • X: An INT or DOUBLE vector indicating the input discrete signal sequence.

dst

Syntax

dst(X)

Details

The method performs a DST and returns a DOUBLE sequence of the same length as the input vector.

Parameters

  • X: An INT or DOUBLE vector indicating the input discrete signal sequence.

dwt

Syntax

dwt(X)

Details

The method performs a 1-D DWT and returns a table containing two columns: cA and cD. cA denotes the approximation coefficients, and cD represents the detail coefficients.

Parameters

  • X: An INT or DOUBLE vector indicating the input discrete signal sequence.

idwt

Syntax

idwt(X,Y)

Details

The method performs an inverse transformation on cA and cD and returns the signal sequence.

Parameters

  • X: An INT or DOUBLE vector indicating cA (approximation coefficients).
  • Y: An INT or DOUBLE vector indicating cD (detail coefficients).

dctParallel

Syntax

dctParallel(ds)

Details

The method performs the DCT with distributed implementation and returns the transformed sequence. Due to the potential high system load from multi-threaded parallel computing, avoid using it in multi-threaded environments.

Parameters

  • ds: A tuple of data sources indicating the input discrete signal sequence. ds, which can be returned by the sqlDS function, includes several partitions distributed across multiple controllers.

fft

Syntax

fft(X,[n,norm])

Details

The method performs a 1-D FFT (Fast Fourier Transform) and returns a complex vector of length n.

Parameters

  • X: A real or complex vector indicating the data to be transformed.
  • n (optional): An INT scalar indicating the length of the output vector. The default length is X.
  • norm (optional): A STRING scalar indicating the normalization mode. It can take the following values:
    • "backward" (default): No normalization.
    • "forward": Multiply the result by 1/n.
    • "ortho": Multiply the result by 1/sqrt(n).

fft!

Syntax

fft!(X,[n,norm])

Details

The method performs a 1-D FFT (Fast Fourier Transform). Note that the only difference between fft and fft! is that the latter operates in-place, directly modifying the input X. This only occurs when X is a complex vector and its length is not less than n.

Parameters

Refer to fft.

ifft

Syntax

ifft(X,[n,norm])

Details

The method performs a 1-D IFFT (Inverse Fast Fourier Transform) and returns a complex vector of length n.

Parameters

  • X: A real or complex vector indicating the data to be transformed.
  • n (optional): An INT scalar indicating the length of the output vector. The default length is X.
  • norm (optional): A STRING scalar indicating the normalization mode. It can take the following values:
    • "backward" (default): No normalization.
    • "forward": Multiply the result by 1/n.
    • "ortho": Multiply the result by 1/sqrt(n).

ifft!

Syntax

ifft!(X,[n,norm])

Details

The method performs a 1-D IFFT (Inverse Fast Fourier Transform). Note that the only difference between ifft and ifft! is that the latter operates in-place, directly modifying the input X. This only occurs when X is a complex vector and its length is not less than n.

Parameters

Refer to ifft.

fft2

Syntax

fft2(X,[s,norm])

Details

The method performs a 2-D FFT (Fast Fourier Transform) and returns a complex matrix.

Parameters

  • X: A real or complex matrix indicating the data to be transformed.
  • s (optional): A two-element vector containing integers that specify the dimension of the output matrix, with the first element indicating the number of rows and the second element indicating the number of columns. The default dimension is X×X.
  • norm (optional): A STRING scalar indicating the normalization mode. It can take the following values:
    • "backward" (default): No normalization.
    • "forward": Multiply the result by 1/n (n is the number of elements in the matrix).
    • "ortho": Multiply the result by 1/sqrt(n).

fft2!

Syntax

fft2!(X,[s,norm])

Details

The method performs a 2-D FFT (Fast Fourier Transform). Note that the only difference between fft2 and fft2! is that the latter operates in-place, directly modifying the input X. This only occurs when X is a complex vector and its length is not less than s.

Parameters

Refer to fft2.

ifft2

Syntax

ifft2(X,[s,norm])

Details

The method performs a 2-D IFFT (Inverse Fast Fourier Transform) and returns a complex matrix.

Parameters

  • X: A real or complex matrix indicating the data to be transformed.
  • s (optional): A two-element vector containing integers that specify the dimension of the output matrix, with the first element indicating the number of rows and the second element indicating the number of columns. The default dimension is X×X.
  • norm (optional): A STRING scalar indicating the normalization mode. It can take the following values:
    • "backward" (default): No normalization.
    • "forward": Multiply the result by 1/n (n is the number of elements in the matrix).
    • "ortho": Multiply the result by 1/sqrt(n).

ifft2!

Syntax

ifft2!(X,[s,norm])

Details

The method performs a 2-D IFFT (Inverse Fast Fourier Transform). Note that the only difference between ifft2 and ifft2! is that the latter operates in-place, directly modifying the input X. This only occurs when X is a complex vector and its length is not less than s.

Parameters

Refer to ifft2.

secc

Syntax

secc(data,template,k,[moveout,weight])

Details

The method performs waveform cross-correlation of data and each column of *template. *It returns a matrix with n columns and m rows.

Parameters

  • data: A 1-D real vector of length l, indicating the waveform data.
  • template: A real-valued matrix with dimensions m×n, where each of the n columns represents a waveform segment of length m. Note that m must be no greater than the length l of data.
  • k: An INT scalar. It must be at least 2*m and is recommended to be a power of 2.
  • moveout (optional): A DOUBLE vector of length n, indicating time delays. The default value is 0.
  • weight (optional): A DOUBLE vector of length n, indicating weights. The default value is 1.

abs

Syntax

abs(data)

Details

The method calculates the magnitude of complex numbers.

  • If data is a scalar, it returns a DOUBLE scalar.
  • If data is a vector, it returns a DOUBLE vector.

Parameters

  • data: A complex scalar or vector indicating the data to be calculated.

mul

Syntax

mul(data, num)

Details

The method performs multiplication on complex numbers. The result retains the same format as the input data.

Parameters

  • data: A complex scalar or vector indicating the data to be multiplied.
  • num: A DOUBLE scalar indicating the multiplier.

Usage Examples

Example 1. Discrete cosine transform

X = [1,2,3,4]
signal::dct(X)
// output: [5,-2.23044235292127,-2.411540739456585E-7,-0.15851240125353]

Example 2. Discrete sine transform

X = [1,2,3,4]
signal::dst(X)
// output: [15.388417979126893,-6.88190937668141,3.632712081813623,-1.624597646358306]

Example 3. Discrete wavelet transform

X = [1,2,3]
signal::dwt(X)
// output:
cA                cD                
----------------- ------------------
2.121320343559643 -0.707106781186548
4.949747468305834 -0.707106781186548

Example 4. Inverse discrete wavelet transform

X = [2.121320343559643,4.949747468305834]
Y = [-0.707106781186548,-0.707106781186548]
signal::dwt(x,y)
// output: [1,2,3.000000000000001,4.000000000000001]

Example 5. DctParallel

f1=0..9999
f2=1..10000
t=table(f1,f2)
db = database("dfs://rangedb_data", RANGE, 0 5000 10000)
signaldata = db.createPartitionedTable(t, "signaldata", "f1")
signaldata.append!(t)
signaldata=loadTable(db,"signaldata")
ds=sqlDS(<select * from signaldata >)
loadPlugin("/path/to/PluginSignal.txt")
use signal
signal::dctParallel(ds);

Example 6. Fast Fourier transform

X = [1,2,3,4]
signal::fft(X);
// output: [10+0i,-2+2i,-2+0i,-2-2i]

Example 7. Inverse fast Fourier transform

X = [1,2,3,4]
signal::ifft(X);
// output: [2.5+0i,-0.5-0.5i,-0.5+0i,-0.5+0.5i]

Example 8. 2-D fast Fourier transform

X = matrix([1,2,3,4],[4,3,2,1])
signal::fft2(X);
// output: 
#0    #1   
----- -----
20+0i 0+0i 
0+0i  -4+4i
0+0i  -4+0i
0+0i  -4-4i

Example 9. 2-D inverse fast Fourier transform

X = matrix([1,2,3,4],[4,3,2,1])
signal::ifft2(X);
// output: 
#0     #1       
------ ---------
2.5+0i 0+0i     
0+0i   -0.5-0.5i
0+0i   -0.5+0i  
0+0i   -0.5+0.5i

Example 10. Super‐efficient cross‐correlation

x=[1, 2, 1, -1, 0, 3];
y=matrix([1,3,2],[4,1,5]);
signal::secc(x,y,4);
// output: 
#0                 #1               
------------------ -----------------
0.981980506061966  0.692934867183583
0.327326835353989  0.251976315339485
-0.377964473009227 0.327326835353989
0.422577127364258  0.536745040121693