how to implement this function in fixed point and generate the hdl code for the function?
2 views (last 30 days)
i have the function below and i want to generate hdl code for it and to convert it to fixed point for virsualization in simulink, i get the error that (exp and spdiags) are not supported for hdl code generation. i also have a simple testbench for calling this function.
unction [c, count]=sfft(x)
% Input: x, can be a vector (row or column) or matrix. When x is
% matrix, the Fourier transform is performed columnwise.
% The length of x is expected to be a power of 2. If not,
% zeros will be padded to the end of x to increase its length
% the next power of 2. Multidimensional array inputs are not
% Output: c, the complex Fourier coefficients. Its preserves the
% dimensions of the x when zero-padding is not applied to x.
% If zero-padding is applied, c will be longer or taller
% than x.
global count % for counting the number of multiplications.
%% Prepare for the recursive call.
if siz1==1 % x is a row vector
if mod(ell, 1)~=0,
ell=ceil(ell); n=2^ell; x(end+1:n)=0; zeropad=true;
x=x(:); % recur_sfft requires a column vector.
else % x is a column vector or matrix
if mod(ell, 1)~=0,ell=ceil(ell); n=2^ell; x(end+1:n,:)=0; end
warning('The input has been zero-padded to increase its length to the next power of 2.')
c_even=recur_sfft(x(1:2:n,:)); % (0:2:n-1)+1
c_odd=recur_sfft(x(2:2:n,:)); % (1:2:n-1)+1
% even means (0:2:n-1),and odd means 1:2:n-1 but they need to be added by 1 to meet Matlab's 1-based indices.
D=spdiags(w.^(k-1).',0, k(end), k(end));
% counting number of multiplications
% fill in the second half of c first
% which has also pre-allocated RAM for the first half of c
% now do the first half of X.
% the bottom is reached, 2-point of x.
Bharath Venkataraman on 3 Aug 2022
Edited: Bharath Venkataraman on 5 Aug 2022
For HDL, you will need to implement this in a streaming fashion. lease take a look at the FFT Streaming model provided in this example. You will need to modify it to pad in zeros when the size of the input is smaller than the FFT size.