Main Content

dsphdl.IFFT

Compute inverse fast Fourier transform (IFFT)

Description

The dsphdl.IFFT 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 inverse fast Fourier transform:

  1. Create the dsphdl.IFFT 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

IFFT_N = dsphdl.IFFT returns an HDL IFFT System object, IFFT_N, that performs a fast Fourier transform.

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

Example: ifft128 = dsphdl.IFFT(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 IFFT 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 IFFT 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 IFFT 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] = IFFT_N(X,validIn) returns the next element of the inverse fast Fourier transform (IFFT), 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] = IFFT_N(X,validIn) returns the next element of the IFFT 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:

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

[Y,validOut,ready] = IFFT_var(X,validIn,log2FFTLen,loadFFTLen) returns the next element of the IFFT 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:

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

[Y,startOut,endOut,validOut] = IFFT_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:

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

[Y,validOut] = IFFT_N(X,validIn,resetIn) returns the IFFT, Y, 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:

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

[Y,startOut,endOut,validOut] = IFFT_N(X,validIn,resetIn) returns the IFFT, 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. This example uses a 128-point FFT.

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,16);
noOp = zeros(1,'like',y_fixed);

Compute the FFT of the signal to use as the input to the IFFT object.

hdlfft = dsphdl.FFT(FFTLength=N,BitReversedOutput=false);
Yf = zeros(1,4*N);
validOut = false(1,4*N);
for loop = 1:1:N
   	  [Yf(loop),validOut(loop)] = hdlfft(complex(y_fixed(loop)),true);
end
for loop = N+1:1:4*N
	  [Yf(loop),validOut(loop)] = hdlfft(complex(noOp),false);
end
Yf = Yf(validOut == 1);

Plot the single-sided amplitude spectrum.

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

Select frequencies that hold the majority of the energy in the signal. The cumsum function does not accept fixed-point arguments, so convert the data back to double.

[Ysort,i] = sort(abs(double(transpose(Yf(1:N)))),1,'descend');
Ysort_d = double(Ysort);
CumEnergy = sqrt(cumsum(Ysort_d.^2))/norm(Ysort_d);
j = find(CumEnergy > 0.9, 1);
     disp(['Number of FFT coefficients that represent 90% of the ', ...
     'total energy in the sequence: ', num2str(j)])
Yin = zeros(N,1);
Yin(i(1:j)) = Yf(i(1:j));
Number of FFT coefficients that represent 90% of the total energy in the sequence: 4

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

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

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

% Copyright 2012-2023 The MathWorks, Inc.

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

Xt = zeros(1,3*N);
validOut = false(1,3*N);
for loop = 1:1:N
    [Xt(loop),validOut(loop)] = HDLIFFT128(complex(Yin(loop)),true);
end
for loop = N+1:1:3*N
    [Xt(loop),validOut(loop)] = HDLIFFT128(complex(0),false);
end

Discard invalid output samples. Then inspect the output and compare it with the input signal. The original input is in green.

Xt = Xt(validOut==1);
Xt = bitrevorder(Xt);
norm(x-transpose(Xt(1:N)))
figure
stem(real(Xt))
figure
stem(real(x),'--g')
ans =

    0.7863

Create the 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);

Compute the FFT of the signal, to use as the input to the IFFT object.

hdlfft = dsphdl.FFT('FFTLength',N);
loopCount = getLatency(hdlfft,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)] = hdlfft(complex(y_vect(:,i)),(loop<=N/V));
end

Plot the single-sided amplitude spectrum.

C = Yf(:,validOut==1);
Yf_flat = C(:);
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)')

Select frequencies that hold the majority of the energy in the signal. The cumsum function doesn't accept fixed-point arguments, so convert the data back to double.

[Ysort,i] = sort(abs(double(Yr(1:N))),1,'descend');
CumEnergy = sqrt(cumsum(Ysort.^2))/norm(Ysort);
j = find(CumEnergy > 0.9, 1);
     disp(['Number of FFT coefficients that represent 90% of the ', ...
     'total energy in the sequence: ', num2str(j)])
Yin = zeros(N,1);
Yin(i(1:j)) = Yr(i(1:j));
YinVect = reshape(Yin,V,N/V);
Number of FFT coefficients that represent 90% of the total energy in the sequence: 4

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

function [yOut,validOut] = HDLIFFT128V16(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 ifft128v16;
  if isempty(ifft128v16)
    ifft128v16 = dsphdl.IFFT(FFTLength=128)
  end    
  [yOut,validOut] = ifft128v16(yIn,validIn);
end

% Copyright 2012-2023 The MathWorks, Inc.

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

Xt = 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
 	  [Xt(:,loop),validOut(loop)] = HDLIFFT128V16(complex(YinVect(:,i)),(loop<=N/V));
end
ifft128v16 = 

  dsphdl.IFFT with properties:

   Main
             Architecture: 'Streaming Radix 2^2'
          FFTLengthSource: 'Property'
                FFTLength: 128
    ComplexMultiplication: 'Use 4 multipliers and 2 adders'
        BitReversedOutput: true
         BitReversedInput: false
                Normalize: true

  Use get to show all properties

Discard invalid output samples. Then inspect the output and compare it with the input signal. The original input is in green.

C = Xt(:,validOut==1);
Xt = C(:);
Xt = bitrevorder(Xt);
norm(x-Xt(1:N))
figure
stem(real(Xt))
figure
stem(real(x),'--g')
ans =

    0.7863

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.IFFT object and request the latency.

hdlifft = dsphdl.IFFT(FFTLength=512);
L512 = getLatency(hdlifft)
L512 = 
599

Request hypothetical latency information about a similar object with a different FFT length. The properties of the original object do not change. When you do not specify a vector length, the function assumes scalar input data.

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

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

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

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

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

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

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

Algorithms

expand all

Extended Capabilities

expand all

Version History

Introduced in R2014b

expand all

See Also

Objects

Blocks