2023-11-02 20:37:07 +00:00
|
|
|
---
|
|
|
|
slug: /en/sql-reference/functions/time-series-functions
|
2023-11-07 19:56:34 +00:00
|
|
|
sidebar_position: 172
|
2023-11-02 20:37:07 +00:00
|
|
|
sidebar_label: Time Series
|
|
|
|
---
|
|
|
|
|
2023-11-09 21:16:38 +00:00
|
|
|
# Time Series Functions
|
2023-11-02 20:37:07 +00:00
|
|
|
|
2023-11-07 19:56:34 +00:00
|
|
|
Below functions are used for time series analysis.
|
2023-11-02 20:37:07 +00:00
|
|
|
|
2023-11-07 19:56:34 +00:00
|
|
|
## seriesPeriodDetectFFT
|
2023-11-02 20:37:07 +00:00
|
|
|
|
2023-11-07 19:56:34 +00:00
|
|
|
Finds the period of the given time series data using FFT
|
2023-12-14 16:34:37 +00:00
|
|
|
FFT - [Fast Fourier transform](https://en.wikipedia.org/wiki/Fast_Fourier_transform)
|
2023-11-02 20:37:07 +00:00
|
|
|
|
|
|
|
**Syntax**
|
|
|
|
|
|
|
|
``` sql
|
2023-11-07 19:56:34 +00:00
|
|
|
seriesPeriodDetectFFT(series);
|
2023-11-02 20:37:07 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
**Arguments**
|
|
|
|
|
|
|
|
- `series` - An array of numeric values
|
|
|
|
|
|
|
|
**Returned value**
|
|
|
|
|
|
|
|
- A real value equal to the period of time series
|
2023-12-08 15:10:47 +00:00
|
|
|
- Returns NAN when number of data points are less than four.
|
2023-11-02 20:37:07 +00:00
|
|
|
|
|
|
|
Type: [Float64](../../sql-reference/data-types/float.md).
|
|
|
|
|
|
|
|
**Examples**
|
|
|
|
|
|
|
|
Query:
|
|
|
|
|
|
|
|
``` sql
|
2023-11-07 19:56:34 +00:00
|
|
|
SELECT seriesPeriodDetectFFT([1, 4, 6, 1, 4, 6, 1, 4, 6, 1, 4, 6, 1, 4, 6, 1, 4, 6, 1, 4, 6]) AS print_0;
|
2023-11-02 20:37:07 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Result:
|
|
|
|
|
|
|
|
``` text
|
|
|
|
┌───────────print_0──────┐
|
|
|
|
│ 3 │
|
|
|
|
└────────────────────────┘
|
2023-11-09 21:16:38 +00:00
|
|
|
```
|
2023-12-11 16:43:40 +00:00
|
|
|
|
|
|
|
``` sql
|
|
|
|
SELECT seriesPeriodDetectFFT(arrayMap(x -> abs((x % 6) - 3), range(1000))) AS print_0;
|
|
|
|
```
|
|
|
|
|
|
|
|
Result:
|
|
|
|
|
|
|
|
``` text
|
|
|
|
┌─print_0─┐
|
|
|
|
│ 6 │
|
|
|
|
└─────────┘
|
|
|
|
```
|