In the following code, the statement with buildInstrumentedMex gives the error "Unknown exception" while fiaccel is working fine. So the code generation must be OK. I do not have a license for code generation, but the examples from the Fixed Point Designer Getting Started Guide with buildInstrumentedMex are working fine. What am I missing?
T = mytypes('9Q23');Hinp = cast(ones(2,2)+1j*ones(2,2),'like',T.x);fiaccel inv4fix -args {Hinp,T} -o fiaccelinv4fix_mexH1 = cast([ 0.1+1j*0.2 0.3+1j*0.4; 0.5+1j*0.6 0.7+1j*0.8 ],'like',T.x);H1inv = fiaccelinv4fix_mex(H1,T);buildInstrumentedMex înv4fix -args {Hinp,T} -histogram -o inv4fix_mexwhere % mytypes.m
function T = mytypes(dt) switch dt case '9Q23' F = fimath('RoundingMethod', 'Nearest', ... 'OverflowAction', 'Saturate', ... 'ProductMode', 'SpecifyPrecision', ... 'ProductWordLength', 32, ... 'ProductFractionLength', 23, ... 'SumMode', 'SpecifyPrecision', ... 'SumWordLength', 32, ... 'SumFractionLength', 23, ... 'CastBeforeSum', true); T.x = fi([],true,32,23,F); endend% inv4fix.m
function Hinv = inv4fix(H,T) %#codegen
if size(H,1)==2; % inverse of [a b; c d] is 1/(ad-bc) [d -b; -c a]
% fixed point types
Tdiv = numerictype('Signed',true,'WordLength',T.x.WordLength,'FractionLength',T.x.FractionLength); % real algorithm
a = cast(H(1,1),'like',T.x); b = cast(H(1,2),'like',T.x); c = cast(H(2,1),'like',T.x); d = cast(H(2,2),'like',T.x); factor = cast((a*d - b*c),'like',T.x); % 1/(a+1j*b) = (a-1j*b)/(a^2+b^2)
factor_r = cast(real(factor),'like',T.x); factor_i = cast(imag(factor),'like',T.x); denominator = cast(factor_r*factor_r + factor_i*factor_i,'like',T.x); factor_r = divide(Tdiv,factor_r,denominator); factor_i = divide(Tdiv,factor_i,denominator); Hinv = [d -b; -c a]; Hinv = cast((factor_r-1j*factor_i) * Hinv,'like',T.x);else Hinv = H;endend
Best Answer