0
votes

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

1
Could you indent your code 4 spaces so it's easier to read, please? StackOverflow will keep your indentation and also syntax highlight your code if you do that.Benjamin Oakes
or highlight it and hit the 'ones and zeros' button if you don't like hitting the home>four spaces>down arrow combo over and over againDoresoom
@Doresoom: Huh, I didn't know it did that. I guess that's what I get for always editing my posts in Vim... :)Benjamin Oakes
Here is similar question, if it helps: stackoverflow.com/questions/1259001/…yuk

1 Answers

1
votes
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);