
function VLF_2

clear all;
close all;


% Define data
ip_mag = 1.0;    quad_mag =0.3;
ip_angle = 30;   quad_angle=-90;
rad=pi/180.;
t=2*pi*[0:0.01:4];  tmax=max(t);

% Instrument parameters - initialize
tilt = -90.;
percent = 0.;
irun = -1
while irun == -1

%Main coil
% Amplitude of inphase signal
a1=ip_mag*cos(rad*(tilt-ip_angle));
% Amplitude of quad signal
a2=quad_mag*cos(rad*(tilt-quad_angle));

%Reference coil
% Amplitude of in phase signal
a3=ip_mag*sin(rad*(tilt-ip_angle));

for i=1:length(t)
   f1(i)=a1*sin(t(i));
   f2(i)=a2*cos(t(i));
   f3(i)=a3*sin(t(i)-pi/2);
end

figure (1);
subplot(2,4,1)

  coil1_x = [-cos(rad*tilt),0.2*cos(rad*tilt)]; coil1_z = [0.5-sin(rad*tilt),0.5+0.5*sin(rad*tilt)];
  coil2_x = [-0.5*sin(rad*tilt),0.5*sin(rad*tilt)]; coil2_z = [0.5+0.5*cos(rad*tilt),0.5-0.5*cos(rad*tilt)];
  quad_x = [0,quad_mag*cos(rad*quad_angle)];      quad_z = [-0.5,-0.5+quad_mag*sin(rad*quad_angle)];
  ip_x   = [0,ip_mag*cos(rad*ip_angle)];          ip_z   = [-0.5,-0.5+ip_mag*sin(rad*ip_angle)];

  plot(coil1_x,coil1_z,'k.-');
  hold on
  plot(coil2_x,coil2_z,'k.-');
  plot(ip_x,ip_z,'k')
  plot(quad_x,quad_z,'r');
  plot(quad_x(1),quad_z(1),'k.');
  hold off
  axis equal
  axis([-1.,1,-2.5,2.5]);
  title('H-field and VLF unit')
  
  subplot(2,9,4) 
  bar(percent)
  ylabel('quad (%)')
  axis([0.5,1.5,-50,50]);

subplot(2,2,2)
  plot(t,f1,'k')
  hold on
  plot(t,f2,'r')
  plot(t,f1+f2)
  hold off
  axis([0,tmax,-1,1])
  title('Main coil')
  xlabel('time')
  ylabel('amplitude')

subplot(2,2,3)
  plot(t,(percent/100)*f3,'k')
  axis([0,tmax,-1,1])
  title('Reference coil : phase shift and attn')
  xlabel('time')
  ylabel('amplitude')

subplot(2,2,4)
  plot(t,(percent/100)*f3+f1+f2)
  axis([0,tmax,-1,1])
  title('Main coil : Audio output')
  xlabel('time')
  ylabel('amplitude')
  
  %print (3,'-dpsc', 'VLF_2.ps')


choice = MENU('VLF','CW','CCW','Increase %','Decrease %','Quit');

if choice == 1; tilt=tilt-1;  end
if choice == 2; tilt=tilt+1;  end
if choice == 3; percent=percent+1; end
if choice == 4; percent=percent-1; end
if choice == 5; irun =1;        end
percent
end

print (1,'-dpsc', 'VLF_2.ps')
