2-D FFT: Library
2-D FFT: Library
Library
Transforms
viptransforms
Description
The 2-D FFT block computes the fast Fourier transform (FFT) of a two-
dimensional M-by-N input matrix in two steps. First it computes the one-
dimensional FFT along one dimension (row or column). Then it computes the
FFT of the output of the first step along the other dimension (column or
row). The dimensions of the input matrix, M and N, must be powers of two.
To work with other input sizes, use the Pad block to pad or truncate these
dimensions to powers of two.
The output of the 2-D FFT block is equivalent to the MATLAB ® fft2 function:
y = fft2(A) % Equivalent MATLAB code
Computing the FFT of each dimension of the input matrix is equivalent to
calculating the two-dimensional discrete Fourier transform (DFT), which is
defined by the following equation:
where and .
Complex Values
Port Description Supported Data Types
Supported
Fixed point
The block computes all the possible trigonometric values of the twiddle
factor
Optimize Table for Parameter Setting Number of Table Entries for N-Point FFT
N - fixed point
Note The 2-D FFT block calculates its output in bit-reversed order. Linearly ordering the 2-D FFT
block output requires an extra bit-reversal operation. Thus, in many situations, you can increase the
speed of the 2-D FFT block by selecting the Output in bit-reversed order check box.
For more information ordering of the output, see Bit-Reversed Order. The 2-D
FFT block bit-reverses the order of both the columns and the rows.
Algorithms Used for FFT Computation
Which algorithms the block uses depends on whether the block input is
floating-point or fixed-point, real or complex. The choice of algorithms is also
affected by whether you want the output in linear or bit-reversed order.
Based on these specifications, the block can use any of the following
algorithms:
Bit-reversal operation
Double-signal algorithm
Half-length algorithm
Radix-2 decimation-in-time (DIT) algorithm
Radix-2 decimation-in-frequency (DIF) algorithm
Floating-Point Signals
Real Linear Bit-reversal operation and radix-2 DIT in conjunction with the half-
length and double-signal algorithms
Real Bit-reversed Radix-2 DIF in conjunction with the half-length and double-signal
algorithms
Fixed-Point Signals
Example
Bit-Reversed Order
Two numbers are bit-reversed values of each other when the binary
representation of one is the mirror image of the binary representation of the
other. For example, in a three-bit system, one and four are bit-reversed
values of each other because the three-bit binary representation of one,
001, is the mirror image of the three-bit binary representation of four, 100.
The following diagram shows the row indices in linear order. To put them in
bit-reversed order
1.Translate the indices into their binary representation with the
minimum number of bits. In this example, the minimum number of
bits is three because the binary representation of 7 is 111.
2.Find the mirror image of each binary entry, and write it beside the
original binary representation.
3.Translate the indices back to their decimal representation.
The row indices now appear in bit-reversed order.
If, on the 2-D FFT block parameters dialog box, you select the Output in
bit-reversed order check box, the block bit-reverses the order of both the
columns and the rows. The next diagram illustrates the linear and bit-
reversed outputs of the 2-D FFT block. The output values are the same, but
they appear in different order.
Dialog Box
The Main pane of the 2-D FFT dialog box appears as shown in the following
figure.
Optimize table for
Optimize the table of twiddle factor values for Speed or Memory. This
parameter must be set to Speed for fixed-point signals.
Output in bit-reversed order
Designate the order of the output channel elements relative to the
ordering of the input elements. When selected, the output channel
elements appear in bit-reversed order relative to the input ordering.
Otherwise, the output column elements display in linear order relative
to the input ordering. Linearly ordering the output requires extra data
sorting manipulation. For more information, see Bit-Reversed Order.
Divide butterfly outputs by two
When you select this parameter, the output of each butterfly of the
FFT is divided by two.
The Data Types pane of the 2-D FFT dialog box appears as shown in the
following figure.
Rounding mode
Select the rounding mode for fixed-point operations. The sine table
values do not obey this parameter; instead, they always round to
Nearest.
Overflow mode
Select the overflow mode for fixed-point operations. The sine table
values do not obey this parameter; instead, they are always
saturated.
Sine table data type
Choose how you specify the word length of the values of the sine
table. The fraction length of the sine table values always equals the
word length minus one. You can set this parameter to:
A rule that inherits a data type, for example, Inherit: Same
word length as input
An expression that evaluates to a valid data type, for example,
fixdt(1,16)
The sine table values do not obey the Rounding mode and
Overflow mode parameters; instead, they are always saturated and
rounded to Nearest.
Product output data type
Specify the product output data type. See Fixed-Point Data Types and
Multiplication Data Types for illustrations depicting the use of the product
output data type in this block. You can set this parameter to:
A rule that inherits a data type, for example, Inherit:
Inherit via internal rule
An expression that evaluates to a valid data type, for example,
fixdt(1,16,0)
Using these ideal results, the internal rule then selects word
lengths and fraction lengths that are appropriate for your
hardware. For more information, see Inherit via Internal Rule.
An expression that evaluates to a valid data type, for example,
fixdt(1,16,0)
See Also
fft MATLAB
ifft MATLAB
Computing FFT Twiddle Factors
Posted by Rick Lyons on Aug 7 2010 under Tips and Tricks
Some days ago I read a post on the comp.dsp newsgroup and, if I understood the poster's words, it
seemed that the poster would benefit from knowing how to compute the twiddle factors of a radix-2
fast Fourier transform (FFT).
Then, later it occurred to me that it might be useful for this blog's readers to be aware of algorithms
for computing FFT twiddle factors. So,... what follows are two algorithms showing how to compute
the individual twiddle factors of an N-point decimation-in-frequency (DIF) and an N-point decimation-
in-time (DIT) FFT.
The vast majority of FFT applications use (notice how I used the word "use" instead of the clumsy
word "utilize") standard, pre-written, FFT software routines. However, there are non-standard FFT
applications (for example, specialized harmonic analysis, transmultiplexers, or perhaps using an FFT
to implement a bank of filters) where only a subset of the full N-sample complex FFT results are
required. Those oddball FFT applications, sometimes called "pruned FFTs", require computation of
individual FFT twiddle factors, and that's the purpose of this blog.
(If, by chance, the computation of FFT twiddle factors is of no interest to you, you might just scroll
down to the "A Little History of the FFT" part of this blog.)
Before we present the two twiddle factor computation algorithms, let's understand the configuration
of a single "butterfly" operation used in our radix-2 FFTs. We've all seen the signal flow drawings of
FFTs with their arrays of butterfly operations. There are various ways of implementing a butterfly
operation, but my favorites are the efficient single-complex-multiply butterflies shown in Figure 1. A
DIF butterfly is shown in Figure 1(a), while a DIT butterfly is shown in Figure 1(b). In Figure 1 the
twiddle factors are shown as e–j2πQ/N, where variable Q is merely an integer in the range of 0 ≤ Q ≤
(N/2)–1.
To simplify this blog's follow-on figures, we'll use Figures 1(c) and 1(d) to represent the DIF and DIT
butterflies. As such, Figure 1(c) is equivalent to Figure 1(a), and Figure 1(d) is equivalent to Figure
1(b).
Figure 1: Single-complex-multiply DIF and DIT butterflies.
Computing DIF Twiddle Factors
Take a look at Figure 2 showing the butterfly operations for an 8-point radix-2 DIF FFT.
Not counting the –1 twiddle factors, the Pth stage has N/2P unique twiddle factors, numbered
k = 0, 1, 2, ..., N/2P–1 as indicated by the bold numbers above the upward-pointing arrows at
the bottom of Figure 2.
Given those characteristics, the kth unique twiddle factor phase angle for the Pth stage is computed
using:
kth DIF twiddle factor angle = k•2P/2 (1)
where 0 ≤ k ≤ N/2P–1. For example, for the second stage (P = 2) of an N = 8-point DIF FFT, the
unique Q factors are:
k = 0, Q = 0•2P/2 = 0•4/2 = 0
k = 1, Q = 1•2P/2 = 1•4/2 = 2.
Computing DIT Twiddle Factors
Here's an algorithm for computing the individual twiddle factor angles of a radix-2 DIT FFT. Consider
Figure 3 showing the butterfly signal flow of an 8-point DIT FFT.
Not counting the –1 twiddle factors, the Pth stage has N/2 twiddle factors, numbered k = 0, 1,
2, ..., N/2–1 as indicated by the upward arrows at the bottom of Figure 3.
Given those characteristics, the kth DIT twiddle Q factor for the Pth stage is computed using:
kth DIT twiddle factor Q = [⌊k2P/N⌋]bit-rev (2)
where 0 ≤ k ≤ N/2–1. The ⌊q⌋ operation means the integer part of q. The [z]bit-rev function represents
the three-step operation of:
[1] convert decimal integer z to a binary number represented by log2(N)–1 binary bits,
[2] perform bit reversal on the binary number as discussed in Section 4.5, and
[3] convert the bit reversed number back to a decimal integer.
As an example of using Eq.(2), for the second stage (P = 2) of an N = 8-point DIT FFT, the k = 3
twiddle Q factor is:
3rd twiddle factor Q = [⌊3•22/8⌋]bit-rev
= [⌊1.5⌋]bit-rev = [1]bit-rev = 2.
The above [1]bit-rev operation is: take the decimal number 1 and represent it with log2(N)–1 = 2 bits,
i.e., as 012. Next, reverse those bits to a binary 102 and convert that binary number to our desired
decimal result of 2.