Products & Services Solutions Academia Support User Community Company

Learn more about Signal Processing Blockset   

FFT - Compute fast Fourier transform (FFT) of input

Library

Transforms

dspxfrm3

Description

The FFT block computes the fast Fourier transform (FFT) of each row of a sample-based 1-by-P input vector, u, or across the first dimension (P) of an N-D input array, u. When you select the Inherit FFT length from input dimensions check box, P must be an integer power of two, and the FFT length, M, is set equal to P. If you do not select the check box, P can be any length, and the value of the FFT length parameter must be a positive integer power of two. For user-specified FFT lengths, when M does not equal P, zero padding or modulo-M data wrapping occurs before the FFT operation, as per Orfanidis [1]:

y = fft(u,M)		% P ≤ M
y(:,l) = fft(datawrap(u(:,l),M))		% P > M; l = 1,...,N

When the input length, P, is greater than the FFT length, M, you may see magnitude increases in your FFT output. These magnitude increases occur because the FFT block uses modulo-M data wrapping to preserve all available input samples.

To avoid such magnitude increases, you can truncate the length of your input sample, P, to the FFT length, M. To do so, place a Pad block before the FFT block in your model.

The kth entry of the lth output channel, y(k, l), equals the kth point of the M-point discrete Fourier transform (DFT) of the lth input channel:

This block supports real and complex floating-point and fixed-point inputs.

Input and Output Characteristics

The following table describes valid inputs to the FFT block, their corresponding outputs, and the dimension along which the block computes the DFT.

Valid Block InputsDimension Along Which Block Computes DFTCorresponding Block Output Characteristics

N-D array

First dimension

  • Sample based.

  • Complex valued.

  • N-D array with the size of the first dimension equal to the FFT length, M, and all other dimensions the same size as the input.

  • Each output column contains the M-point DFT of the corresponding input channel in linear or bit-reversed order.

Sample-based 1-by-P row vector

Row

  • Sample based.

  • Complex valued.

  • 1-by-M row vector.

  • Each output row contains the M-point DFT of the corresponding input channel in linear or bit-reversed order.

Unoriented length-P 1-D vector

Vector

Unoriented, length-M, complex-valued 1-D output vector containing M-point DFT of input in linear or bit-reversed order.

Selecting the Twiddle Factor Computation Method

The Twiddle factor computation parameter determines how the block computes the necessary sine and cosine terms to calculate the term , shown in the first equation of this block reference page.

The block only supports Table lookup mode for fixed-point signals.

The Twiddle factor computation parameter has two settings, each with its advantages and disadvantages, as described in the following table.

Twiddle Factor Computation Parameter SettingSine and Cosine Computation MethodEffect on Block Performance

Table lookup

The block computes and stores the trigonometric values before the simulation starts and retrieves them during the simulation. When you generate code from the block, the processor running the generated code stores the trigonometric values computed by the block, and retrieves the values during code execution.

The block usually runs much more quickly, but requires extra memory for storing the precomputed trigonometric values. You can optimize the table for memory consumption or speed, as described in Optimizing the Table of Trigonometric Values.

Trigonometric fcn

The block computes sine and cosine values during the simulation. When you generate code from the block, the processor running the generated code computes the sine and cosine values while the code runs.

The block usually runs more slowly, but does not need extra data memory. For code generation, the block requires a support library to emulate the trigonometric functions, increasing the size of the generated code.

Optimizing the Table of Trigonometric Values

When you set the Twiddle factor computation parameter to Table lookup, you also need to set the Optimize table for parameter.

This parameter optimizes the table of trigonometric values for speed or memory by varying the number of table entries as summarized in the following table.

Optimize Table for Parameter SettingNumber of Table Entries for N-Point FFTMemory Required for Single-Precision, 512-Point FFT

Speed

3N/4 — floating point

N — fixed point

Memory

N/4 — floating point

Not supported for fixed point

Ordering Output Column Entries

You can set the Output in bit-reversed order parameter to specify the ordering of the column elements of the block output. If you select the Output in bit-reversed order check box, the output appears in bit-reversed order. If you clear the Output in bit-reversed order check box, the output appears in linear order.

For more information ordering of the output, see Linear and Bit-Reversed Output Order.

Algorithms Used for FFT Computation

Depending on whether the block's input is real- or complex-valued and whether you want the output in linear or bit-reversed order, the block uses one or more of the following algorithms as summarized in the following table:

Complexity of InputOutput OrderingAlgorithms Used for FFT Computation

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

The efficiency of the FFT algorithm can be enhanced for real input signals by forming complex-valued sequences from the real-valued sequences prior to the computation of the DFT. When there are 2N+1 real input channels, the FFT block forms these complex-valued sequences by applying the double-signal algorithm to the first 2N input channels, and the half-length algorithm to the last odd-numbered channel.

For real input signals with fixed-point data types, it is possible to see different numerical results in the output of the last odd numbered channel, even when all input channels are identical. This numerical difference results from differences in the double-signal algorithm and the half-length algorithm.

You can eliminate this numerical difference in two ways:

For more information on the double-signal and half-length algorithms, see Proakis [2]. "Efficient Computation of the DFT of Two Real Sequences" on page 475 describes the double signal algorithm. "Efficient Computation of the DFT of a 2N-Point Real Sequence" on page 476 describes the half-length algorithm.

Fixed-Point Data Types

The following diagrams show the data types used within the 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 FFT block dialog as discussed in Dialog Box.

The block first casts inputs to the FFT block to the output data type and stores them in the output buffer. Each butterfly stage then processes signals in the accumulator data type, and the block then casts the final output of the butterfly back into the output data type. The block multiplies in a twiddle factor 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, see Multiplication Data Types.

Examples

See the section on Transforming Time-Domain Data into the Frequency Domain in the Signal Processing Blockset User's Guide.

Dialog Box

The Main pane of the FFT block dialog appears as follows.

Twiddle factor computation

Specify the computation method of the term , shown in the first equation of this block reference page.

In Table lookup mode, the block computes and stores the sine and cosine values before the simulation starts.

In Trigonometric fcn mode, the block computes the sine and cosine values during the simulation. See Selecting the Twiddle Factor Computation Method.

This parameter must be set to Table lookup for fixed-point signals.

Optimize table for

Select the optimization of the table of sine and cosine values for Speed or Memory. This parameter becomes available only when you set the Twiddle factor computation parameter to Table lookup. See Selecting the Twiddle Factor Computation Method.

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 you select this check box, the output channel elements appear in bit-reversed order relative to the input ordering. Otherwise, the output column elements appear in linear order relative to the input ordering.

Linearly ordering the output requires extra data sorting manipulation, so in some situations it might be better to output in 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. When you do not select this parameter, the block does not scale the output.

Inherit FFT length from input dimensions

Select to inherit the FFT length from the input dimensions. When you select this parameter, the input length P must be a power of two. When you do not select this parameter, the FFT length parameter becomes available.

FFT length

Specify a power-of-two FFT length. This parameter becomes available only when you do not select the Inherit FFT length from input dimensions parameter.

The Fixed-point pane of the FFT block dialog appears as follows.

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

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:

  • When you select Same word length as input, the word length of the sine table values match that of the input to the block.

  • When you select Specify word length, you can enter the word length of the sine table values, in bits.

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

Use this parameter to specify how you would like to designate the product output word and fraction lengths. See Fixed-Point Data Types and Multiplication Data Types for illustrations depicting the use of the product output data type in this block:

  • When you select Inherit via internal rule, the block calculates the product output word length and fraction length automatically. For information about how the product output word and fraction lengths are calculated when an internal rule is used, see Inherit via Internal Rule.

  • When you select Same as input, these characteristics match those of the input to the block.

  • When you select Binary point scaling, you can enter the word length and the fraction length of the product output, in bits.

  • When you select Slope and bias scaling, you can enter the word length, in bits, and the slope of the product output. This block requires power-of-two slope and a bias of zero.

Accumulator

Use this parameter to specify how you would like to designate the accumulator word and fraction lengths. See Fixed-Point Data Types and Multiplication Data Types for illustrations depicting the use of the accumulator data type in this block:

  • When you select Inherit via internal rule, the block calculates the accumulator word length and fraction length automatically. For information about how the accumulator word and fraction lengths are calculated when an internal rule is used, see Inherit via Internal Rule.

  • When you select Same as product output, these characteristics match those of the product output.

  • When you select Same as input, these characteristics match those of the input to the block.

  • When you select Binary point scaling, you can enter the word length and the fraction length of the accumulator, in bits.

  • When you select Slope and bias scaling, you can enter the word length, in bits, and the slope of the accumulator. This block requires power-of-two slope and a bias of zero.

Output

Choose how you specify the output word length and fraction length:

  • When you select 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.

  • When you select Same as input, these characteristics match those of the input to the block.

  • When you select Binary point scaling, you can enter the word length and the fraction length of the output, in bits.

  • When you select Slope and bias scaling, you can enter the word length, in bits, and the slope of the output. This block requires power-of-two slope and a bias of zero.

Lock scaling against changes by the autoscaling tool

Select this parameter to prevent any fixed-point scaling you specify in this block mask from being overridden by the autoscaling feature of the Fixed-Point Tool. See the fxptdlg reference page for more information.

References

[1] Orfanidis, S. J. Introduction to Signal Processing. Upper Saddle River, NJ: Prentice Hall, 1996, p. 497.

[2] Proakis, John G. and Dimitris G. Manolakis. Digital Signal Processing, 3rd ed. Upper Saddle River, NJ: Prentice Hall, 1996.

Supported Data Types

PortSupported Data Types

Input

  • Double-precision floating point

  • Single-precision floating point

  • Fixed point

  • 8-, 16-, and 32-bit signed integers

  • 8-, 16-, and 32-bit unsigned integers

Output

  • Double-precision floating point

  • Single-precision floating point

  • Fixed point (signed only)

  • 8-, 16-, and 32-bit signed integers

See Also

DCTSignal Processing Blockset
IFFTSignal Processing Blockset
PadSignal Processing Blockset
fftMATLAB
ifftMATLAB
bitrevorderSignal Processing Toolbox

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS