Søren
Søren

Reputation: 1

Could not determine the size of this expression

I have resently started to use MATLAB Simulink, and my problem is that i can't implement an AMDF function, because simulink compiler cannot determine the lengths.

Simulink errors:
|---------------------------------------------------------------------------------------
Could not determine the size of this expression.

Function 'Embedded MATLAB Function2' (#38.728.741), line 33, column 32: "1:flength-k+1"

Errors occurred during parsing of Embedded MATLAB function 'Embedded MATLAB Function2'(#38)

Embedded MATLAB Interface Error: Errors occurred during parsing of Embedded MATLAB function 'Embedded MATLAB Function2'(#38) .
|---------------------------------------------------------------------------------------


MY CODE:
|---------------------------------------------------------------------------------------

function [voiced,minAMDF] = bnrDisAMDF(frame,fs,lvlThr,fspan)<br>
<br>
persistent sLength<br>
persistent fLength<br>
persistent amdf<br>

% Length of the frame<br>
flength = length(frame);<br>

% Pitch period is between 2.5 ms and 19.5 ms for LPC-10 algorithm<br>
% This because this algorithm assumes the frequencyspan is 50 and 400 Hz
pH = ceil((1/min(fspan))*fs);<br>
if(pH > flength)<br>
    pH = flength;<br>
end;<br>
<br>
pL = ceil((1/max(fspan))*fs);<br>
if(pL <= 0 || pL >= flength)<br>
    pL = 0;<br>
end;<br>
<br>
sLength = pH - pL;<br>
<br>
% Normalize the frame<br>
frame = frame/max(max(abs(frame)));<br>
<br>
% Allocating memory for the calculation of the amdf<br>
%amdf = zeros(1,sLength); %%%%%%%%<br>
amdf = 0;<br>
<br>
% Calculating the AMDF with unbiased normalizing<br>
for k = (pL+1):pH<br>
    amdf(k-pL) = sum(abs(frame(1:flength-k+1) - frame(k:flength)))/(flength-k+1);<br>
end;<br>
<br>
% Output of the AMDF<br>
if(min(amdf) < lvlThr)<br>
    voiced = 1;<br>
else<br>
    voiced = 0;<br>
end;<br>
<br>
% Output of the minimum of the amdf<br>
minAMDF = min(amdf);<br>


|----------------------------------------------------------------------------------------
HELP

Kind regards

Søren

Upvotes: 0

Views: 1225

Answers (1)

fathi
fathi

Reputation: 11

waveFile='sunday.wav';
[y, fs, nbits]=wavread(waveFile);
index1=9000;
frameSize=512;
index2=index1+frameSize-1;
frame=y(index1:index2);
maxShift=length(frame);
plotOpt=1;
method=2;
frame2amdf(frame, maxShift, method, plotOpt);

Upvotes: 1

Related Questions