我最近开始使用 MATLAB Simulink,我的问题是我无法实现 AMDF 函数,因为 simulink 编译器无法确定长度。
Simulink 错误:
|---------------------------------------------- -----------------------------------------
无法确定此表达式的大小。
函数“嵌入式 MATLAB Function2”(#38.728.741),第 33 行,第 32 列:“1:flength-k+1”
解析 Embedded MATLAB function 'Embedded MATLAB Function2' (#38) 时出错
嵌入式 MATLAB 接口错误:在解析嵌入式 MATLAB 函数“嵌入式 MATLAB 函数 2”(#38) 期间发生错误。
|------------------------------------------------- --------------------------------------
我的代码:
|------------------------------ -----------------------------------------
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>
|------------------------------------------------- ---------------------------------------
帮助
亲切的问候
索伦