File: t_KissFFT_std.py

package info (click to toggle)
openturns 1.24-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 66,204 kB
  • sloc: cpp: 256,662; python: 63,381; ansic: 4,414; javascript: 406; sh: 180; xml: 164; yacc: 123; makefile: 98; lex: 55
file content (61 lines) | stat: -rwxr-xr-x 1,614 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#! /usr/bin/env python

import openturns as ot

ot.TESTPREAMBLE()


# for fft, the best implementation is given for N = 2^p
size = 16

# collection for test
collection = ot.ComplexCollection(size)

# Fill the data with artificial values

# Create a complex gaussian sample
for index in range(size):
    realPart = 0.1 * (index + 1.0) / size
    imagPart = 0.3 * (index + 1.0) / size
    collection[index] = realPart + 1j * imagPart

myFFT = ot.KissFFT()
print("myFFT = ", myFFT)

# Initial transformation
print("collection = ", collection)

# FFT transform
transformedCollection = ot.ComplexCollection(myFFT.transform(collection))
print("FFT result = ", transformedCollection)

# Inverse transformation
inverseTransformedCollection = ot.ComplexCollection(
    myFFT.inverseTransform(transformedCollection)
)
print("FFT back=", inverseTransformedCollection)

# 2D case now
N = 8
distribution = ot.Normal(N)
sample = distribution.getSample(2 * N)

# FFT transform
transformedSample = myFFT.transform2D(sample)
print("2D FFT result = ", repr(transformedSample))

# Inverse transformation
inverseTransformedSample = myFFT.inverseTransform2D(transformedSample)
print("2D FFT back=", repr(inverseTransformedSample.real()))

# 3D case
elements = [ot.RandomGenerator.Generate() for i in range(N * N * N)]
tensor = ot.ComplexTensor(N, N, N, elements)

# FFT transform
transformedTensor = myFFT.transform3D(tensor)
print("3D FFT result = ", repr(transformedTensor))

# Inverse transformation
inverseTransformedTensor = myFFT.inverseTransform3D(transformedTensor)
print("3D FFT back=", repr(inverseTransformedTensor.real()))