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 Both take a list of complex numbers and
44 apply a Discrete Fourier Transform (DFT) or its inverse respec‐
45 tively to these lists of numbers. A "complex number" in this
46 case is either (i) a pair (two element list) of numbers, inter‐
47 preted as the real and imaginary parts of the complex number, or
48 (ii) a single number, interpreted as the real part of a complex
49 number whose imaginary part is zero. The return value is always
50 in the first format. (The DFT generally produces complex results
51 even if the input is purely real.) Applying first one and then
52 the other of these procedures to a list of complex numbers will
53 (modulo rounding errors due to floating point arithmetic) return
54 the original list of numbers.
55
56 If the input length N is a power of two then these procedures will uti‐
57 lize the O(N log N) Fast Fourier Transform algorithm. If input length
58 is not a power of two then the DFT will instead be computed using a the
59 naive quadratic algorithm.
60
61 Some examples:
62
63 % dft {1 2 3 4}
64 {10 0.0} {-2.0 2.0} {-2 0.0} {-2.0 -2.0}
65 % inverse_dft {{10 0.0} {-2.0 2.0} {-2 0.0} {-2.0 -2.0}}
66 {1.0 0.0} {2.0 0.0} {3.0 0.0} {4.0 0.0}
67 % dft {1 2 3 4 5}
68 {15.0 0.0} {-2.5 3.44095480118} {-2.5 0.812299240582} {-2.5 -0.812299240582} {-2.5 -3.44095480118}
69 % inverse_dft {{15.0 0.0} {-2.5 3.44095480118} {-2.5 0.812299240582} {-2.5 -0.812299240582} {-2.5 -3.44095480118}}
70 {1.0 0.0} {2.0 8.881784197e-17} {3.0 4.4408920985e-17} {4.0 4.4408920985e-17} {5.0 -8.881784197e-17}
71
72
73 In the last case, the imaginary parts <1e-16 would have been zero in
74 exact arithmetic, but aren't here due to rounding errors.
75
76 Internally, the procedures use a flat list format where every even
77 index element of a list is a real part and every odd index element is
78 an imaginary part. This is reflected in the variable names by Re_ and
79 Im_ prefixes.
80
81 The package includes two simple filters. They have an analogue equiva‐
82 lent in a simple electronic circuit, a resistor and a capacitance in
83 series. Using these filters requires the math::complexnumbers package.
84
86 The public Fourier transform procedures are:
87
88 ::math::fourier::dft in_data
89 Determine the Fourier transform of the given list of complex
90 numbers. The result is a list of complex numbers representing
91 the (complex) amplitudes of the Fourier components.
92
93 in_data list List of data
94
95
96 ::math::fourier::inverse_dft in_data
97 Determine the inverse Fourier transform of the given list of
98 complex numbers (interpreted as amplitudes). The result is a
99 list of complex numbers representing the original (complex) data
100
101 in_data list List of data (amplitudes)
102
103
104 ::math::fourier::lowpass cutoff in_data
105 Filter the (complex) amplitudes so that high-frequency compo‐
106 nents are suppressed. The implemented filter is a first-order
107 low-pass filter, the discrete equivalent of a simple electronic
108 circuit with a resistor and a capacitance.
109
110 cutoff float Cut-off frequency
111
112 in_data list List of data (amplitudes)
113
114
115 ::math::fourier::highpass cutoff in_data
116 Filter the (complex) amplitudes so that low-frequency components
117 are suppressed. The implemented filter is a first-order low-pass
118 filter, the discrete equivalent of a simple electronic circuit
119 with a resistor and a capacitance.
120
121 cutoff float Cut-off frequency
122
123 in_data list List of data (amplitudes)
124
125
127 FFT, Fourier transform, complex numbers, mathematics
128
129
130
131math 1.0.2 math::fourier(n)