how to implement this function in fixed point and generate the hdl code for the function?

1 Ansicht (letzte 30 Tage)
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.
f
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
% supported.
%
% 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.
count=0; zeropad=false;
[siz1 siz2]=size(x);
if siz1==1 % x is a row vector
n=siz2;
ell=log2(n);
if mod(ell, 1)~=0,
ell=ceil(ell); n=2^ell; x(end+1:n)=0; zeropad=true;
end
x=x(:); % recur_sfft requires a column vector.
c=recur_sfft(x);
c=c.';
else % x is a column vector or matrix
n=siz1;
ell=log2(n);
if mod(ell, 1)~=0,ell=ceil(ell); n=2^ell; x(end+1:n,:)=0; end
c=recur_sfft(x);
end
if zeropad
warning('The input has been zero-padded to increase its length to the next power of 2.')
end
function c=recur_sfft(x)
global count
n=size(x,1);
if n>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.
k=1:n/2;
w=exp(-pi*2i/n);
D=spdiags(w.^(k-1).',0, k(end), k(end));
c_odd=D*c_odd;
count=count+k(end)*size(c_odd,2);
% counting number of multiplications
% fill in the second half of c first
c(k+n/2,:)=c_even-c_odd;
% which has also pre-allocated RAM for the first half of c
% now do the first half of X.
c(k,:)=c_even+c_odd;
else
% the bottom is reached, 2-point of x.
c=[x(1,:)+x(2,:)
x(1,:)-x(2,:)];
end

Antworten (1)

Bharath Venkataraman
Bharath Venkataraman am 3 Aug. 2022
Bearbeitet: Bharath Venkataraman am 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.

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by