function [ EVAL ] = analyzeMdSvMolLf( freq_resp,SOURCE,EVAL, kgrid)


min_freq_bin=max(find(freq_resp.f_array(1,:)<28.2));
max_freq_bin=max(find(freq_resp.f_array(1,:)<112));

start_x=(SOURCE.coordX+2)*kgrid.Ny+1;
for i=1:kgrid.Ny;
listening(kgrid.Nx*(i-1)-SOURCE.coordX*(i-1)+i:i*kgrid.Nx-i*SOURCE.coordX+i,:)=...
    freq_resp.freq_resp(kgrid.Nx*(i-1)+SOURCE.coordX:i*kgrid.Nx,min_freq_bin:max_freq_bin);
end

EVAL.f_array=freq_resp.f_array(start_x:end,min_freq_bin:max_freq_bin);
EVAL.audience_resp=listening;
%% MD
for i=1:length(listening(:,1));
diff_sqrd(i,:)=(listening(i,:)-mean(listening(i,:))).^2;
diff_sum(i,:)=sum(diff_sqrd(i,:));
EVAL.MD(i,:)=(1/(length(listening(i,:))-1)*diff_sum(i,:))^(1/2);
end

%% SV
Nf=length(listening(1,:));
Np_1=length(listening(:,1))-1;
Lpi=mean(listening(:,:));

for i=1:length(listening(:,1));
brack(i,:)=(listening(i,:)-Lpi).^2;
end

EVAL.SV=((1/Nf)*sum((1/Np_1)*sum(brack))).^(1/2);
%% Lp_foh
EVAL.Xbin=round(EVAL.fohX/kgrid.dx);
EVAL.Ybin=round(EVAL.fohY/kgrid.dy);
EVAL.num_i=EVAL.Ybin*kgrid.Nx-kgrid.Nx+EVAL.Ybin;

EVAL.Lp_foh=mean(freq_resp.freq_resp(EVAL.num_i,min_freq_bin:max_freq_bin));


%% MOL_resp.freq_resp(1,:))
Nf=length(listening(1,:));
Np=length(listening(:,1));
EVAL.MOL=(1/(Nf*Np))*sum(sum(listening(:,:)));

%% LF factor
EVAL.LF=EVAL.MOL-20*log10(SOURCE.num_sources);

%% AUD
EVAL.AUD=abs(EVAL.Lp_foh-EVAL.MOL);
%% HR
EVAL.HR=EVAL.Lp_tar-EVAL.Lp_foh;
if EVAL.HR<0
    EVAL.HR=0;
end

%% APR
WSV=2.5/6;
WHR=1/6;
WAUD=2.5/6;
EVAL.APR=WSV*(10^(-EVAL.SV/20))+WHR*(10^(-EVAL.HR/20))+WAUD*(10^(-EVAL.AUD/20));

%% SPATIAL VARIANCE in BANDS
Lpi=mean(EVAL.audience_resp)
for i=1:length(EVAL.audience_resp(:,1));
    EVAL.spatial_variance_bands(i,:)=abs(EVAL.audience_resp(i,:)-Lpi);
end

%% SPATIAL VARIANCE in Over all bands
for i=1:length(EVAL.audience_resp(:,1));
    EVAL.spatial_variance(i,:)=abs(EVAL.audience_resp(i,:)-mean(Lpi));
end

%% Spatial variance ratio
sv_9=length(find(EVAL.spatial_variance<9));
sv_18=length(find(EVAL.spatial_variance<18))-sv_9;
sv_27=length(find(EVAL.spatial_variance<27))-sv_9-sv_18;
sv_more=numel(EVAL.spatial_variance)-sv_9-sv_18-sv_27;
sv_all=numel(EVAL.spatial_variance);

EVAL.SV_9_ratio=sv_9/sv_all;
EVAL.SV_18_ratio=sv_18/sv_all;
EVAL.SV_27_ratio=sv_27/sv_all;
EVAL.SV_more_ratio=sv_more/sv_all;

end

