%Continuous wave from point sources
%15.01.01  Hans Torp
% version for MEDT8002 03.09.04 HT

f0=2e6;%frequency
c=1540;%speed of sound
lambda=c/f0 %wavelength

xmax=10e-3;% +/- size  x direction
zmax=20e-3;%size  z direction
Nx=300;%number of points in x direction
Nz=300;%antall punkter i zretning

xaxis=linspace(-xmax,xmax,Nx);
zaxis=linspace(0,zmax,Nz)';
x=ones(Nz,1)*xaxis;
z=zaxis*ones(1,Nx);

p=0*x;
image(xaxis,zaxis,real(p));
colormap(gray);axis('image')
disp('Contiuous wave from point sources');
disp('Click to set point source positions (1 or more)');
disp('press return to see animation');
[x0,z0]=ginput(1);
while ~isempty(x0),
   r=sqrt((x-x0).^2+(z-z0).^2);
   p=p+exp(2*pi*i*r/lambda)./r;
   image(xaxis,zaxis,0.05*real(p));
   axis('image');
   [x0,z0]=ginput(1);
end;

%animation
set(1,'Doublebuffer','on');%to prevent flickering
dt=0.1e-6;
w0=2*pi*f0;
for n=1:100,
    p=p.*exp(-i*w0*dt);
    image(xaxis,zaxis,0.05*real(p));
   axis('image');
   pause(0.01);
end;
