function pulseEchoPlot(z1);
%Pulse echo 1D imaging - simulation
% z1 is distance to reflector [m]. default=0.01 m
%23.01.01  Hans Torp
% Modified for complex demodulation 17.10.01

if nargin<1,z1=10e-3;end;

c=1540;%speed of sound
fs=200e6;%sampling freq. 
tmax=20e-6;
t=0:1/fs:tmax;%time axis
z=c/2*t;dz=z(2)-z(1);%depth axis

%define pulse
f0=2e6;
lambda=c/f0;
Tp=2e-6;%pulse length
tp=0:1/fs:Tp;
p=sin(2*pi*f0*tp);

obj=0*z;obj(1)=2;%object function;



obj(1+round(z1/dz))=1;%reflector in position z1
s=filter(p,1,obj);%received signal

B=1.5e6;
[b,a]=butter(2,[f0-B/2,f0+B/2]/(fs/2));
s=filter(b,a,s);

figno=1;
figure(figno);set(figno,'DoubleBuffer','on');%prevent flickering
subplot(4,1,1);plot(z,obj);xlabel('depth z [m]');axis('tight');
subplot(4,1,2);plot(t,s);xlabel('time [s]');axis('tight');

sp=hilbert(s);%pre envelope
sh=imag(hilbert(s));%hilbert transformed signal
subplot(4,1,3);plot(t,sh);xlabel('time [s]');axis('tight');
smix=exp(-i*2*pi*f0*t);%down-mixing signal
iq=sp.*smix;%in phase and quadrature components
subplot(4,1,4);plot(t,real(iq),'r',t,imag(iq),'b',t,abs(iq),'g');xlabel('time [s]');axis([t(1),t(end),-2,2]);
pause(0.1);
