# FFT
# Usage
This function is used to calculate the fast Fourier transform (FFT) of a numerical series.
Name: FFT
Input: Only support a single input series. The type is INT32 / INT64 / FLOAT / DOUBLE.
Parameters:
type
: The type of FFT, which is 'uniform' (by default) or 'nonuniform'. If the value is 'uniform', the timestamps will be ignored and all data points will be regarded as equidistant. Thus, the equidistant fast Fourier transform algorithm will be applied. If the value is 'nonuniform' (TODO), the non-equidistant fast Fourier transform algorithm will be applied based on timestamps.result
: The result of FFT, which is 'real', 'imag', 'abs' or 'angle', corresponding to the real part, imaginary part, magnitude and phase angle. By default, the magnitude will be output.nfft
: The number of points for FFT, which is a positive integer. By default, all input points are used in FFT.compress
: The parameter of compression, which is within (0,1]. It is the reserved energy ratio of lossy compression. By default, there is no compression.
Output: Output a single series. The type is DOUBLE. The length is the same as the input. The timestamps starting from 0 only indicate the order.
Note: NaN
in the input series will be ignored.
# Examples
# Uniform FFT
With the default type
, uniform FFT is applied.
Input series:
+-----------------------------+---------------+
| Time|root.test.d1.s1|
+-----------------------------+---------------+
|1970-01-01T08:00:00.000+08:00| 2.902113|
|1970-01-01T08:00:01.000+08:00| 1.1755705|
|1970-01-01T08:00:02.000+08:00| -2.1755705|
|1970-01-01T08:00:03.000+08:00| -1.9021131|
|1970-01-01T08:00:04.000+08:00| 1.0|
|1970-01-01T08:00:05.000+08:00| 1.9021131|
|1970-01-01T08:00:06.000+08:00| 0.1755705|
|1970-01-01T08:00:07.000+08:00| -1.1755705|
|1970-01-01T08:00:08.000+08:00| -0.902113|
|1970-01-01T08:00:09.000+08:00| 0.0|
|1970-01-01T08:00:10.000+08:00| 0.902113|
|1970-01-01T08:00:11.000+08:00| 1.1755705|
|1970-01-01T08:00:12.000+08:00| -0.1755705|
|1970-01-01T08:00:13.000+08:00| -1.9021131|
|1970-01-01T08:00:14.000+08:00| -1.0|
|1970-01-01T08:00:15.000+08:00| 1.9021131|
|1970-01-01T08:00:16.000+08:00| 2.1755705|
|1970-01-01T08:00:17.000+08:00| -1.1755705|
|1970-01-01T08:00:18.000+08:00| -2.902113|
|1970-01-01T08:00:19.000+08:00| 0.0|
+-----------------------------+---------------+
SQL for query:
select fft(s1) from root.test.d1
Output series:
+-----------------------------+----------------------+
| Time| fft(root.test.d1.s1)|
+-----------------------------+----------------------+
|1970-01-01T08:00:00.000+08:00| 0.0|
|1970-01-01T08:00:00.001+08:00| 1.2727111142703152E-8|
|1970-01-01T08:00:00.002+08:00| 2.385520799101839E-7|
|1970-01-01T08:00:00.003+08:00| 8.723291723972645E-8|
|1970-01-01T08:00:00.004+08:00| 19.999999960195904|
|1970-01-01T08:00:00.005+08:00| 9.999999850988388|
|1970-01-01T08:00:00.006+08:00| 3.2260694930700566E-7|
|1970-01-01T08:00:00.007+08:00| 8.723291605373329E-8|
|1970-01-01T08:00:00.008+08:00| 1.108657103979944E-7|
|1970-01-01T08:00:00.009+08:00| 1.2727110997246171E-8|
|1970-01-01T08:00:00.010+08:00|1.9852334701272664E-23|
|1970-01-01T08:00:00.011+08:00| 1.2727111194499847E-8|
|1970-01-01T08:00:00.012+08:00| 1.108657103979944E-7|
|1970-01-01T08:00:00.013+08:00| 8.723291785769131E-8|
|1970-01-01T08:00:00.014+08:00| 3.226069493070057E-7|
|1970-01-01T08:00:00.015+08:00| 9.999999850988388|
|1970-01-01T08:00:00.016+08:00| 19.999999960195904|
|1970-01-01T08:00:00.017+08:00| 8.723291747109068E-8|
|1970-01-01T08:00:00.018+08:00| 2.3855207991018386E-7|
|1970-01-01T08:00:00.019+08:00| 1.2727112069910878E-8|
+-----------------------------+----------------------+
Note: The input is
# Uniform FFT with Compression
Input series is the same as above, the SQL for query is shown below:
select fft(s1, 'result'='real', 'compress'='0.99'), fft(s1, 'result'='imag','compress'='0.99') from root.test.d1
Output series:
+-----------------------------+----------------------+----------------------+
| Time| fft(root.test.d1.s1,| fft(root.test.d1.s1,|
| | "result"="real",| "result"="imag",|
| | "compress"="0.99")| "compress"="0.99")|
+-----------------------------+----------------------+----------------------+
|1970-01-01T08:00:00.000+08:00| 0.0| 0.0|
|1970-01-01T08:00:00.001+08:00| -3.932894010461041E-9| 1.2104201863039066E-8|
|1970-01-01T08:00:00.002+08:00|-1.4021739447490164E-7| 1.9299268669082926E-7|
|1970-01-01T08:00:00.003+08:00| -7.057291240286645E-8| 5.127422242345858E-8|
|1970-01-01T08:00:00.004+08:00| 19.021130288047125| -6.180339875198807|
|1970-01-01T08:00:00.005+08:00| 9.999999850988388| 3.501852745067114E-16|
|1970-01-01T08:00:00.019+08:00| -3.932894898639461E-9|-1.2104202549376264E-8|
+-----------------------------+----------------------+----------------------+
Note: Based on the conjugation of the Fourier transform result, only the first half of the compression result is reserved. According to the given parameter, data points are reserved from low frequency to high frequency until the reserved energy ratio exceeds it. The last data point is reserved to indicate the length of the series.