%  Demonstration of spatial impulse response for a
%  rectangular aperture using Field II
%
%  Version 1, July 3, 1999, Joergen Arendt Jensen
%
%  Initialize the field system

%field

%  Generate the transducer apertures for send and receive

f0=3e6;                  %  Transducer center frequency [Hz]
fs=1000e6;               %  Sampling frequency [Hz]
c=1540;                  %  Speed of sound [m/s]
lambda=c/f0;             %  Wavelength [m]
width=4/1000;            %  Width of element
height=5/1000;           %  Height of element [m]
kerf=0.1/1000;           %  Kerf [m]
focus=[0 0 70]/1000;     %  Fixed focal point [m]
N_elements=1;            %  Number of physical elements

%  Set the sampling frequency and use lines

set_sampling(fs);
set_field ('use_lines',1);

%  Generate aperture for emission

emit_aperture = xdc_linear_array (N_elements, width, height, kerf, 1, 1,focus);

%  Set the impulse response and excitation of the emit aperture

impulse_response=sin(2*pi*f0*(0:1/fs:2/f0));
impulse_response=impulse_response.*hanning(max(size(impulse_response)))';
xdc_impulse (emit_aperture, impulse_response);

excitation=sin(2*pi*f0*(0:1/fs:2/f0));
xdc_excitation (emit_aperture, excitation);

%   Make the inital plot of the transducer and the field area

axes(position)
plot([-1 0 0 -1 -1],[-width/2 -width/2 width/2 width/2 -width/2]*1000)
hold on
plot([0 0],[-20 20],'--r')
axis([-2 50 -5 5])
grid
xlabel('Axial distance (z) [mm]')
ylabel('Lateral distance (x) [mm]')
title('Transducer')

%  Set-up varibels for plotting

x=0;
z=50;
xt=0;
yt=0;
tt=0;
rt=0;
