clear
close all

load elnyelo_foldon_2mic.mat;

fs = Result.AcqSetup.Fs;
N = Result.AcqSetup.nSamples;

Pmic = Result.FrequencyResponseFunction(:,1:2);
freq = (0:N/2)'/N*fs;
om = 2*pi*freq;
rho0 = 1.2;
c = 343.1;
Z0 = rho0*c;

dz = 9.111e-3;
Pest = mean(Pmic,2);
Vest = (Pmic(:,2)-Pmic(:,1))./(1i*om*rho0*dz);
%%
Zs = Pest./Vest;
d0 = 1e-2;
k = om/c;

Z = (Zs - 1i.*Z0.*tan(k*d0))./(Z0- 1i*Zs.*tan(k*d0));
R = (Z-1)./(Z+1);

alpha = 1 - ( abs(R) ).^2;

Lf = 20;
alpha = conv(alpha,ones(Lf,1)/Lf,'same');
figure
semilogx(freq,  alpha);
grid on
hold on
xlim([50,10e3]);
ylim([-0.1,1]);
hold on

load elnyelo_kockakon_000.mat;

fs = Result.AcqSetup.Fs;
N = Result.AcqSetup.nSamples;

Pmic = Result.FrequencyResponseFunction(:,1:2);
freq = (0:N/2)'/N*fs;
om = 2*pi*freq;
rho0 = 1.2;
c = 343.1;
Z0 = rho0*c;

dz = 9.111e-3;
Pest = mean(Pmic,2);
Vest = (Pmic(:,2)-Pmic(:,1))./(1i*om*rho0*dz);
%%
Zs = Pest./Vest;
d0 = 1e-2;
k = om/c;

Z = (Zs - 1i.*Z0.*tan(k*d0))./(Z0- 1i*Zs.*tan(k*d0));
R = (Z-1)./(Z+1);

alpha = 1 - ( abs(R) ).^2;

Lf = 20;
alpha = conv(alpha,ones(Lf,1)/Lf,'same');

semilogx(freq,  alpha);
grid on
hold on
xlim([50,11e3]);
ylim([-0.1,1]);
hold on