Main Content

dsphdl.FFT

Compute fast Fourier transform (FFT)

Description

The dsphdl.FFT System object™ provides two architectures that implement the algorithm for FPGA and ASIC applications. You can select an architecture that optimizes for either throughput or area.

  • 'Streaming Radix 2^2' — Use this architecture for high-throughput applications. This architecture supports scalar or vector input data. You can achieve gigasamples-per-second (GSPS) throughput, also called super sample rates, using vector input. Since 2025a, this architecture also supports specifying the FFT size by using an input port, when you use scalar input data.

  • 'Burst Radix 2' — Use this architecture for a minimum resource implementation, especially with large fast-Fourier-transform (FFT) sizes. Your system must be able to tolerate bursty data and higher latency. This architecture supports only scalar input data.

The object accepts real or complex data, provides hardware-friendly control signals, and has optional output frame control signals.

To calculate the fast Fourier transform:

  1. Create the dsphdl.FFT object and set its properties.

  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects?

Note

You can also generate HDL code for this hardware-optimized algorithm, without creating a MATLAB® script, by using the DSP HDL IP Designer app. The app provides the same interface and configuration options as the System object.

Creation

Description

FFT_N = dsphdl.FFT returns an HDL FFT System object, FFT_N, that performs a fast Fourier transform.

FFT_N = dsphdl.FFT(Name=Value) sets properties using one or more name-value arguments.

Example: fft128 = dsphdl.FFT(FFTLength=128)

example

Properties

expand all

Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and the release function unlocks them.

If a property is tunable, you can change its value at any time.

For more information on changing property values, see System Design in MATLAB Using System Objects.

Specify the hardware implementation for the FFT.

  • 'Streaming Radix 2^2' — Low-latency architecture. This architecture supports GSPS throughput when you use vector input. Since R2025a, this architecture supports variable FFT length. When you use variable FFT length, your input data must comply with the ready backpressure signal.

  • 'Burst Radix 2'— Minimum resource architecture. This architecture does not support vector input. When you use this architecture, your input data must comply with the ready backpressure signal. This architecture supports only fixed FFT lengths.

For more details about these architectures, see Algorithm.

Since R2025a

You can enter a constant FFT length as a property or provide time-varying FFT length by using an input argument. When you set this property to 'Input port', you enable the log2FFTLen, loadFFTLen, and ready arguments of the object.

Dependencies

This property is only available when you set the Architecture property to 'Streaming Radix 2^2'.

When you set this property to 'Input port', the BitReversedOutput and BitReversedInput properties are read-only. The object uses natural input order and bit-reversed output order.

Number of data points used for one FFT calculation, specified as an integer power of 2 between 22 and 216. The object accepts FFT lengths outside this range, but they are not supported for HDL code generation.

Dependencies

This property is available when you set the Architecture property to 'Burst Radix 2' or you set the FFTLengthSource property to 'Property'.

Since R2025a

Specify the maximum number of data points used for one FFT calculation. This property can help limit the hardware resources needed for a variable-size FFT design. For HDL code generation, the FFT length must be a power of 2 between 22 to 216.

If you provide an input frame after reset without setting the FFT length from the argument, the object uses the FFTLengthMax property value.

Dependencies

This property is available when you set the FFTLengthSource property to 'Input port'.

Specify the hardware implementation for complex multipliers. Each multiplication is implemented either with 'Use 4 multipliers and 2 adders' or 'Use 3 multipliers and 5 adders'. Depending on your synthesis tool and target device, one option may be faster or smaller.

Order of the output data, specified as either:

  • true — The output channel elements are bit reversed relative to the input order.

  • false — The output channel elements are in linear order.

The FFT algorithm calculates output in the reverse order to the input. When you request output in the same order as the input, the algorithm performs an extra reversal operation. For more information on ordering of the output, see Linear and Bit-Reversed Output Order.

Dependencies

When you set the FFTLengthSource property to 'Input port', the BitReversedOutput and BitReversedInput properties are read-only. The object uses natural input order and bit-reversed output order.

Expected order of the input data, specified as either:

  • true — The input channel elements are in bit-reversed order.

  • false — The input channel elements are in linear order.

The FFT algorithm calculates output in the reverse order to the input. When you request output in the same order as the input, the algorithm performs an extra reversal operation. For more information on ordering of the output, see Linear and Bit-Reversed Output Order.

Dependencies

When you set the FFTLengthSource property to 'Input port', the BitReversedOutput and BitReversedInput properties are read-only. The object uses natural input order and bit-reversed output order.

Output scaling, specified as either:

  • true — The object implements an overall 1/FFTLength scale factor by dividing the output of each butterfly multiplication by 2. This adjustment keeps the output of the FFT in the same amplitude range as its input.

  • false — The object avoids overflow by increasing the word length by one bit after each butterfly multiplication. The bit growth is the same for both architectures.

Rounding mode used for internal fixed-point calculations. When the input is any integer or fixed-point data type, the FFT algorithm uses fixed-point arithmetic for internal calculations. This option does not apply when the input is single or double type. Rounding applies to twiddle factor multiplication and scaling operations. For more information about rounding modes, see Rounding Modes.

Enable the reset input argument to the object.

Enable the startOut output argument of the object. When enabled, the object returns an additional output signal that is 1 (true) on the first cycle of each valid output frame.

Enable the endOut output argument of the object. When enabled, the object returns an additional output signal that is 1 (true) on the last cycle of each valid output frame.

Usage

Description

[Y,validOut] = FFT_N(X,validIn) returns the next element of the fast Fourier transform (FFT), Y,calculated from the input, X, when validIn is true. validIn and validOut are logical scalars that indicate the validity of the input and output signals, respectively.

example

[Y,validOut,ready] = FFT_N(X,validIn) returns the next element of the FFT when using the burst Radix 2 architecture. The ready signal indicates when the object has memory available to accept new input samples. When you use the burst architecture, you must send input data only when the ready backpressure signal is 1 (true). The object ignores any input data and valid signals when ready is 0 (false).

To use this syntax, set the Architecture property to 'Burst Radix 2'. For example:

FFT_N = dsphdl.FFT(___,Architecture='Burst Radix 2');
...
[y,validOut,ready] = FFT_N(x,validIn)

[Y,validOut,ready] = FFT_N(X,validIn,log2FFTLen,loadFFTLen) returns the next element of the FFT when configured for a variable size FFT. Specify the log2FFTLen input argument as log2(FFTLength). Set the loadFFTLen input argument to 1 (true) to capture the value from the input log2FFTLen argument.

When you use variable FFT length, you must send input data only when the ready backpressure signal is 1 (true). The object sets the ready output argument to 0 (false) if a new FFT length is supplied while processing a frame of data. The object sets the ready output argument to 1 (true) when it has completed a frame of output data and has updated the FFT length for the next input frame.

To use this syntax, set the FFTLengthSource property to 'Input port'. For example:

FFT_var = dsphdl.FFT(___,Architecture='Streaming Radix 2^2', ...
                       FFTLengthSource='Input port', ...
                       FFTLengthMax=512);
...
[y,validOut,ready] = FFT_var(x,validIn,log2FFTLen,1)
[y,validOut,ready] = FFT_var(x,validIn,log2FFTLen,0)

[Y,startOut,endOut,validOut] = FFT_N(X,validIn) also returns frame control signals startOut and endOut. startOut is 1 (true) with the first sample of a frame of output data. endOut is 1 (true) with the last sample of a frame of output data.

To use this syntax, set the StartOutputPort and EndOutputPort properties to true. For example:

FFT_N = dsphdl.FFT(___,StartOutputPort=true,EndOutputPort=true);
...
[y,startOut,endOut,validOut] = FFT_N(x,validIn)

[Y,validOut] = FFT_N(X,validIn,resetIn) returns the FFT when validIn is 1 (true) and resetIn is 0 (false). When resetIn is 1 (true), the object stops the current calculation and clears all internal state.

To use this syntax set the ResetInputPort property to true. For example:

FFT_N = dsphdl.FFT(___,ResetInputPort=true);
...
[y,validOut] = FFT_N(x,validIn,resetIn)

[Y,startOut,endOut,validOut] = FFT_N(X,validIn,resetIn) returns the FFT, Y, using all optional control signals. You can use any combination of the optional argument syntaxes.

Input Arguments

expand all

Input data, specified as a scalar or column vector of real or complex values, in fixed-point or integer format. Vector input is supported with the 'Streaming Radix 2^2' architecture, and not supported with variable FFT size. The vector size must be a power of 2 between 1 and 64 that is not greater than the FFT length.

The software supports double and single data types for simulation, but not for HDL code generation.

Data Types: fi | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | single | double
Complex Number Support: Yes

Control signal that indicates if the input data is valid. When validIn is 1 (true), the object captures the values from the dataIn argument. When validIn is 0 (false), the object ignores the values from the dataIn argument.

When you set the set the Architecture property to 'Burst Radix 2', or set the FFTLengthSource property to 'Input port', you must comply with the ready backpressure signal. When ready is 1 (true), you can specify the data and valid inputs for the next time step. When ready is 0 (false), the object ignores any input data in the next time step.

Data Types: logical

Since R2025a

Provide the FFT size as log2(FFTLength). For example, if the FFT length is 32, specify 5 for the input argument. For HDL code generation, the FFT length must be a power of 2 between 22 and 216, so the argument value must be in the range 2 to 16. If the value is less than 2, the object uses an FFT length of 4. If the value is greater than 16, the object uses an FFT length of 216.

To capture the value from the log2FFTLen input argument, call the object with the loadFFTLen argument set to 1 (true)

When you use variable FFT length, you must send input data only when the ready backpressure signal is 1 (true). The object sets the ready output argument to 0 (false) if a new FFT length is supplied while processing a frame of data. The object sets the ready output argument to 1 (true) when it has completed a frame of output data and has updated the FFT length for the next input frame.

Dependencies

To enable this argument, set the FFTLengthSource property to 'Input port'.

Data Types: fixdt(0,M,0) where 1<M<6

Since R2025a

Control signal that indicates if the input FFT size is valid. When loadFFTLen is 1 (true), the object captures the value from the log2FFTLen input argument. When loadFFTLen is 0 (false), the object ignores the value from the log2FFTLen input argument.

Dependencies

To enable this argument, set the FFTLengthSource property to 'Input port'.

Data Types: logical

Control signal that clears internal states. When reset is 1 (true), the object stops the current calculation and clears internal states. When the reset is 0 (false) and the input valid is 1 (true), the object captures data for processing.

For more reset considerations, see the Reset Signal section on the Hardware Control Signals page.

Dependencies

To enable this argument, set ResetInputPort to true.

Data Types: logical

Output Arguments

expand all

Output data, returned as a scalar or column vector of real or complex values. When input is fixed-point data type and scaling is enabled, the output data type is the same as the input data type. When the input is integer type and scaling is enabled, the output is fixed-point type with the same word length as the input integer. The output order is bit-reversed by default. If scaling is disabled, the output word length increases to avoid overflow. For more information, see the Normalize property.

Control signal that indicates if the output data is valid. When validOut is 1 (true), the object returns valid data from the dataOut argument. When validOut is 0 (false), values from the dataOut argument are not valid.

Data Types: logical

Control signal that indicates that the object is ready for new input data sample on the next cycle. When ready is 1 (true), you can specify the data and valid inputs for the next time step. When ready is 0 (false), the object ignores any input data in the next time step.

For a waveform that shows this protocol, see the timing diagrams in the Control Signals section.

Dependencies

To enable this output argument, set the Architecture property to 'Burst Radix 2', or with Architecture set to 'Streaming Radix 2^2', set the FFTLengthSource property to 'Input port'.

Data Types: logical

Control signal that indicates the first valid cycle of the output frame, returned as a logical scalar.

Dependencies

To enable this argument, set the StartOutputPort property to true.

Data Types: logical

Control signal that indicates the last valid sample of output frame, returned as a logical scalar.

Dependencies

To enable this argument, set the EndOutputPort property to true.

Data Types: logical

Object Functions

To use an object function, specify the System object as the first input argument. For example, to release system resources of a System object named obj, use this syntax:

release(obj)

expand all

getLatencyLatency of FFT calculation
stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

Examples

collapse all

Create the specifications and input signal.

N = 128;
Fs = 40;
t = (0:N-1)'/Fs;
x = sin(2*pi*15*t) + 0.75*cos(2*pi*10*t);
y = x + .25*randn(size(x));
y_fixed = fi(y,1,32,24);

Write a function that creates and calls the System object™. You can generate HDL from this function.

function [yOut,validOut] = HDLFFT128(yIn,validIn)
%HDLFFT128 
% Processes one sample of FFT data using the dsphdl.FFT System object(TM)
% yIn is a fixed-point scalar or column vector. 
% validIn is a logical scalar value.
% You can generate HDL code from this function.

  persistent fft128;
  if isempty(fft128)
    fft128 = dsphdl.FFT(FFTLength=128);
  end    
  [yOut,validOut] = fft128(yIn,validIn);
end

% Copyright 2012-2023 The MathWorks, Inc.

Compute the FFT by calling the function for each data sample.

Yf = zeros(1,3*N);
validOut = false(1,3*N);
for loop = 1:1:3*N
    if (mod(loop, N) == 0)
        i = N;
    else
        i = mod(loop, N);
    end
    [Yf(loop),validOut(loop)] = HDLFFT128(complex(y_fixed(i)),(loop <= N));
end

Discard invalid data samples. Then plot the frequency channel results from the FFT.

Yf = Yf(validOut == 1);
Yr =  bitrevorder(Yf);
plot(Fs/2*linspace(0,1,N/2), 2*abs(Yr(1:N/2)/N))
title('Single-Sided Amplitude Spectrum of Noisy Signal y(t)')
xlabel('Frequency (Hz)')
ylabel('Output of FFT (f)')

Create specifications and input signal. This example uses a 128-point FFT and computes the transform over 16 samples at a time.

N = 128;
V = 16;
Fs = 40;
t = (0:N-1)'/Fs;
x = sin(2*pi*15*t) + 0.75*cos(2*pi*10*t);
y = x + .25*randn(size(x));
y_fixed = fi(y,1,32,24);
y_vect = reshape(y_fixed,V,N/V);

Write a function that creates and calls the System object™. The function does not need to know the vector size. The object saves the size of the input signal the first time you call it.

function [yOut,validOut] = HDLFFT128V16(yIn,validIn)
%HDLFFT128V16 
% Processes 16-sample vectors of FFT data 
% yIn is a fixed-point column vector. 
% validIn is a logical scalar value.
% You can generate HDL code from this function.

  persistent fft128v16;
  if isempty(fft128v16)
    fft128v16 = dsphdl.FFT(FFTLength=128);
  end    
  [yOut,validOut] = fft128v16(yIn,validIn);
end

% Copyright 2012-2023 The MathWorks, Inc.

Compute the FFT by passing 16-element vectors to the object. Use the getLatency function to find out when the first output data sample will be ready. Then, add the frame length to determine how many times to call the object. Because the object variable is inside the function, use a second object to call getLatency. Use the loop counter to flip validIn to false after N input samples.

tempfft = dsphdl.FFT;
loopCount = getLatency(tempfft,N,V)+N/V;
Yf = zeros(V,loopCount);
validOut = false(V,loopCount);
for loop = 1:1:loopCount
    if ( mod(loop,N/V) == 0 )
        i = N/V;
    else
        i = mod(loop,N/V);
    end
    [Yf(:,loop),validOut(loop)] = HDLFFT128V16(complex(y_vect(:,i)),(loop<=N/V));
end

Discard invalid output samples.

C = Yf(:,validOut==1);
Yf_flat = C(:);

Plot the frequency channel data from the FFT. The FFT output is in bit-reversed order. Reorder it before plotting.

Yr =  bitrevorder(Yf_flat);
plot(Fs/2*linspace(0,1,N/2),2*abs(Yr(1:N/2)/N))
title('Single-Sided Amplitude Spectrum of Noisy Signal y(t)')
xlabel('Frequency (Hz)')
ylabel('Output of FFT (f)')

The latency of the object varies with the FFT length and the vector size. Use the getLatency function to find the latency of a particular configuration. The latency is the number of cycles between the first valid input and the first valid output, assuming that the input is contiguous.

Create a new dsphdl.FFT object and request the latency.

hdlfft = dsphdl.FFT(FFTLength=512);
L512 = getLatency(hdlfft)
L512 = 
599

Request hypothetical latency information about a similar object with a different FFT length. The properties of the original object do not change.

L256 = getLatency(hdlfft,256)
L256 = 
329
N = hdlfft.FFTLength
N = 
512

Request hypothetical latency information of a similar object that accepts eight-sample vector input.

L256v8 = getLatency(hdlfft,256,8)
L256v8 = 
93

Enable scaling at each stage of the FFT. The latency does not change.

hdlfft.Normalize = true;
L512n = getLatency(hdlfft)
L512n = 
599

Request the same output order as the input order. The latency increases because the object must collect the output before reordering.

hdlfft.BitReversedOutput = false;
L512r = getLatency(hdlfft)
L512r = 
1078

Algorithms

expand all

Extended Capabilities

expand all

Version History

Introduced in R2014b

expand all

See Also

Objects

Blocks