or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

array-creation.mdcuda-integration.mdcustom-kernels.mddata-types.mdextended-functionality.mdfft.mdindex.mdio-functions.mdlinear-algebra.mdlogic-functions.mdmathematical-functions.mdpolynomial.mdrandom.mdstatistics.mdutilities.md

fft.mddocs/

0

# Fast Fourier Transform

1

2

GPU-accelerated Fast Fourier Transform operations supporting 1D, 2D, and N-dimensional transforms for both complex and real data. Built on cuFFT library for high-performance frequency domain computations.

3

4

## Capabilities

5

6

### Standard FFTs

7

8

Complex-to-complex Fast Fourier Transforms.

9

10

```python { .api }

11

def fft(a, n=None, axis=-1, norm=None):

12

"""

13

Compute 1D discrete Fourier transform.

14

15

Parameters:

16

- a: array-like, input array

17

- n: int, length of transformed axis (zero-padded or truncated if needed)

18

- axis: int, axis over which to compute FFT

19

- norm: {None, 'ortho'}, normalization mode

20

21

Returns:

22

cupy.ndarray: Complex-valued FFT result

23

"""

24

25

def ifft(a, n=None, axis=-1, norm=None):

26

"""Compute 1D inverse discrete Fourier transform."""

27

28

def fft2(a, s=None, axes=(-2, -1), norm=None):

29

"""

30

Compute 2D discrete Fourier transform.

31

32

Parameters:

33

- a: array-like, input array

34

- s: tuple of ints, shape of result

35

- axes: tuple of ints, axes over which to compute FFT

36

- norm: {None, 'ortho'}, normalization mode

37

38

Returns:

39

cupy.ndarray: 2D FFT result

40

"""

41

42

def ifft2(a, s=None, axes=(-2, -1), norm=None):

43

"""Compute 2D inverse discrete Fourier transform."""

44

45

def fftn(a, s=None, axes=None, norm=None):

46

"""

47

Compute N-dimensional discrete Fourier transform.

48

49

Parameters:

50

- a: array-like, input array

51

- s: sequence of ints, shape of result

52

- axes: sequence of ints, axes over which to compute FFT

53

- norm: {None, 'ortho'}, normalization mode

54

55

Returns:

56

cupy.ndarray: N-D FFT result

57

"""

58

59

def ifftn(a, s=None, axes=None, norm=None):

60

"""Compute N-dimensional inverse discrete Fourier transform."""

61

```

62

63

### Real FFTs

64

65

Optimized transforms for real-valued input data.

66

67

```python { .api }

68

def rfft(a, n=None, axis=-1, norm=None):

69

"""

70

Compute 1D FFT of real input.

71

72

Parameters:

73

- a: array-like, real input array

74

- n: int, length of transformed axis

75

- axis: int, axis over which to compute FFT

76

- norm: {None, 'ortho'}, normalization mode

77

78

Returns:

79

cupy.ndarray: Complex FFT result (approximately half size)

80

"""

81

82

def irfft(a, n=None, axis=-1, norm=None):

83

"""

84

Compute inverse of rfft.

85

86

Returns:

87

cupy.ndarray: Real-valued result

88

"""

89

90

def rfft2(a, s=None, axes=(-2, -1), norm=None):

91

"""Compute 2D FFT of real input."""

92

93

def irfft2(a, s=None, axes=(-2, -1), norm=None):

94

"""Compute 2D inverse of rfft2."""

95

96

def rfftn(a, s=None, axes=None, norm=None):

97

"""Compute N-D FFT of real input."""

98

99

def irfftn(a, s=None, axes=None, norm=None):

100

"""Compute N-D inverse of rfftn."""

101

```

102

103

### Hermitian FFTs

104

105

Transforms for Hermitian-symmetric input.

106

107

```python { .api }

108

def hfft(a, n=None, axis=-1, norm=None):

109

"""

110

Compute FFT of signal with Hermitian symmetry.

111

112

Parameters:

113

- a: array-like, Hermitian input array

114

- n: int, length of transformed axis

115

- axis: int, axis over which to compute FFT

116

- norm: {None, 'ortho'}, normalization mode

117

118

Returns:

119

cupy.ndarray: Real-valued FFT result

120

"""

121

122

def ihfft(a, n=None, axis=-1, norm=None):

123

"""Compute inverse of hfft."""

124

```

125

126

### Helper Functions

127

128

Utility functions for frequency analysis and array manipulation.

129

130

```python { .api }

131

def fftfreq(n, d=1.0):

132

"""

133

Return discrete Fourier transform sample frequencies.

134

135

Parameters:

136

- n: int, window length

137

- d: scalar, sample spacing (inverse of sampling rate)

138

139

Returns:

140

cupy.ndarray: Sample frequencies

141

"""

142

143

def rfftfreq(n, d=1.0):

144

"""Return sample frequencies for rfft."""

145

146

def fftshift(x, axes=None):

147

"""

148

Shift zero-frequency component to center of spectrum.

149

150

Parameters:

151

- x: array-like, input array

152

- axes: int or shape tuple, axes over which to shift

153

154

Returns:

155

cupy.ndarray: Shifted array

156

"""

157

158

def ifftshift(x, axes=None):

159

"""Inverse of fftshift."""

160

```

161

162

## Usage Examples

163

164

### Basic FFT Operations

165

166

```python

167

import cupy as cp

168

import matplotlib.pyplot as plt

169

170

# Create test signal

171

t = cp.linspace(0, 1, 1000, endpoint=False)

172

signal = cp.sin(50 * 2 * cp.pi * t) + 0.5 * cp.sin(80 * 2 * cp.pi * t)

173

174

# Compute FFT

175

fft_result = cp.fft.fft(signal)

176

frequencies = cp.fft.fftfreq(len(signal), 1/1000)

177

178

# Get magnitude spectrum

179

magnitude = cp.abs(fft_result)

180

181

# Real FFT for real signals (more efficient)

182

rfft_result = cp.fft.rfft(signal)

183

rfrequencies = cp.fft.rfftfreq(len(signal), 1/1000)

184

```

185

186

### 2D FFT for Images

187

188

```python

189

import cupy as cp

190

191

# Create 2D test pattern

192

x = cp.linspace(-5, 5, 256)

193

y = cp.linspace(-5, 5, 256)

194

X, Y = cp.meshgrid(x, y)

195

image = cp.sin(X) * cp.cos(Y)

196

197

# 2D FFT

198

fft2_result = cp.fft.fft2(image)

199

fft2_magnitude = cp.abs(fft2_result)

200

201

# Shift zero frequency to center

202

fft2_shifted = cp.fft.fftshift(fft2_result)

203

204

# Inverse transform

205

reconstructed = cp.fft.ifft2(fft2_result).real

206

```