% Emacs mode header: -*-Octave-*- source.%
% % -% OCTAVE
%addpath('/home/marsalek/src/mlab/lib')

cd ../pass

xX=0.1:1:35.1;
xXE=[8 12 16 20 24];
fF=invGwM(xX); coef=1; %coef=100000;
yY200=coef*Glat_pas_ana2M(xX,200);
yY1000=coef*Glat_pas_ana2M(xX,1000);
yY10000=coef*Glat_pas_ana2M(xX,10000);
ypool=Glat_pas_ana2M(xX,invGwM(xX)); %
cC200=GspeedM(xX,200);
cC1000=GspeedM(xX,1000);
cC10000=GspeedM(xX,10000);
cpool=GspeedM(xX,invGwM(xX));
%L0=-10;L1=10;
Hbot=0;Htop=12;
L0=0;L1=35.1; LN=10; x=0.1:1:L1;
A = 4.91; B = 0.363; C = 0.113; 
asmall = 0.084;

lateAE=A+B*exp(C*xXE);
veloAE=1./(0.113*(lateAE-4.91));

nonDim = L1/LN;
xLM = nonDim*[2 4 8];
veloLM = [10 9 6];
lateLM = [2.5 5 10];

subplot(2,2,1)
hold on
pha221E=plot(xXE, veloAE,'g-o');
pha221T=plot(xLM, veloLM,'k-+');
set(pha221E,'Color',[0.5 0.5 0.5]);
grid on
%axis([0, L1, 0, 25])
axis([0 35 0 12])
gcah1=gca;
set(gcah1,'XTick',0:5:35) %0:8.75:35
legend('experiment','theory')
legend boxoff
xlabel('Distance from stapes, mm')
ylabel('velocity, m/s')
title('Active velocity, m/s - live cochlea')

subplot(2,2,3), hold on
offs3=0;
pha223E=plot(xXE, lateAE-offs3, 'b-o');
plot(xLM, lateLM-offs3, 'k-+')
set(pha223E,'Color',[0.5 0.5 0.5]);
axis([0 35 -offs3 15-offs3])
gcah2=gca;
set(gcah2,'XTick',[0 5 10 15 20 25 30 35])
legend('experiment', 'theory') 
legend boxoff
grid on
xlabel('Distance from stapes, mm')
ylabel('Latencies with matching offsets, ms')
title('Active latency, ms - live cochlea')

subplot(2,2,4)
hold on
xPT=0:1:34;
latePT=Glat_pas_ana2M(xPT,invGwM(xPT));
xPE =    [20, 23, 25, 28, 30, 34]; %veloPE = [5]; 10^(1)
latePE=[10^(-4+2.5/19),10^(-4+15/19), 10^(-3), ...
        10^(-3+3/19),  10^(-3+6/19),  10^(-3+11.5/19)];
offs1 = 0.0055011; offs2 = 0; msec = 1000;
pha224E=plot(+xPE, 1+offs2+msec*latePE, 'b-o');
plot(+xPT(17:35), 1+offs2+msec*(offs1 + 10*latePT(17:35)), 'k-+')
set(pha224E,'Color',[0.5 0.5 0.5]);
legend('experiment [von Bekesy 1943]','theory') %... %1949,1960
legend boxoff
grid on %axis([-35 -20 msec*1e-4 msec*1e-2])
axis([0 35 offs2 offs2+7.5]) % 0/10/15 35 -5.5 0.5
gcah3=gca;
set(gcah3,'XTick',0:5:35) %[0:9:35,35]
title(strcat('Experiments on dead cochlea versus',...
             ' theoretical passive wave latency'))
xlabel('Distance from stapes, mm')
ylabel('Latencies with matching offsets, ms')
title('Passive latency, ms - dead cochlea')

xPEv = [17, xPE];
latePEv =[ -0.0004, latePE];
veloPE = diff(xPEv)./(msec*diff(latePEv));
subplot(2,2,2)
hold on
plot(x,1*cpool,'k-')
pha222E=plot(+xPE, veloPE, 'g-o');
set(pha222E,'Color',[0.5 0.5 0.5]);
grid on
axis([0 35 0 60]) % [0 35 0 24/120/150]
gcah4=gca;
set(gcah4,'XTick',0:5:35) %[0 10 20 30 35]
set(gcah4,'YTick',0:10:60)
legend('theoretical (pooled) velocity','calculated from Bekesy')
legend boxoff
xlabel('Distance from stapes, mm')
ylabel('velocity, m/s')
title('Passive velocity, m/s - dead cochlea') %...Eq. 11

cd ../mkfig

% === EOF
