1math::fourier(n) Tcl Math Library math::fourier(n)
2
3
4
5______________________________________________________________________________
6
8 math::fourier - Discrete and fast fourier transforms
9
11 package require Tcl 8.4
12
13 package require math::fourier 1.0.2
14
15 ::math::fourier::dft in_data
16
17 ::math::fourier::inverse_dft in_data
18
19 ::math::fourier::lowpass cutoff in_data
20
21 ::math::fourier::highpass cutoff in_data
22
23_________________________________________________________________
24
26 The math::fourier package implements two versions of discrete Fourier
27 transforms, the ordinary transform and the fast Fourier transform. It
28 also provides a few simple filter procedures as an illustrations of how
29 such filters can be implemented.
30
31 The purpose of this document is to describe the implemented procedures
32 and provide some examples of their usage. As there is ample literature
33 on the algorithms involved, we refer to relevant text books for more
34 explanations. We also refer to the original Wiki page on the subject
35 which describes some of the considerations behind the current implemen‐
36 tation.
37
39 The two top-level procedures defined are
40
41 · dft data-list
42
43 · inverse_dft data-list
44
45 Both take a list of complex numbers and apply a Discrete Fourier Trans‐
46 form (DFT) or its inverse respectively to these lists of numbers. A
47 "complex number" in this case is either (i) a pair (two element list)
48 of numbers, interpreted as the real and imaginary parts of the complex
49 number, or (ii) a single number, interpreted as the real part of a com‐
50 plex number whose imaginary part is zero. The return value is always in
51 the first format. (The DFT generally produces complex results even if
52 the input is purely real.) Applying first one and then the other of
53 these procedures to a list of complex numbers will (modulo rounding
54 errors due to floating point arithmetic) return the original list of
55 numbers.
56
57 If the input length N is a power of two then these procedures will uti‐
58 lize the O(N log N) Fast Fourier Transform algorithm. If input length
59 is not a power of two then the DFT will instead be computed using a the
60 naive quadratic algorithm.
61
62 Some examples:
63
64 % dft {1 2 3 4}
65 {10 0.0} {-2.0 2.0} {-2 0.0} {-2.0 -2.0}
66 % inverse_dft {{10 0.0} {-2.0 2.0} {-2 0.0} {-2.0 -2.0}}
67 {1.0 0.0} {2.0 0.0} {3.0 0.0} {4.0 0.0}
68 % dft {1 2 3 4 5}
69 {15.0 0.0} {-2.5 3.44095480118} {-2.5 0.812299240582} {-2.5 -0.812299240582} {-2.5 -3.44095480118}
70 % inverse_dft {{15.0 0.0} {-2.5 3.44095480118} {-2.5 0.812299240582} {-2.5 -0.812299240582} {-2.5 -3.44095480118}}
71 {1.0 0.0} {2.0 8.881784197e-17} {3.0 4.4408920985e-17} {4.0 4.4408920985e-17} {5.0 -8.881784197e-17}
72
73
74 In the last case, the imaginary parts <1e-16 would have been zero in
75 exact arithmetic, but aren't here due to rounding errors.
76
77 Internally, the procedures use a flat list format where every even
78 index element of a list is a real part and every odd index element is
79 an imaginary part. This is reflected in the variable names by Re_ and
80 Im_ prefixes.
81
82 The package includes two simple filters. They have an analogue equiva‐
83 lent in a simple electronic circuit, a resistor and a capacitance in
84 series. Using these filters requires the math::complexnumbers package.
85
87 The public Fourier transform procedures are:
88
89 ::math::fourier::dft in_data
90 Determine the Fourier transform of the given list of complex
91 numbers. The result is a list of complex numbers representing
92 the (complex) amplitudes of the Fourier components.
93
94 list in_data
95 List of data
96
97
98 ::math::fourier::inverse_dft in_data
99 Determine the inverse Fourier transform of the given list of
100 complex numbers (interpreted as amplitudes). The result is a
101 list of complex numbers representing the original (complex) data
102
103 list in_data
104 List of data (amplitudes)
105
106
107 ::math::fourier::lowpass cutoff in_data
108 Filter the (complex) amplitudes so that high-frequency compo‐
109 nents are suppressed. The implemented filter is a first-order
110 low-pass filter, the discrete equivalent of a simple electronic
111 circuit with a resistor and a capacitance.
112
113 float cutoff
114 Cut-off frequency
115
116 list in_data
117 List of data (amplitudes)
118
119
120 ::math::fourier::highpass cutoff in_data
121 Filter the (complex) amplitudes so that low-frequency components
122 are suppressed. The implemented filter is a first-order low-pass
123 filter, the discrete equivalent of a simple electronic circuit
124 with a resistor and a capacitance.
125
126 float cutoff
127 Cut-off frequency
128
129 list in_data
130 List of data (amplitudes)
131
132
134 This document, and the package it describes, will undoubtedly contain
135 bugs and other problems. Please report such in the category math ::
136 fourier of the Tcllib SF Trackers [http://source‐
137 forge.net/tracker/?group_id=12883]. Please also report any ideas for
138 enhancements you may have for either package and/or documentation.
139
141 FFT, Fourier transform, complex numbers, mathematics
142
143
144
145math 1.0.2 math::fourier(n)