From: Michael Hosea on
Apparently afsb0 has the wrong size. Make sure it has the same size as
fsb0.
--
Mike

"khan Sim" <akhun85(a)yahoo.com> wrote in message
news:hsdb3s$ffb$1(a)fred.mathworks.com...
> well i am facing another problem while executing the code written by you.
> i want to use this code as a function in matlab embedded function block.
> function fsb0 = fcn(amp_max,P_max,afsb0)
> %#eml
> fsb0=zeros(1,512);
> for k = 1:length(fsb0)
> if afsb0(k) > amp_max*P_max
> fsb0(k) =
> (amp_max*(P_max^2)./afsb0(k)).*exp(sqrt(-1)*angle(fsb0(k)));
> end
> end
>
>
> when i run the simulation of this function block, i face errors like,
> "Embedded MATLAB Interface Error: Simulation stopped due to out of bounds
> error.
> Block Embedded MATLAB Function2 (#55)
> While executing: none"
>
> kindly guide me here, thanx
> kind regards


From: Michael Hosea on
Why is fsb0 not an input? Be that as it may, you introduced this problem by
writing

> fsb0=zeros(1,512);

You should have written

fsb0=complex(zeros(1,512));

BTW, you don't need to define cj like that. The expression 1j or 1i both
refer to sqrt(-1). Actually, by default i and j do as well, but using i and
j alone for sqrt(-1) is not recommended because you may re-define these
variables in your code. Writing 1i or 1j, on the other hand, always gives
sqrt(-1) no matter what.

However, it makes little sense to set fsb0 to zeros because that would make
exp(cj*angle(fsb0(k)))=1.
--
Mike

"khan Sim" <akhun85(a)yahoo.com> wrote in message
news:hsdeuj$eus$1(a)fred.mathworks.com...
> well the latest progress is when i used the following code using the
> matlab embedded function block, errors were given
>
>
> function fsb0 = fcn(amp_max,P_max,afsb0)
> %#eml
> fsb0=zeros(1,512);
> cj=sqrt (complex(-1))
> for k = 1:length(fsb0)
> if afsb0(k) > amp_max*P_max
> fsb0(k) = (amp_max*(P_max^2)./afsb0(k)).*exp(cj*angle(fsb0(k)));
> end
> end
>
>
> when i run this code in the matlab embedded coder the following error is
> given.
>
> "The left-hand side has been constrained to be non-complex, but the
> right-hand side is complex. To correct this problem, make the right-hand
> side real using the function REAL, or change the initial assignment to the
> left-hand side variable to be a complex value using the COMPLEX function.
>
> Function 'Embedded MATLAB Function2' (#54.151.214), line 7, column 9:
> "fsb0(k) = (amp_max*(P_max^2)./afsb0(k)).*exp(cj*angle(fsb0(k)))"
> Launch diagnostic report."
>
> Kindly help me out in this regard
>
> thanx
>


From: khan Sim on
well i ve again cheked the original code debuged the original code and in this code fsb0 is a matrix of size [1x512]. it is not wrong, the problem is somewhere else, kindly have a look again and guide me accordingly.

afsb0=abs(fsb0);
fsbo=[1x512] of complex data type

i ve initialized the fsbo to zeros(1,512) which is done by mistake, fsbo is the result of fft of a vector.

fsb0=fftshift(fft(fftshift(sb0.'))).';

where sb0 is the input vector to fsb0 and the order of fsb0 is [1x512]
now the whole code becomes like this

cj=sqrt(-1);
fsb0=fftshift(fft(fftshift(sb0.'))).';
mag=abs(fsb0);
amp_max=1/sqrt(2);
afsb0=abs(fsb0);
P_max=max(afsb0);
for k = 1:length(fsb0)
if afsb0(k) > amp_max*P_max
fsb0(k) = (amp_max*(P_max^2)./afsb0(k)).*exp(cj*angle(fsb0(k)));
end
end

i want to to implement this code on embedded matlab function block. then i have to convert this code to verilog for fpga processing,

now i want to to work on the following code in an embedded matlab function block

function fsb0 = fcn(amp_max,P_max,afsb0)
%#eml;
cj=sqrt(complex(-1));
for k = 1:length(fsb0)
if afsb0(k) > amp_max*P_max
fsb0(k) = (amp_max*(P_max^2)./afsb0(k)).*exp(cj*angle(fsb0(k)));
end
end

i need to initialize to define the size of afsb0, how can i define its size to be afsb0, ?
how can run this code with out error on matlab embedded function block?

thanx for your time.

waiting anxiously for your reply
kind regards
From: khan Sim on
well because of support from you and your time, i have been able to to write the code with out error,

this simulation worked with the following code

function fsb0 = fcn(amp_max,P_max,afsb0)
cj=sqrt(complex(-1));
fsb0=complex(zeros(1,512));
for k = 1:512
if afsb0(k) > amp_max*P_max
fsb0(k) = (amp_max*(P_max^2)./afsb0(k)).*exp(cj*angle(fsb0(k)));
end
end

now in the above code i have defined the type and size of fsb0 as [1x512].
fsb0=complex(zeros(1,512)); for simulation purpose,

actually fsb0 is coming from another block. i want to apply the code on fsb0 as any complex input of size [1x512].
kindly help me out.
thanx.