Package: tcllib, Version: CVS HEAD
math::fourier -
Discrete and fast fourier transforms
package require Tcl 8.4 package require math::fourier 1.0.2 ::math::fourier::dft in_data ::math::fourier::inverse_dft in_data ::math::fourier::lowpass cutoff in_data ::math::fourier::highpass cutoff in_data
The math::fourier package implements two versions of discrete Fourier transforms, the ordinary transform and the fast Fourier transform. It also provides a few simple filter procedures as an illustrations of how such filters can be implemented.
The purpose of this document is to describe the implemented procedures and provide some examples of their usage. As there is ample literature on the algorithms involved, we refer to relevant text books for more explanations. We also refer to the original Wiki page on the subject which describes some of the considerations behind the current implementation.
If the input length N is a power of two then these procedures will utilize the O(N log N) Fast Fourier Transform algorithm. If input length is not a power of two then the DFT will instead be computed using a the naive quadratic algorithm.
Some examples:
% dft {1 2 3 4} {10 0.0} {-2.0 2.0} {-2 0.0} {-2.0 -2.0} % inverse_dft {{10 0.0} {-2.0 2.0} {-2 0.0} {-2.0 -2.0}} {1.0 0.0} {2.0 0.0} {3.0 0.0} {4.0 0.0} % dft {1 2 3 4 5} {15.0 0.0} {-2.5 3.44095480118} {-2.5 0.812299240582} {-2.5 -0.812299240582} {-2.5 -3.44095480118} % inverse_dft {{15.0 0.0} {-2.5 3.44095480118} {-2.5 0.812299240582} {-2.5 -0.812299240582} {-2.5 -3.44095480118}} {1.0 0.0} {2.0 8.881784197e-17} {3.0 4.4408920985e-17} {4.0 4.4408920985e-17} {5.0 -8.881784197e-17}
In the last case, the imaginary parts <1e-16 would have been zero in exact arithmetic, but aren't here due to rounding errors.
Internally, the procedures use a flat list format where every even index element of a list is a real part and every odd index element is an imaginary part. This is reflected in the variable names by Re_ and Im_ prefixes.
The package includes two simple filters. They have an analogue equivalent in a simple electronic circuit, a resistor and a capacitance in series. Using these filters requires the math::complexnumbers package.
Type | Name | Mode |
---|---|---|
list | in_data | |
List of data |
Type | Name | Mode |
---|---|---|
list | in_data | |
List of data (amplitudes) |