clear 
close all
load('2mic_measurement_000.mat');
%%
fs = Result.AcqSetup.Fs;
Ns = Result.AcqSetup.nSamples;

h_25 = Result.ImpulseResponse(:,1);
h_55 = Result.ImpulseResponse(:,2);
t = (0:size(h_25,1)-1)/fs;
%h_25(550:end) = 0;
%h_55(550:end) = 0;

H_25 = fft(h_25);
H_55 = fft(h_55);
Nfilt = length(H_25);
freq = (0:Nfilt-1)'/Nfilt*fs;

w = 2*pi*freq;
k = w / 343.1;

H12 = H_55./H_25;
z1 = 2.7e-2;
z2 = 5.7e-2;

R = ( H12.*exp(1i*k*z1) - exp(1i*k*z2) )./( exp(-1i*k*z2) - H12.*exp(-1i*k*z1) );

alpha = 1 - abs(R).^2;
Z = 1.2*343.1*(1+R)./(1-R);

figure
subplot(1,2,1)
semilogx(freq,real(Z));
xlim([20,5e3]);
grid on
xlabel('f -> [Hz]')
ylabel('Real(Z) -> []')
title('Impedancia')

subplot(1,2,2)
semilogx(freq,alpha);
xlim([20,5e3]);
grid on
xlabel('f -> [Hz]')
ylabel('\alpha -> []')
title('Elnyelési tényező')
