MATLAB: I am trying to convert the built in dsp.HDLIFFT function to HDL. When I get to the Fixed-Point Conversion step it states the inputs to the system object are not of the same type. How could I resolve this issue

fpgahdlHDL CoderMATLAB

Test Bench File:
% FFT length
N = 128;
% create input sine wave
Fs = 40;
t = (0:N-1)'/Fs;
y = sin(t);
% convert input signal to fixed point
y_fixed = sfi(y, 32, 24);
hfft = dsp.HDLFFT('FFTLength',N,'OverflowAction','Saturate', 'RoundingMethod', 'Nearest', 'BitReversedOutput', false);
Yf = zeros(1,4*N);
validOut = false(1,4*N);
for loop = 1:1:N
[Yf(loop),validOut(loop)] = step(hfft, complex(y_fixed(loop)), true);
end
for loop = N+1:1:4*N
[Yf(loop),validOut(loop)] = step(hfft, complex(0), false);
end
% strip non-valid output data
Yf = Yf(validOut == 1);
[Xout] = IFFT_128( Yf );
Function:
function [ Xout ] = IFFT_128( X )
persistent hifft;
hifft = dsp.HDLIFFT('FFTLength',128,'OverflowAction','Saturate', 'RoundingMethod', 'Nearest' , 'BitReversedOutput', false);
Xt = complex(zeros(1,3*128));
validOut = false(1,3*128);
for loop = 1:1:128
[Xt(loop),validOut(loop)] = step(hifft, complex(X(loop)),true);
end
for loop = 128+1:1:3*128
[Xt(loop),validOut(loop)] = step(hifft, complex(0),false);
end
% grab only valid data
Xout = Xt(validOut==1);
end
The error I encounter is when the Workflow Advisor is on the Fixed-Point Conversion step. The error is:
Wrong class of input #1: expected 'embedded.fi', got 'double'. Code generation requires that all calls to step() on same object have inputs of same type.

Best Answer

There are two changes you should make to the code.
  1. Remove the assignment of double values to Yf.
  2. Assuming that you want to generate HDL code next, the function IFFT_128 should not contain any for loops. Instead the for loop should be in the Testbench.
Take a look at this MATLAB Answers response to see how to make the changes.