I want to make a function that computes the value of the Scallop loss for a Rectangular, Hamming and Blackman window using the Scallop loss formula. I have created a function but it only returns that answer 0, have I made an error?
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;
You have a maths problem:
abs(sum(A)) != sum(abs(A))
They are not the same!
Change your code to:
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;