fs=100e6;           %  Sampling frequency  [Hz]
c=1540;             %  Speed of sound [m]
no_lines=128;                 %  Number of lines in image
image_width=90/180*pi;         %  Size of image sector [rad]
dtheta=0.7/180*pi;   %  Increment for image

%  Read the data and adjust it in time 

min_sample=0;
for i=1:no_lines

  %  Load the result
  cmd=['load sim_feu/rf_ln',num2str(i),'.mat']
  eval(cmd)
  
  %  Find the envelope
  rf_env=...
end

%%  Do logarithmic compression to 60 dB



%%  Get the data into the proper format

start_depth=0.02;   % Depth for start of image in meters
image_size=0.105;   % Size of image in meters

samples=max(size(log_env));

start_of_data=1/fs*c/2;           	% Depth for start of data in meters
end_of_data=(samples+1)/fs*c/2;     % Depth for end of data in meters
delta_r=c/2*1/fs;                   % Sampling interval for data in meters

theta_start= -no_lines/2*dtheta;     % Angle for first line in image

Nz=512;                         % Size of image in pixels
Nx=512;                         % Size of image in pixels
scaling=1;                      % Scaling factor form envelope to image

[N,M]=size(log_env);
D=floor(N/1024);
env_disp=255*log_env(1:D:N,:)/max(max(log_env));

%  Polar to cartesian interpolation
th_range=-127/2*0.7/180*pi:0.7/180*pi:128/2*0.7/180*pi;
d_range=start_of_data:D*c/2*1/fs:end_of_data;


