计算扇贝损失的函数

时间:2016-12-01 13:14:41

标签: matlab signal-processing windowing

我想创建一个函数,使用扇贝损失公式计算矩形,汉明和布莱克曼窗口的扇贝损失值。 我创建了一个函数,但它只返回了答案0,我犯了错误吗?

function s_l = scallop loss(len)
window = rectwin(len);
num_total = 0;
den_total = 0;

for n = 0:len-1
    A1 = exp(-((1i*(n)*pi)/len));
    A2 = window(n+1)*A1;
    num = abs(A2);
    den = win(n+1);
    num_total = num_total + num;
    den_total = den_total + den:
end

result = 20*log(num_total/den_total);

s_l = result;

Scallop Loss Formula

2 个答案:

答案 0 :(得分:2)

你有数学问题:

abs(sum(A)) != sum(abs(A))

他们不一样!

将您的代码更改为:

window = rectwin(len);
num_total = 0;
den_total = 0;

for n = 0:len-1
    A1 = exp(-((1i*(n)*pi)/len));
    A2 = window(n+1)*A1;
    num = A2;                      % !!
    den = abs(window(n+1));        % you also forgot the abs  here
    num_total = num_total + num;
    den_total = den_total + den;
end
num_total=abs(num_total);    % !!
result = 20*log(num_total/den_total);

s_l = result;

答案 1 :(得分:1)

请将log()函数更改为log10()。没有它,结果是完全错误的:)

我的意思是这一行: 结果= 20 * log10 *(num_total / den_total);