ECE 431 Spring 2005
Tutorial March 28, 2005
The Sliding DFT
1 Motivation
Given a discrete-time signal, which can be considered as a sequence . . . , x(2), x(1), x(0), x(1), x(2), . . . , x(n), x(n + 1), . . . (1)
In some applications, one may wish to analyze the signal using a xed-length sliding window. For example, suppose at the time instant n, a windowed sequence x(n) consisting of N samples, is formed as follows x(n) = {x(n N + 1), x(n N + 2), . . . , x(n 1), x(n)} and an N -DFT operation is performed on x(n) to yield X(n) = {X0 , X1 , . . . , XN 2 , XN 1 }. (3) (2)
Hence, at each new time instant n, a new DFT-sequence X(n) is computed (compare to the previously examined short-term Fourier transform method). Evidently, an FFT operation can be used to evaluate the N -sequence X(n). What is important to note is that the FFT is fast or computationally ecient when ALL the N values of X(n) are needed. But suppose, in a certain scenario, we are only interested in the kth value of the DFT, i.e., Xk1 , then the FFT seems to be wasteful. Essentially, with the FFT, we have to compute the entire DFT-sequence and discard the unwanted values. Is there a better solution? In fact, there exists a more desirable method, known as the Goertzel algorithm, to obtain an isolated Xk (see Sec. 9.2 in your Oppenheim text). In addition, when we are considering a sliding-window scenario described above, an algorithm known as the sliding DFT (SDFT) is particularly ecient. Basically, the SDFT comes from the observation that for two successive time instants, say n 1 and n, the windowed sequences x(n 1) and x(n) contain essentially identical elements. For example, if the window length N =16, then at the time instant n = 15, the sequence x(15) = {x(0), x(1), . . . , x(14), x(15)} is fed to the 16-DFT. And at n = 16, x(16) = {x(1), x(2), . . . , x(15), x(16)} (5) (4)
is used in the 16-DFT computation. The striking similarity between x(n 1) and x(n) is exploited in the SDFT for computational eciency.
Method
Before presenting the SDFT, we recall the following DFT property. If N -DFT of x[n] is X[k] then x[((n m))N ]
j2
N DF T
km WN X[k]
(6)
where WN = e N . Thus, (6) shows the N -DFT of a circularly shifted sequence. In particular, if a sequence is circularly shifted by one sample (to the left), then the DFT value Xk becomes Xk Xk ej2k/N . (7)
Now let us consider more closely how to relate two successive windowed sequences, such as those in (4) and (5). In fact, regardless of the value of N , one can obtain x(n) from x(n 1) by the following simple 2-step process: 1. Replace the rst element of x(n 1) with the last element of x(n), e.g., start with (4) and replace x0 with x16 . 2. Perform circular shift on the replaced sequence by one sample (to the left). These two steps lead to simple eects in the DFT domain.
2.1
Eect of Step #1:
Observe the contribution of the rst element (i.e., x(0)) in the DFT:
N 1
Xk =
n=0
nk k x(n)WN = x(0) + x(1)WN + . . . + x(N 1)WN
(N 1)k
(8)
which shows that the rst element x(0) appears unmodied in the DFT formula. Hence, the eect of step #1 on the DFT is simple. For example, perform step 1 on (4) to get an intermediate sequence x(15) = {x(16), x(1), . . . , x(14), x(15)}. (9) Denoting by Xk (15) and Xk (15) the DFTs of respectively x(15) and x(15), we get from (8) Xk (15) = Xk (15) x(0) + x(16) (10)
2.2
Eect of Step #2:
Denote by Xk (16) the DFT of x(16), then we simply apply property (7) to (10) to get Xk (16) = Xk (15)ej2k/N (11)
2.3
The SDFT Algorithm
Hence, combining the eects of both steps, we can relate the DFTs of two successive windowed sequences, each of length N , x(n 1) and x(n) as: Xk (n) = [Xk (n 1) x(n N ) + x(n)] ej2k/N 2 (12)
Analysis
In terms of eciency, the SDFT is impressive because, regardless of N , it requires a constant number of operations to compute a successive DFT output: two real adds and one complex multiply (from (12)). However, this computation assumes that, for the current time instant, the DFT of the previous time instant is available. A simple solution for algorithm initialization is to obtain the DFT of the rst time instant simply using the direct DFT (8), or apply the FFT (when more than one Xk s are required). Alternatively, we consider an IIR implementation, shown in Fig. 1. This structure is simply a comb and resonator cascade lter. The output is relabeled as Sk (n) to emphasize the transient nature of the lter, i.e., due to the comb lter delay, the output Sk (n) is not equal to Xk (n) for n < N . This means that the output is not valid until N input samples have been processed (as is expected, since an N -DFT requires by denition N samples).
x(n) z N Sk(n)
e j 2k /N
z 1 Sk(n1)
x(nN)
Figure 1: An IIR Implementation of the SDFT: Comb and Resonator Cascade. Also note that if several DFT elements are required, then a bank of resonators, all driven by a single comb lter can be used. For example, if one is interested in the X1 and X4 values of a 16-DFT, then two resonators at frequencies 2/16 and 24/16 are driven by a single comb lter with a delay N = 16.
Examples
{x(n)}4 = [1, 2, 3, 4, 5] n=0
Example 4.1 (Circular Shift) The sequence (13)
has 5-DFT sequence Xk = [15, 2.5 + 3.4410i, 2.5 + 0.8123i, 2.5 0.8123i, 2.5 3.4410i]. Hence, the circularly shifted sequence y[n] = (x(n 2))5 y[n] = (x(n 2))5 = [4, 5, 1, 2, 3] has 5-DFT sequence
2k Yk = Xk WN = [15, 4.0451 1.3143i, 1.5451 2.1266i, 1.5451 + 2.1266i, 4.0451 + 1.3143i] (16)
(14)
(15)
See the following GNU Octave snippet. Obviously with very large N , using the DFT property is more ecient than manually invoking the FFT.
GNU Octave/MATLAB code snippet: x % m % Y % k = [1,2,3,4,5], N = length(x); X = fft(x,N) do circular shift = 2; n = [0:N-1]; n = mod(n-m,N);y = x(n+1) manual FFT = fft(y) circular shift property = [0:N-1]; X.*exp(-j*2*pi*m*k/N)
Example 4.2 (Sliding DFT ) Let x[n] in the previous example be a windowed sequence dened at some instant in time. And suppose the following windowed sequence is the sequence z[n] = [2, 3, 4, 5, 6], which has 5-DFT sequence Zk . Then the elements of Zk can be computed using the SDFT as: Zk = (Xk 1 + 6)ej2k/5 = [20 2.5 + 3.4410i, 2.5 + 0.8123i, 2.5 0.8123i, 2.5 3.4410i] (17) For example, Z4 = (2.5 3.4410i 1 + 6)ej24/5 = 2.5 3.4410i GNU Octave/MATLAB code snippet: z % Z % k % k = [2,3,4,5,6] manual FFT = fft(z) sliding DFT for whole sequence, i.e., like filter bank = [0:N-1]; (X(k+1)-x(1)+z(end)).*exp(j*2*pi*k/N) sliding DFT for single value = 4; (X(k+1)-x(1)+z(end)).*exp(j*2*pi*k/N) (18)
You can modify the above snippet for very large N , and run over many successive sliding windows, to measure the speed dierence between FFT and sliding DFT.
References
[1] E. Jacobsen and R. Lyons. The Sliding DFT, IEEE Signal Processing Magazine, Mar. 2003, pp. 74-80. [2] E. Jacobsen and R. Lyons. An update to the Sliding DFT, IEEE Signal Processing Magazine, Jan. 2004, pp.110-111.