vhdl coding of matlab embedded ftn

5 views (last 30 days)
Hi
Following is the serialized matlab code of the cooley tukey algorithm ifft that i want to cosimulate in my Simulink model but i dont get the idea that how to do it.
What necessary steps are additionally required
I learned a lot from demos that
First convert it to fix point ,Then apply hdl coder but:
  1. How to assign fix point data types,
  2. and can the Matlab complex number multiplication, addition and other arithrematic operation in use can be directly converted to hdl code or not.
p.s the code works perfectly in the simulink model.
The code is given below:
function y = iffxt( u )
b = numerictype(1, 16, 15);
c = numerictype(1, 16, 15);
d = numerictype(1, 16, 15);
e = numerictype(1, 16, 15);
x = numerictype(1, 16, 15);
x = [ u(1);u(2);u(3);1;u(4);u(5);u(6);0;0;u(7);u(8);u(9);-1;u(10);u(11);u(12);];
b = [x(1)+x(9); x(2)+x(10); x(3)+x(11); x(4)+x(12); x(5)+x(13); x(6)+x(14); x(7)+x(15); x(8)+x(16); x(1)-x(9); x(2)-x(10); x(3)-x(11); x(4)-x(12);x(5)-x(13); x(6)-x(14) ;x(7)-x(15); x(8)-x(16);];
c = [ b(1)+b(5); b(2)+b(6); b(3)+b(7); b(4)+b(8); b(1)-b(5); b(2)-b(6); b(3)-b(7); b(4)-b(8); b(9)+b(13)*1j; b(10)+b(14)*1j; b(11)+b(15)*1j; b(12)+b(16)*1j; b(9)+b(13)*-1j; b(10)+b(14)*-1j; b(11)+b(15)*-1j; b(12)+b(16)*-1j;];
d = [ c(3)+c(1); c(4)+c(2); c(1)-c(3); c(2)-c(4); c(5)+c(7)*1j; c(6)+c(8)*1j;c(5)+c(7)*-1j; c(6)+c(8)*-1j; c(9)+c(11)*(.7071+.7071j); c(10)+c(12)*(.7071+.7071j); c(9)+c(11)*(-.7071-.7071j); c(10)+c(12)*(-.7071-.7071j); c(13)+c(15)*(-.7071+.7071j);c(14)+c(16)*(-.7071+.7071j); c(13)+c(15)*(.7071-.7071j);c(14)+c(16)*(.7071-.7071j); ];
e = [ d(1)+d(2); d(1)-d(2); 1i*d(4)+d(3); -1i*d(4)+d(3);d(5)+d(6)*(.7071+.7071j); d(5)+d(6)*(-.7071-.7071j); d(7)+d(8)*(-.7071+.7071j); d(7)+d(8)*(.7071-.7071j); d(9)+d(10)*(.923879532+.382683432j) ; d(9)+d(10)*(-.923879532-.382683432j); d(11)+d(12)*(-.382683432+.923879532j); d(11)+d(12)*(.382683432-.923879532j);d(13)+d(14)*(.382683432+.923879532j); d(13)+d(14)*(-.382683432-.923879532j); d(15)+d(16)*(-.923879532+.382683432j);d(15)+d(16)*(.923879532-.382683432j);];
y = [e(1);e(16);e(8);e(12);e(4);e(14);e(6);e(10);e(2);e(15);e(7);e(11);e(3);e(13);e(5);e(9);]*.0625;

Accepted Answer

Walter Roberson
Walter Roberson on 24 Mar 2011
My recollection from seeing a past query is that code generation for complex numbers is not supported.

More Answers (1)

Tim McBrayer
Tim McBrayer on 31 Jan 2012
For your first question, the Simulink Fixed-Point Advisor might be able to help you convert your design from floating point to fixed point.
The answer to your second question is yes, Simulink HDL Coder can convert complex arithmetic operations to HDL code. It can do so from Simulink blocks such as Product and Gain as well as from the MATLAB Function block. Any complex signals are automatically flattened into separate real and imaginary parts and the correct operations applied to the inputs. For example, the following code snippet is the VHDL output from a complex fixed-point multiply in a MATLAB Function block. The inputs u (u_re + u_im*i) and v (v_re + v_im*i) are of type sfix15_En8, and the output y (y_re + y_im*i)is sfix31_En16.
pr1 <= u_re * v_re;
pr2 <= u_im * v_im;
pr1in <= resize(pr1, 31);
pr2in <= resize(pr2, 31);
pre <= pr1in - pr2in;
pi1 <= u_re * v_im;
pi2 <= u_im * v_re;
pi1in <= resize(pi1, 31);
pi2in <= resize(pi2, 31);
pim <= pi1in + pi2in;
y_re <= pre;
y_im <= pim;

Community Treasure Hunt

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

Start Hunting!