%
%     cross-correlation sine with delayed version, and rectified sine
%
%    call:   Exc_7_3(f0, dT)     f0 = frequency in Hz (def: 100), 
%                                dT = delay in ms (def.: 3)
%
function Exc_7_3(f0, dT)

if nargin<2 dT = 3; end
if nargin<1 f0 = 100; end

Fs=5000; dt = 1/Fs;
delay = dT/1000;
t=0:dt:0.02;

x1 = sin(2*pi*f0*t);
x1d = sin(2*pi*f0*(t-delay));

y1 = x1;
y1d = x1d;
for n=1:length(x1)
    if y1(n)<0 y1(n)=0; end
    if y1d(n)<0 y1d(n)=0; end
end

xc = xcorr(x1,x1d,'unbiased');
yc = xcorr(y1,y1d,'unbiased');

figure(1); clf;
N=length(xc);

t2=-0.02:dt:0.02;
plot(t2,xc,'r-','linewidth',2);
hold on
plot(t2, yc,'b-','linewidth',2);
plot([-0.02 0.02],[0 0],'k--','linewidth',1);
plot([0 0],[-1 1],'k--','linewidth',1);

axis([-0.01 0.01 -.6 0.6]);
set(gca, 'fontsize',12,'fontweight','bold');
xlabel('Relative Time [s]', 'fontsize',13,'fontweight','bold');
ylabel('Amplitude', 'fontsize',13,'fontweight','bold');

s=sprintf('Delay: %3d ms', dT);
text(-0.005,-0.55, s, 'fontsize',11,'fontweight','bold');
print -djpeg Fig7_3
return