0% found this document useful (0 votes)
349 views15 pages

2-D FFT: Library

The 2-D fft block computes the fast Fourier transform (FFT) of a twodimensional M-by-N input matrix in two steps. The dimensions of the input matrix, m and N, must be powers of two. You can optimize the table of trigonometric values for memory or speed using the Optimize Table for parameter.

Uploaded by

Amol Jagtap
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
349 views15 pages

2-D FFT: Library

The 2-D fft block computes the fast Fourier transform (FFT) of a twodimensional M-by-N input matrix in two steps. The dimensions of the input matrix, m and N, must be powers of two. You can optimize the table of trigonometric values for memory or speed using the Optimize Table for parameter.

Uploaded by

Amol Jagtap
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 15

2-D FFT - Compute 2-D FFT of input

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

Input Vector or matrix of intensity  Double-precision floating point Yes


values
 Single-precision floating point

 Fixed point

 8-, 16-, 32-bit signed integer

 8-, 16-, 32-bit unsigned


integer

Output 2-D FFT of the input Same as input port Yes


If the input signal data type is floating point, the data type of the output
signal uses the same floating-point data type. Otherwise, the output can be
any fixed-point data type.

Optimizing the Table of Trigonometric Values

The block computes all the possible trigonometric values of the twiddle
factor

where K is the greater value of either M or N and . The block


stores these values in a table and retrieves them during simulation. You can
optimize the table of trigonometric values for memory or speed using the
Optimize table for parameter. This parameter varies the number of table entries as
summarized in the following table.

Optimize Table for Parameter Setting Number of Table Entries for N-Point FFT

Speed 3N/4-floating point

N - fixed point

Memory N/4 -floating point

Not supported for fixed point

Ordering Output Column Entries

Use the Output in bit-reversed order parameter to specify the ordering of


the column elements of the output as either linear or bit-reversed. If you
select the Output in bit-reversed order check box, the row and column
elements are output in bit-reversed order. Thus, the mth row element
appears at the kth position, where k is the bit reversed value of m. Also, the
nth column element appears at the lth position, where l is the bit reversed
value of n. If you clear the Output in bit-reversed order check box, the channel
elements are output in linear order.

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

Complexity of Output Algorithms Used for FFT Computation


Input Ordering

Complex Linear Bit-reversal operation and radix-2 DIT

Complex Bit-reversed Radix-2 DIF

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

Complexity of Input Output Ordering Algorithms Used for FFT Computation

Real or complex Linear Bit-reversal operation and radix-2 DIT

Real or complex Bit-reversed Radix-2 DIF

Fixed-Point Data Types


The following diagrams show the data types used in the 2-D FFT block for
fixed-point signals. You can set the sine table, accumulator, product output,
and output data types displayed in the diagrams in the 2-D FFT dialog box as
discussed in Dialog Box.
The block first casts inputs to the output data type and stores them in the
output buffer. Each butterfly stage then processes signals in the accumulator
data type, with the final output of the butterfly being cast back into the
output data type. The block multiplies twiddle factor values before each
butterfly stage in a decimation-in-time FFT and after each butterfly stage in
a decimation-in-frequency FFT.
The output of the multiplier appears in the accumulator data type because
both of the inputs to the multiplier are complex. For details on the complex
multiplication performed, refer to Multiplication Data Types in the Signal
Processing Blockset documentation.

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)

Click the Show data type assistant button to display the


Data Type Assistant, which helps you set the Product output data
type parameter.
See Using the Data Type Assistant for more information.
Accumulator data type
Specify the accumulator data type. See Fixed-Point Data Types for
illustrations depicting the use of the accumulator 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)

Click the Show data type assistant button to display the


Data Type Assistant, which helps you set the Accumulator data
type parameter.
See Using the Data Type Assistant for more information.
Output data type
Specify the output data type. See Fixed-Point Data Types for illustrations
depicting the use of the 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.
When you select Inherit: Inherit via internal rule, the
block calculates the output word length and fraction length
automatically. The internal rule first calculates an ideal output
word length and fraction length using the following equations:

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)

Click the Show data type assistant button to display the


Data Type Assistant, which helps you set the Output data type
parameter.
See Specifying Block Output Data Types for more information.
Lock data type settings against change by the fixed-point tools
Select this parameter to prevent the fixed-point tools from overriding
the data types you specify on the block mask. For more information,
see fxptdlg, a reference page on the Fixed-Point Tool in the Simulink
documentation.

See Also

2-D DCT Video and Image Processing Blockset software

2-D IDCT Video and Image Processing Blockset software

2-D IFFT Video and Image Processing Blockset software

FFT Signal Processing Blockset software

IFFT Signal Processing Blockset software


Pad Signal Processing Blockset software

bitrevorder Signal Processing Toolbox software

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.

Figure 2: 8-point DIF FFT signal flow diagram.


For the radix-2 DIF FFT using the Figures 1(c) and 1(d) butterflies,
 The N-point DIF FFT has log2(N) stages, numbered P = 1, 2, ..., log2(N).
 Each stage comprises N/2 butterflies.

 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.

Figure 3: 8-point DIT FFT signal flow diagram.


For the DIT FFT using the Figures 1(c) and 1(d) butterflies,
 The N-point DIT FFT has log2(N) stages, numbered P = 1, 2, ..., log2(N).
 Each stage comprises N/2 butterflies.

 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.

You might also like