Discrete Fourier Transform¶
Description¶
This treatment performs a Discrete Fourier Transform (DFT) on all the given variables of a 3-D finite time-marching result.
The Fourier transform of a continuous-time signal \(x(t)\) may be defined as:
\(X(f) = \int_{-\infty}^{+\infty} x(t) e^{-j2 \pi ft}dt\)
The Discrete Fourier Transform implemented replaces the infinite integral with a finite sum:
\(X(k) = \frac{1}{N}\sum_{n=0}^{N-1} x(n) e^{-j2 \pi \frac{nk}{N}}dt\)
where \(x(n)\) is the \(N\) sampling terms of an analogic signal \(x(t) = x(n\Delta t)\) and the \(N\) terms \(X(k)\) are an approximation of the Fourier transform of this signal at the mode frequency defined as \(f_k = k\Delta f/N = k/T\).
- with:
the sampling frequency: \(\Delta f = \frac{1}{\Delta t}\)
the sampling interval: \(T = N \Delta t\)
the mode \(k = f_k \times T\)
Construction¶
import antares
myt = antares.Treatment('dft')
Parameters¶
- base:
Base
The base on which the Fourier modes will be computed. It can contain several zones and several instants. DFT is performed on all variables except coordinates.
- base:
- type: str, default= ‘mod/phi’
The DFT type of the output data: ‘mod/phi’ for modulus/phase decomposition or ‘im/re’ for imaginery/real part decomposition.
- coordinates: list(str), default=
antares.Base.coordinate_names
The variable names that define the set of coordinates. The coordinates will not be computed by the DFT treatment.
- coordinates: list(str), default=
- mode: lists(int), default= None
Give one mode or a list of mode ([1, 2, 4] for example). If empty, this returns all the mode including the mean part.
- dt: float, default= None
Time step between instants. If given, each mode instants will contain the frequency value in the attribute “frequency”
- phi_in_degrees: bool, default= True
In mode = “mod/phi”, if the angle phi should be expressed in degrees or radians
Preconditions¶
All the zones must have the same instant.
Postconditions¶
if dt is not None, each instant will contain an attribute “frequency” containing the frequency for the given mode.
Example¶
import antares
myt = antares.Treatment('dft')
myt['base'] = base
myt['type'] = 'mod/phi'
myt['mode'] = [4, 18, 36]
dft_modes = myt.execute()
Warning
A mode is defined as \(k=f_k \times T\), with \(T\) the sampling interval.
Main functions¶
Example¶
"""
This example illustrates the Discrete Fourier Transform
treatment of Antares.
"""
import os
if not os.path.isdir('OUTPUT'):
os.makedirs('OUTPUT')
from antares import Reader, Treatment, Writer
# ------------------
# Reading the files
# ------------------
reader = Reader('bin_tp')
reader['filename'] = os.path.join('..', 'data', 'ROTOR37', 'GENERIC', 'flow_<zone>_<instant>.dat')
base = reader.read()
# ----
# DFT
# ----
treatment = Treatment('dft')
treatment['base'] = base
treatment['type'] = 'mod/phi'
treatment['mode'] = list(range(0, 2))
result = treatment.execute()
# -------------------
# Writing the result
# -------------------
writer = Writer('bin_tp')
writer['filename'] = os.path.join('OUTPUT', 'ex_dft_<instant>.plt')
writer['base'] = result
writer.dump()