%========================================================================== % % Template Code for FDTD Lab (ECE3300, Lab 4). % % This script represents a skeleton code for completing Lab 4. % Follow the instructions on the lab handout to fill in the appropriate % values for the blank variables indicated below. % %========================================================================== % % James Nagel % ECE 3300 % Oct. 8, 2008 clear all; close all; % Physical Constants e_0 = % Permittivity of free space (F/m). m_0 = % Permeability of free space (H/m). % Simulation parameters. K = % Number of grid points. N = % Number of time steps (frames). dz = % Grid spacing (m) z = (0:K-1)*dz; % Z-axis (m). T_fr = 2; % Time steps per frame update. % Initialize Voltage and Current Arrays V = zeros(1,K); I = zeros(1,K); % Gaussian parameters for voltage generator. Vg = 1.0; % Amplitude (V). t0 = 150; % Time-shift (steps). sigma = 40; % Standard deviation (steps). % Axis scaling. Vmax = 2; % Voltage y-scale (V). Imax = 20; % Current y-scale (mA). % Transmission line parameters for RG-58. b = (2.95/2)*1e-3; % Outer conductor radius (m). a = (0.812/2)*1e-3; % Inner conductor radius (m). e_r = % Innter dielectric constant. L = % Inductance (H/m). C = % Capacitance (F/m). R = % Resistance (Ohm/m). G = % Conductance (Mho/m). % Propagation velocity (m/s) vp = % Critical time step. dt = % Define update-equation constants. c1 = c2 = c3 = c4 = % Initialize figure with two subplots. The top plot is the voltage and % the bottom plot is the current. fig = figure(1); clf set(fig,'units','pixels','position',[100, 100, 640, 480]); set(fig,'color',[1 1 1]/1.5); subplot(2,1,1); lineV = plot(z,V,'r','linewidth',2); axis([min(z) max(z) -Vmax Vmax]); grid on ylabel('Voltage (V)'); xlabel('Position (m)'); subplot(2,1,2); lineI = plot(z,[I(1:end-1) I(end-1)]*1e3,'b','linewidth',2); axis([min(z) max(z) -Imax Imax]); grid on ylabel('Current (mA)'); xlabel('Position (m)'); % FDTD loop for n = 1:N % Set the generator voltage. V(1) = Vg*exp(-(n-t0)^2/(2*sigma^2)); % Gaussian pulse. % Voltage update equation loop. for k = end % Current update equation loop. for k = end % Set the Right-most boundary condition on the current sample. I(end) = % Only update the plot after a few iterations to make the simulation % run faster. if mod(n,T_fr) == 0 if (any(isnan(V))) error('Simulation Terminated Due to Instability.'); end % Remember to convert I to mili-amps. set(lineV,'ydata',V); set(lineI,'ydata',I*1e3); drawnow; end end