
function atten_movie

% 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
freq = 10
omega = 2*pi*freq

xg =[-1.5,1.5]
zg =[0,0]

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

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=45;
M=moviein(n);
for it=1:n
  t=(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])
  title('MT plane wave: f=10 Hz : rho = 10 ohm.m')
  xlabel ('E_x')
  ylabel ('depth (km)')
  M(:,it)=getframe;
end
  
movie(M,50)