
function atten_movie_vary_freq

% Plots E-field as function of depth and illustrates
% skin depth effect. Animated as movie

clear all
close all

mu = 4*pi*0.0000001;  sigma = 0.1;

xg =[-1.5,1.5];  zg =[0,0];             ncycle = 1;

% Set up array of depths
iz=0
for zdum =-5000:50:5000;
   iz=iz+1;  z(iz) = zdum;
end
nz = length(z);

nfreq = 40; freq(1) = 10;

for ifreq =2:nfreq
  freq(ifreq) = freq(ifreq-1)*1.1;  
end



for ifreq = 1:nfreq
    
  omega = 2*pi*freq(ifreq);  
  k = (1-j)*sqrt((mu*sigma*omega)/2);
  real_k = sqrt((mu*sigma*omega)/2);  imag_k = -sqrt((mu*sigma*omega)/2);

  %Start time step loop
  n=120*freq(1)/freq(ifreq); %
    %M=moviein(n);
  for it=1:n
    t=ncycle*(it*2*pi)/n;
    for iz=1:nz
      if z(iz)>= 0
        realex_t(iz) = cos(imag_k*z(iz)+t)*exp(-real_k*z(iz));
      else
        realex_t(iz) = cos(imag_k*z(iz)+t);
      end
    end
    plot(realex_t,-z*0.001,'b');
    hold on
    plot(xg,zg,':')
    hold off
    axis([-1.1,1.1, -5,5])
    f = omega/(2*pi);
    d = 500/sqrt(sigma*f);
    title(['f =',num2str(f,'%6.0f'),' Hz : \delta = ',num2str(d,'%6.0f'), ' m' ])
    %title(['f = ',num2str(freq(ifreq),'%6.3f'),'Hz'])
    xlabel ('E_x')
    ylabel ('depth (km)')
    pause (0.05)
    %M(:,it)=getframe;
  end
  

end  
%movie(M,10)



end


