Eel6487 Spring2014 Ho 11 Hw2soln

  • Upload
    rawoo5

  • View
    216

  • Download
    0

Embed Size (px)

Citation preview

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    1/43

    EEL 6487 - Electromagnetic Field Theory and Applications II Handout #11

    Moore 25 February 2014

    Spring 2014

    SOLUTIONS to Homework Assignment #2

    1. 1-D FDTD. Numerically simulate a Jcurrent source between two perfect electric conductors

    spaced 4 meters apart. The perfect electric conductors are located at x=0 and atx=4 meters.Use the 1-D equivalent of the FDTD equations given by Taflove and HagnessEquations 3.29

    3.30, choosex=0.001 meters andS=1.0, and assume the following Jcurrent source:

    Jz(x=2.5 m, t) =

    2.5sin(4109t) 0 t 2109sec

    0 otherwise (1)

    Region 1 (0x

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    2/43

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% EEL 6486% Spr i ng 2014% Homewor k #2, Pr obl em 1% Moore%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Here we i mpl ement a 1- D versi on of t he FDTD equat i ons, as% di scr et i zed by Tavl ove and Hagness [ 2000] . The pr ogr am aut omat i cal l y% di spl ays pl ot s of t he numeri cal sol ut i on when t he wave f r ont i s about% 0. 5 met er s f r om t he l ef t - most boundar y.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% We st ar t by suppl yi ng our const ant s

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%eps0 = 8. 854e- 12;mu0 = 4*pi *1e- 7;c = 1/ sqr t ( mu0*eps0) ;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% We then pr ovi de our S parameter , cal cul ate our r ange f or x, and use t hem% t o cal cul at e del t a_t .%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%S = 1. 0;

    f 0 = 2e9; %Hzl ambda0 = c/ f 0;

    mi n_x = 0; %met er smax_x = 4; %met er sdel t a_x = 1e- 3; %met er sx = ( mi n_x: del t a_x: max_x) ' ;

    N_l ambda = l ambda0/ del t a_x;

    del t a_t = del t a_x*S/ c;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% We pr ovi de t he per mi t t i vi t y, per meabi l i t y, and conduct i vi t y as a f unct i on% of space.

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    3/43

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    4/43

    end

    Ex( : , 2) = Ca_hal f . *Ex( : , 1) - Cb_hal f . *J x( : , 1) . *del t a_x;

    Ey(2: end- 1, 2) = Ca( 2: end- 1) . *Ey( 2: end- 1, 1) + Cb( 2: end- 1) . *( Hz( 1: end- 1, 2) - Hz( 2: end, 2) -J y( 2: end- 1, 1) . *del t a_x) ;

    Ey( 1, 2) = 0; Ey(end, 2) = 0;

    Ez( 2: end- 1, 2) = Ca( 2: end- 1) . *Ez(2: end- 1, 1) + Cb( 2: end- 1) . *( Hy(2: end, 2) - Hy(1: end- 1, 2) -J z( 2: end- 1, 1) . *del t a_x) ; Ez( 1, 2) = 0; Ez( end, 2) = 0;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Cal cul at e S at hal f poi nt s i n space and whol e poi nt s i n t i me.

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TAvg_Ex = ( Ex( : , 1) +Ex(: , 2) ) / 2; TAvg_Ey = ( Ey( : , 1) +Ey(: , 2) ) / 2; TAvg_Ez = ( Ez( : , 1) +Ez( : , 2) ) / 2; STAvg_Ey = ( TAvg_Ey( 1: end- 1)+TAvg_Ey( 2: end) ) / 2; STAvg_Ez = ( TAvg_Ez( 1: end- 1)+TAvg_Ez( 2: end) ) / 2; SAvg_Hx = 0;

    Sx = STAvg_Ey. *Hz( : , 2) - STAvg_Ez. *Hy( : , 2) ; Sy = STAvg_Ez. *SAvg_Hx - TAvg_Ex. *Hz( : , 2) ;

    Sz = TAvg_Ex. *Hy( : , 2) - STAvg_Ey. *SAvg_Hx;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    % Cal cul ate wave i mpedance at hal f poi nt s i n space and whol e poi nt s i n % t i me. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% et a = - STAvg_Ez. / Hy( : , 2) ; s = f i nd( Sx < 0) ; et a( s) = - et a( s) ;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Fi gur e- maki ng code bel ow. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% f i gur e( 1) ; pl ot ( x, Ez ( : , 2) ) ;

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    5/43

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    6/43

    vp1 = 2*pi *f 0/ i deal _bet a1;vp2 = 2*pi *f 0/ i deal _bet a2;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Use t he chi r p z- t r ansf or m t o cal cul at e t he r ef l ect i on and t r ansmi ssi on% coef f i c i ent s .

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%t 1_i ndex = r ound( 0. 1/ vp1/ del t a_t ) +1;t 2_i ndex = t 1_i ndex + r ound( 2e- 9/ del t a_t ) ;t 3_i ndex = r ound( 0. 9/ vp1/ del t a_t ) +1;t 4_i ndex = t 3_i ndex + r ound( 2e- 9/ del t a_t ) ;

    i nci dent _f i el d = out put _save_Ez( t 1_i ndex: t 2_i ndex, 1) ;r ef l ect ed_f i el d = out put _save_Ez( t 3_i ndex: t 4_i ndex, 1) ;

    I FZ = czt ( i nci dent _f i el d, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;

    RFZ = czt ( r ef l ected_f i el d, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;

    gamma = RFZ. / I FZ;T = gamma + 1;

    mag_ gamma = abs( gamma)angl e_gamma = angl e( gamma) *180/ pi

    mag_T = abs( T)angl e_T = angl e(T) *180/ pi

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Use t he chi r p z- t r ansf or m t o cal cul at e t he at t enuat i on r at e and phase% const ant i n medi um 1.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%t 1_i ndex = r ound( 0. 1/ vp1/ del t a_t ) +1;t 2_i ndex = t 1_i ndex + r ound( 2e- 9/ del t a_t ) ;t 3_i ndex = r ound( 0. 15/ vp1/ del t a_t ) +1;t 4_i ndex = t 3_i ndex + r ound( 2e- 9/ del t a_t ) ;

    i nci dent _f i el d1 = out put _save_Ez( t 1_i ndex: t 2_i ndex, 1) ;i nci dent _f i el d2 = out put _save_Ez( t 3_i ndex: t 4_i ndex, 2) ;

    I FZ1 = czt( i nci dent _f i el d1, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;I FZ2 = czt( i nci dent f i el d2, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a t ) ) ;

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    7/43

    al pha2 = - l og( abs( TFZ2. / TFZ1) ) / 0. 01

    t r ansmi t t ed_f i el d1 = out put _save_Ez(t 3_i ndex: t 2_i ndex, 3) ;t r ansmi t t ed_f i el d2 = out put _save_Ez(t 3_i ndex: t 2_i ndex, 4) ;

    TFZ1 = cz t ( t r ansmi t t ed_f i el d1, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;

    TFZ2 = cz t ( t r ansmi t t ed_f i el d2, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;

    beta2 = angl e(TFZ2. / TFZ1) / 0. 01

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Ref l ecti on Coef f i ci ent Resul t s:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% mag_i deal _gamma = 9. 999380612777624e- 01% angl e_i deal _gamma = 1. 799964510627202e+02% mag_gamma = 1. 000001593964612e+00

    % angl e_gamma = 1. 799967281651190e+02%% The numer i cal l y cal cul at ed val ues are ver y cl ose to the i deal val ues.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Tr ansmi ssi on Coef f i ci ent Resul t s:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% mag_i deal _T = 8. 759458098238177e- 05% angl e_i deal _T = 4. 499822553136009e+01% mag_T = 5. 712657875068623e- 05

    % angl e_T = 9. 159725730173959e+01%% The numer i cal l y cal cul at ed val ues ar e moder at el y cl ose t o t he i deal% val ues. They ar e of f a bi t , but t he magni t udes of t he f i el ds used t o% make the cal cul at i ons ar e ver y l ow.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% al pha/ bet a Resul t s, Medi um 1:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% i deal _al pha1 = 0

    % i deal _beta1 = 4. 191645585990301e+01% al pha1 = 4. 440892098500627e- 15% bet a1 = 4. 055126750393537e+01%% The numer i cal l y cal cul at ed val ues are ver y cl ose to the i deal val ues.

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    8/43

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    9/43

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% EEL 6486% Spr i ng 2014% Homewor k #2, Pr obl em 2% Moore%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Here we i mpl ement a 1- D versi on of t he FDTD equat i ons, as% di scr et i zed by Tavl ove and Hagness [ 2000] . The pr ogr am aut omat i cal l y% di spl ays pl ot s of t he numeri cal sol ut i on when t he wave f r ont i s about% 0. 5 met er s f r om t he l ef t - most boundar y.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% We st ar t by suppl yi ng our const ant s

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%eps0 = 8. 854e- 12;mu0 = 4*pi *1e- 7;c = 1/ sqr t ( mu0*eps0) ;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% We then pr ovi de our S parameter , cal cul ate our r ange f or x, and use t hem% t o cal cul at e del t a_t .%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%S = 1. 0;

    f 0 = 2e9; %Hzl ambda0 = c/ f 0;

    mi n_x = 0; %met er smax_x = 4; %met er sdel t a_x = 1e- 3; %met er sx = ( mi n_x: del t a_x: max_x) ' ;

    N_l ambda = l ambda0/ del t a_x;

    del t a_t = del t a_x*S/ c;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% We pr ovi de t he per mi t t i vi t y, per meabi l i t y, and conduct i vi t y as a f unct i on% of space.

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    10/43

    si gma_hal f = si gma(1: end- 1) ;

    Ca_hal f = ( 1- si gma_hal f . *del t a_t . / 2. / eps_hal f ) . / ( 1+si gma_hal f . *del t a_t . / 2. / eps_hal f ) ;Cb_hal f = ( del t a_t . / eps_hal f . / del t a_x) . / ( 1+si gma_hal f . *del t a_t . / 2. / eps_hal f ) ;Da_hal f = ones( si ze( Ca_hal f ) ) ;Db_hal f = del t a_t . / mu_hal f . / del t a_x;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% We t hen set our i ni t i al condi t i ons ( E=H=J =0 everywhere) . Based on t he% Yee gr i d, some vect or s ar e l onger t han ot hers. We keep 1 past val ue of% al l vector s, except f or J .%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Hx = zer os(l engt h( x), 2) ;Ey = zer os(l engt h( x), 2) ;Ez = zer os(l engt h( x), 2) ;

    J y = zer os( l engt h( x) , 1) ;

    J z = zer os( l engt h( x) , 1) ;

    Hy = zer os(l engt h( x)- 1, 2) ;Hz = zer os(l engt h( x)- 1, 2) ;Ex = zer os(l engt h( x)- 1, 2) ;

    J x = zer os( l engt h( x) - 1, 1) ;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Here we cal cul at e t he i ndex of t he sour ce l ocat i on.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    [ val , sour ce_l ocat i on] = mi n( abs( x - 2. 5) ) ;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% I n or der t o cal cul at e t he r ef l ecti on coef f i ci ent , t r ansmi ssi on% coef f i ci ent , at t enuat i on r at e, and phase const ant i n each medi um, we save% t he val ues at cert ai n l ocat i ons f or al l t i me. Her e we cal cul at e t he% i ndi ces of t hose l ocat i ons. These val ues change based on t he parameters% of medi um 2.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%[ val , save_l ocat i on1] = mi n( abs( x - 2. 60) ) ;

    [ val , save_l ocat i on2] = mi n( abs( x - 2. 65) ) ;[ val , save_l ocat i on3] = mi n( abs( x - 3. 01) ) ;[ val , save_l ocat i on4] = mi n( abs( x - 3. 02) ) ;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    11/43

    end

    Ex( : , 2) = Ca_hal f . *Ex( : , 1) - Cb_hal f . *J x( : , 1) . *del t a_x;

    Ey(2: end- 1, 2) = Ca( 2: end- 1) . *Ey( 2: end- 1, 1) + Cb( 2: end- 1) . *( Hz( 1: end- 1, 2) - Hz( 2: end, 2) -J y( 2: end- 1, 1) . *del t a_x) ;

    Ey( 1, 2) = 0; Ey(end, 2) = 0;

    Ez( 2: end- 1, 2) = Ca( 2: end- 1) . *Ez(2: end- 1, 1) + Cb( 2: end- 1) . *( Hy(2: end, 2) - Hy(1: end- 1, 2) -J z( 2: end- 1, 1) . *del t a_x) ; Ez( 1, 2) = 0; Ez( end, 2) = 0;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Cal cul at e S at hal f poi nt s i n space and whol e poi nt s i n t i me.

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TAvg_Ex = ( Ex( : , 1) +Ex(: , 2) ) / 2; TAvg_Ey = ( Ey( : , 1) +Ey(: , 2) ) / 2; TAvg_Ez = ( Ez( : , 1) +Ez( : , 2) ) / 2; STAvg_Ey = ( TAvg_Ey( 1: end- 1)+TAvg_Ey( 2: end) ) / 2; STAvg_Ez = ( TAvg_Ez( 1: end- 1)+TAvg_Ez( 2: end) ) / 2; SAvg_Hx = 0;

    Sx = STAvg_Ey. *Hz( : , 2) - STAvg_Ez. *Hy( : , 2) ; Sy = STAvg_Ez. *SAvg_Hx - TAvg_Ex. *Hz( : , 2) ;

    Sz = TAvg_Ex. *Hy( : , 2) - STAvg_Ey. *SAvg_Hx;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    % Cal cul ate wave i mpedance at hal f poi nt s i n space and whol e poi nt s i n % t i me. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% et a = - STAvg_Ez. / Hy( : , 2) ; s = f i nd( Sx < 0) ; et a( s) = - et a( s) ;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Fi gur e- maki ng code bel ow. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% f i gur e( 1) ; pl ot ( x, Ez ( : , 2) ) ;

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    12/43

    set ( h1, ' col or ' , ' r ' , ' Li neWi dth' , 2) ; yl abel ( ' S_x ( W/ m 2) ' ) ;

    r ange = [ 0 600] ; subpl ot ( 3, 1, 3) ; pl ot ( x(1: end- 1) +del t a_x/ 2, et a) ;

    yl i m( r ange) ; xl i m( [ mi n_x max_x] ) ; gr i d on; h1 = l i ne( [ 3 3] , r ange) ; set ( h1, ' col or ' , ' r ' , ' Li neWi dth' , 2) ; yl abel ( ' \ et a_w ( \ Omega) ' ) ; xl abel ( ' x ( met er s)' ) ; end

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    % Updat e t he ar r ays/ var i abl es f or t he next i t er at i on. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Ex( : , 1) = Ex( : , 2) ; Ex(: , 2) = 0; Ey( : , 1) = Ey( : , 2) ; Ey(: , 2) = 0; Ez(: , 1) = Ez(: , 2) ; Ez( : , 2) = 0; Hx( : , 1) = Hx( : , 2) ; Hx( : , 2) = 0;

    Hy( : , 1) = Hy( : , 2) ; Hy( : , 2) = 0; Hz( : , 1) = Hz( : , 2) ; Hz( : , 2) = 0; t = t + del t a_t ;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Save t he el ect r i c f i el d val ues at t he l ocat i ons cal cul at ed above. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% out put _save_Ez( i t er at i on, 1) = Ez( save_l ocat i on1, 1) ;

    out put _save_Ez( i t er at i on, 2) = Ez( save_l ocat i on2, 1) ; out put _save_Ez( i t er at i on, 3) = Ez( save_l ocat i on3, 1) ; out put _save_Ez( i t er at i on, 4) = Ez( save_l ocat i on4, 1) ;end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    13/43

    vp1 = 2*pi *f 0/ i deal _bet a1;vp2 = 2*pi *f 0/ i deal _bet a2;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Use t he chi r p z- t r ansf or m t o cal cul at e t he r ef l ect i on and t r ansmi ssi on% coef f i c i ent s .

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%t 1_i ndex = r ound( 0. 1/ vp1/ del t a_t ) +1;t 2_i ndex = t 1_i ndex + r ound( 2e- 9/ del t a_t ) ;t 3_i ndex = r ound( 0. 9/ vp1/ del t a_t ) +1;t 4_i ndex = t 3_i ndex + r ound( 2e- 9/ del t a_t ) ;

    i nci dent _f i el d = out put _save_Ez( t 1_i ndex: t 2_i ndex, 1) ;r ef l ect ed_f i el d = out put _save_Ez( t 3_i ndex: t 4_i ndex, 1) ;

    I FZ = czt ( i nci dent _f i el d, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;

    RFZ = czt ( r ef l ected_f i el d, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;

    gamma = RFZ. / I FZ;T = gamma + 1;

    mag_ gamma = abs( gamma)angl e_gamma = angl e( gamma) *180/ pi

    mag_T = abs( T)angl e_T = angl e(T) *180/ pi

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Use t he chi r p z- t r ansf or m t o cal cul at e t he at t enuat i on r at e and phase% const ant i n medi um 1.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%t 1_i ndex = r ound( 0. 1/ vp1/ del t a_t ) +1;t 2_i ndex = t 1_i ndex + r ound( 2e- 9/ del t a_t ) ;t 3_i ndex = r ound( 0. 15/ vp1/ del t a_t ) +1;t 4_i ndex = t 3_i ndex + r ound( 2e- 9/ del t a_t ) ;

    i nci dent _f i el d1 = out put _save_Ez( t 1_i ndex: t 2_i ndex, 1) ;i nci dent _f i el d2 = out put _save_Ez( t 3_i ndex: t 4_i ndex, 2) ;

    I FZ1 = czt( i nci dent _f i el d1, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;I FZ2 = czt( i nci dent f i el d2, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a t ) ) ;

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    14/43

    al pha2 = - l og( abs( TFZ2. / TFZ1) ) / 0. 01

    t r ansmi t t ed_f i el d1 = out put _save_Ez(t 3_i ndex: t 2_i ndex, 3) ;t r ansmi t t ed_f i el d2 = out put _save_Ez(t 3_i ndex: t 2_i ndex, 4) ;

    TFZ1 = cz t ( t r ansmi t t ed_f i el d1, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;

    TFZ2 = cz t ( t r ansmi t t ed_f i el d2, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;

    beta2 = angl e(TFZ2. / TFZ1) / 0. 01

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Ref l ecti on Coef f i ci ent Resul t s:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% mag_i deal _gamma = 8. 118117194577373e- 01% angl e_i deal _gamma = 1. 774489411567733e+02% mag_gamma = 8. 176446708021385e- 01

    % angl e_gamma = - 1. 798417037074187e+02%% The numer i cal l y cal cul at ed val ues are ver y cl ose to the i deal val ues.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Tr ansmi ssi on Coef f i ci ent Resul t s:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% mag_i deal _T = 1. 924159944908357e- 01% angl e_i deal _T = 1. 082373892090762e+01% mag_T = 1. 823724408414141e- 01

    % angl e_T = - 7. 097194330325466e- 01%% The numer i cal l y cal cul at ed val ues ar e r easonabl y cl ose t o t he i deal% val ues. They ar e of f a l i t t l e bi t , but t hey ar e bet t er t han f or copper .%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% al pha/ bet a Resul t s, Medi um 1:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% i deal _al pha1 = 0% i deal _beta1 = 4. 191645585990301e+01

    % al pha1 = 4. 440892098500627e- 15% bet a1 = 4. 055126750393537e+01%% The numer i cal l y cal cul at ed val ues are ver y cl ose to the i deal val ues.%

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    15/43

    0.5

    0.0

    0.5

    600

    400

    200

    0200

    400

    0 0.5 1.0 1.5 2.0 2.5 3.0 3.50

    100

    200

    300

    400

    500

    EEL 6487 Homework 2, Problem 2: Time: 6668 picoseconds

    Ez

    (V/m)

    Sx

    (W/m

    2)

    w

    ()

    x (meters)

    = 0= 0= 0 S/m

    = 810= 0

    = 4.0 S/m

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    16/43

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% EEL 6486% Spr i ng 2014% Homewor k #2, Pr obl em 3% Moore%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Here we i mpl ement a 1- D versi on of t he FDTD equat i ons, as% di scr et i zed by Tavl ove and Hagness [ 2000] . The pr ogr am aut omat i cal l y% di spl ays pl ot s of t he numeri cal sol ut i on when t he wave f r ont i s about% 0. 5 met er s f r om t he l ef t - most boundar y.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% We st ar t by suppl yi ng our const ant s

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%eps0 = 8. 854e- 12;mu0 = 4*pi *1e- 7;c = 1/ sqr t ( mu0*eps0) ;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% We then pr ovi de our S parameter , cal cul ate our r ange f or x, and use t hem% t o cal cul at e del t a_t .%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%S = 1. 0;

    f 0 = 2e9; %Hzl ambda0 = c/ f 0;

    mi n_x = 0; %met er smax_x = 4; %met er sdel t a_x = 1e- 3; %met er sx = ( mi n_x: del t a_x: max_x) ' ;

    N_l ambda = l ambda0/ del t a_x;

    del t a_t = del t a_x*S/ c;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% We pr ovi de t he per mi t t i vi t y, per meabi l i t y, and conduct i vi t y as a f unct i on% of space.

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    17/43

    si gma_hal f = si gma(1: end- 1) ;

    Ca_hal f = ( 1- si gma_hal f . *del t a_t . / 2. / eps_hal f ) . / ( 1+si gma_hal f . *del t a_t . / 2. / eps_hal f ) ;Cb_hal f = ( del t a_t . / eps_hal f . / del t a_x) . / ( 1+si gma_hal f . *del t a_t . / 2. / eps_hal f ) ;Da_hal f = ones( si ze( Ca_hal f ) ) ;Db_hal f = del t a_t . / mu_hal f . / del t a_x;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% We t hen set our i ni t i al condi t i ons ( E=H=J =0 everywhere) . Based on t he% Yee gr i d, some vect or s ar e l onger t han ot hers. We keep 1 past val ue of% al l vector s, except f or J .%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Hx = zer os(l engt h( x), 2) ;Ey = zer os(l engt h( x), 2) ;Ez = zer os(l engt h( x), 2) ;

    J y = zer os( l engt h( x) , 1) ;

    J z = zer os( l engt h( x) , 1) ;

    Hy = zer os(l engt h( x)- 1, 2) ;Hz = zer os(l engt h( x)- 1, 2) ;Ex = zer os(l engt h( x)- 1, 2) ;

    J x = zer os( l engt h( x) - 1, 1) ;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Here we cal cul at e t he i ndex of t he sour ce l ocat i on.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    [ val , sour ce_l ocat i on] = mi n( abs( x - 2. 5) ) ;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% I n or der t o cal cul at e t he r ef l ecti on coef f i ci ent , t r ansmi ssi on% coef f i ci ent , at t enuat i on r at e, and phase const ant i n each medi um, we save% t he val ues at cert ai n l ocat i ons f or al l t i me. Her e we cal cul at e t he% i ndi ces of t hose l ocat i ons. These val ues change based on t he parameters% of medi um 2.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%[ val , save_l ocat i on1] = mi n( abs( x - 2. 60) ) ;

    [ val , save_l ocat i on2] = mi n( abs( x - 2. 65) ) ;[ val , save_l ocat i on3] = mi n( abs( x - 3. 01) ) ;[ val , save_l ocat i on4] = mi n( abs( x - 3. 02) ) ;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    18/43

    end

    Ex( : , 2) = Ca_hal f . *Ex( : , 1) - Cb_hal f . *J x( : , 1) . *del t a_x;

    Ey(2: end- 1, 2) = Ca( 2: end- 1) . *Ey( 2: end- 1, 1) + Cb( 2: end- 1) . *( Hz( 1: end- 1, 2) - Hz( 2: end, 2) -J y( 2: end- 1, 1) . *del t a_x) ;

    Ey( 1, 2) = 0; Ey(end, 2) = 0;

    Ez( 2: end- 1, 2) = Ca( 2: end- 1) . *Ez(2: end- 1, 1) + Cb( 2: end- 1) . *( Hy(2: end, 2) - Hy(1: end- 1, 2) -J z( 2: end- 1, 1) . *del t a_x) ; Ez( 1, 2) = 0; Ez( end, 2) = 0;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Cal cul at e S at hal f poi nt s i n space and whol e poi nt s i n t i me.

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TAvg_Ex = ( Ex( : , 1) +Ex(: , 2) ) / 2; TAvg_Ey = ( Ey( : , 1) +Ey(: , 2) ) / 2; TAvg_Ez = ( Ez( : , 1) +Ez( : , 2) ) / 2; STAvg_Ey = ( TAvg_Ey( 1: end- 1)+TAvg_Ey( 2: end) ) / 2; STAvg_Ez = ( TAvg_Ez( 1: end- 1)+TAvg_Ez( 2: end) ) / 2; SAvg_Hx = 0;

    Sx = STAvg_Ey. *Hz( : , 2) - STAvg_Ez. *Hy( : , 2) ; Sy = STAvg_Ez. *SAvg_Hx - TAvg_Ex. *Hz( : , 2) ;

    Sz = TAvg_Ex. *Hy( : , 2) - STAvg_Ey. *SAvg_Hx;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    % Cal cul ate wave i mpedance at hal f poi nt s i n space and whol e poi nt s i n % t i me. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% et a = - STAvg_Ez. / Hy( : , 2) ; s = f i nd( Sx < 0) ; et a( s) = - et a( s) ;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Fi gur e- maki ng code bel ow. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% f i gur e( 2) ; pl ot ( x, Ez ( : , 2) ) ;

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    19/43

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    20/43

    vp1 = 2*pi *f 0/ i deal _bet a1;vp2 = 2*pi *f 0/ i deal _bet a2;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Use t he chi r p z- t r ansf or m t o cal cul at e t he r ef l ect i on and t r ansmi ssi on% coef f i c i ent s .

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%t 1_i ndex = r ound( 0. 1/ vp1/ del t a_t ) +1;t 2_i ndex = t 1_i ndex + r ound( 2e- 9/ del t a_t ) ;t 3_i ndex = r ound( 0. 9/ vp1/ del t a_t ) +1;t 4_i ndex = t 3_i ndex + r ound( 2e- 9/ del t a_t ) ;

    i nci dent _f i el d = out put _save_Ez( t 1_i ndex: t 2_i ndex, 1) ;r ef l ect ed_f i el d = out put _save_Ez( t 3_i ndex: t 4_i ndex, 1) ;

    I FZ = czt ( i nci dent _f i el d, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;

    RFZ = czt ( r ef l ected_f i el d, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;gamma = RFZ. / I FZ;

    T = gamma + 1;

    mag_ gamma = abs( gamma)angl e_gamma = angl e( gamma) *180/ pi

    mag_T = abs( T)angl e_T = angl e(T) *180/ pi

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Use t he chi r p z- t r ansf or m t o cal cul at e t he at t enuat i on r at e and phase% const ant i n medi um 1.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%t 1_i ndex = r ound( 0. 1/ vp1/ del t a_t ) +1;t 2_i ndex = t 1_i ndex + r ound( 2e- 9/ del t a_t ) ;t 3_i ndex = r ound( 0. 15/ vp1/ del t a_t ) +1;t 4_i ndex = t 3_i ndex + r ound( 2e- 9/ del t a_t ) ;

    i nci dent _f i el d1 = out put _save_Ez( t 1_i ndex: t 2_i ndex, 1) ;i nci dent _f i el d2 = out put _save_Ez( t 3_i ndex: t 4_i ndex, 2) ;

    I FZ1 = czt( i nci dent _f i el d1, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;I FZ2 = czt( i nci dent f i el d2, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a t ) ) ;

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    21/43

    al pha2 = - l og( abs( TFZ2. / TFZ1) ) / 0. 01

    t r ansmi t t ed_f i el d1 = out put _save_Ez(t 3_i ndex: t 2_i ndex, 3) ;t r ansmi t t ed_f i el d2 = out put _save_Ez(t 3_i ndex: t 2_i ndex, 4) ;

    TFZ1 = cz t ( t r ansmi t t ed_f i el d1, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;

    TFZ2 = cz t ( t r ansmi t t ed_f i el d2, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;beta2 = angl e(TFZ2. / TFZ1) / 0. 01

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Ref l ecti on Coef f i ci ent Resul t s:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% mag_i deal _gamma = 5. 195057303848667e- 01% angl e_i deal _gamma = 1. 798190721495866e+02% mag_gamma = 5. 202522378426062e- 01

    % angl e_gamma = 1. 777712192340359e+02%% The numer i cal l y cal cul at ed val ues are ver y cl ose to the i deal val ues.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Tr ansmi ssi on Coef f i ci ent Resul t s:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% mag_i deal _T = 4. 804996601879765e- 01% angl e_i deal _T = 1. 956152922781980e- 01% mag_T = 4. 805674242177409e- 01

    % angl e_T = 2. 412936146231353e+00%% The numer i cal l y cal cul at ed val ues are ver y cl ose to the i deal val ues.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% al pha/ bet a Resul t s, Medi um 1:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% i deal _al pha1 = 0% i deal _beta1 = 4. 191645585990301e+01% al pha1 = 4. 440892098500627e- 15

    % bet a1 = 4. 055126750393537e+01%% The numer i cal l y cal cul at ed val ues are ver y cl ose to the i deal val ues.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    22/43

    0.5

    0.0

    0.5

    600

    400

    200

    0200

    400

    0 0.5 1.0 1.5 2.0 2.5 3.0 3.50

    100

    200

    300

    400

    500

    EEL 6487 Homework 2, Problem 3: Time: 6668 picoseconds

    Ez

    (V/m)

    Sx

    (W/m

    2)

    w

    ()

    x (meters)

    = 0= 0= 0 S/m

    = 100= 0

    = 0.01 S/m

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    23/43

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% EEL 6486% Spr i ng 2014% Homewor k #2, Pr obl em 4% Moore%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Here we i mpl ement a 1- D versi on of t he FDTD equat i ons, as% di scr et i zed by Tavl ove and Hagness [ 2000] . The pr ogr am aut omat i cal l y% di spl ays pl ot s of t he numeri cal sol ut i on when t he wave f r ont i s about% 0. 5 meters f r om t he l ef t - most boundary. We i nt r oduce t he wave at x = 2. 5% meter s usi ng t he TF/ SF f ormul at i on.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    % We st ar t by suppl yi ng our const ant s%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%eps0 = 8. 854e- 12;mu0 = 4*pi *1e- 7;c = 1/ sqr t ( mu0*eps0) ;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% We then pr ovi de our S parameter , cal cul ate our r ange f or x, and use t hem% t o cal cul at e del t a_t .%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    S = 1. 0;f 0 = 2e9; %Hzl ambda0 = c/ f 0;

    mi n_x = 0; %met er smax_x = 4; %met er sdel t a_x = 1e- 3; %met er sx = ( mi n_x: del t a_x: max_x) ' ;

    N_l ambda = l ambda0/ del t a_x;

    del t a_t = del t a_x*S/ c;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% We pr ovi de t he per mi t t i vi t y, per meabi l i t y, and conduct i vi t y as a f unct i on

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    24/43

    mu_hal f = mu(1: end- 1) ;si gma_hal f = si gma(1: end- 1) ;

    Ca_hal f = ( 1- si gma_hal f . *del t a_t . / 2. / eps_hal f ) . / ( 1+si gma_hal f . *del t a_t . / 2. / eps_hal f ) ;Cb_hal f = ( del t a_t . / eps_hal f . / del t a_x) . / ( 1+si gma_hal f . *del t a_t . / 2. / eps_hal f ) ;Da_hal f = ones( si ze( Ca_hal f ) ) ;

    Db_hal f = del t a_t . / mu_hal f . / del t a_x;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% We t hen set our i ni t i al condi t i ons ( E=H=J =0 everywhere) . Based on t he% Yee gr i d, some vect or s ar e l onger t han ot hers. We keep 1 past val ue of% al l vector s, except f or J .%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Hx = zer os(l engt h( x), 2) ;Ey = zer os(l engt h( x), 2) ;Ez = zer os(l engt h( x), 2) ;

    J y = zer os( l engt h( x) , 1) ;J z = zer os( l engt h( x) , 1) ;

    Hy = zer os(l engt h( x)- 1, 2) ;Hz = zer os(l engt h( x)- 1, 2) ;Ex = zer os(l engt h( x)- 1, 2) ;

    J x = zer os( l engt h( x) - 1, 1) ;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Here we cal cul at e t he i ndex of t he sour ce l ocat i on.

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%[ val , t f sf _boundar y] = mi n( abs( x - 2. 500) ) ;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% I n or der t o cal cul at e t he r ef l ecti on coef f i ci ent , t r ansmi ssi on% coef f i ci ent , at t enuat i on r at e, and phase const ant i n each medi um, we save% t he val ues at cert ai n l ocat i ons f or al l t i me. Her e we cal cul at e t he% i ndi ces of t hose l ocat i ons. These val ues change based on t he parameters% of medi um 2.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    [ val , save_l ocat i on1] = mi n( abs( x - 2. 60) ) ;[ val , save_l ocat i on2] = mi n( abs( x - 2. 40) ) ;[ val , save_l ocat i on3] = mi n( abs( x - 2. 65) ) ;[ val , save_l ocat i on4] = mi n( abs( x - 3. 01) ) ;[ val , save l ocat i on5] = mi n( abs( x - 3. 02) ) ;

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    25/43

    Hy( t f sf _boundar y- 1, 2) = Hy( t f sf _boundar y- 1, 2) - Db_hal f ( t f sf _boundar y- 1) . *Ez_i nc; Hz( : , 2) = Da_hal f . *Hz( : , 1) + Db_hal f . *( Ey( 1: end- 1, 1) - Ey( 2: end, 1) ) ; Hz( t f sf _boundar y- 1, 2) = Hz( t f sf _boundar y- 1, 2) + Db_hal f ( t f sf _boundar y- 1) . *Ey_i nc;

    Hy_i nc = - 0. 5/ et a1*si n( 2*pi *f 0*t + bet a1*del t a_x/ 2) ; Hz_ i nc = 0;

    Ex( : , 2) = Ca_hal f . *Ex( : , 1) - Cb_hal f . *J x( : , 1) . *del t a_x;

    Ey(2: end- 1, 2) = Ca( 2: end- 1) . *Ey( 2: end- 1, 1) + Cb( 2: end- 1) . *( Hz( 1: end- 1, 2) - Hz( 2: end, 2) -J y( 2: end- 1, 1) . *del t a_x) ; Ey(t f sf _boundar y, 2) = Ey( t f sf _boundar y, 2) + Cb( t f sf _boundar y). *Hz_i nc; Ey( 1, 2) = 0; Ey(end, 2) = 0;

    Ez( 2: end- 1, 2) = Ca( 2: end- 1) . *Ez(2: end- 1, 1) + Cb( 2: end- 1) . *( Hy(2: end, 2) - Hy(1: end- 1, 2) -

    J z( 2: end- 1, 1) . *del t a_x) ; Ez( t f sf _boundar y, 2) = Ez( t f sf _boundar y, 2) - Cb( t f sf _boundar y) . *Hy_i nc; Ez( 1, 2) = 0; Ez( end, 2) = 0;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Cal cul at e S at hal f poi nt s i n space and whol e poi nt s i n t i me. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TAvg_Ex = ( Ex( : , 1) +Ex(: , 2) ) / 2; TAvg_Ey = ( Ey( : , 1) +Ey(: , 2) ) / 2;

    TAvg_Ez = ( Ez( : , 1) +Ez( : , 2) ) / 2; STAvg_Ey = ( TAvg_Ey( 1: end- 1)+TAvg_Ey( 2: end) ) / 2; STAvg_Ez = ( TAvg_Ez( 1: end- 1)+TAvg_Ez( 2: end) ) / 2; SAvg_Hx = 0;

    Sx = STAvg_Ey. *Hz( : , 2) - STAvg_Ez. *Hy( : , 2) ; Sy = STAvg_Ez. *SAvg_Hx - TAvg_Ex. *Hz( : , 2) ; Sz = TAvg_Ex. *Hy( : , 2) - STAvg_Ey. *SAvg_Hx;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    % Cal cul ate wave i mpedance at hal f poi nt s i n space and whol e poi nt s i n % t i me. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% et a = - STAvg_Ez. / Hy( : , 2) ; s = f i nd( Sx < 0) ;

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    26/43

    r ange = [ - 6 6] *1e- 4;

    subpl ot ( 3, 1, 2) ; pl ot ( x(1: end- 1) +del t a_x/ 2, Sx) ; yl i m( r ange) ; xl i m( [ mi n_x max_x] ) ;

    gr i d on; h1 = l i ne( [ 3 3] , r ange) ; set ( h1, ' col or ' , ' r ' , ' Li neWi dth' , 2) ; yl abel ( ' S_x ( W/ m 2) ' ) ;

    r ange = [ 0 600] ; subpl ot ( 3, 1, 3) ; pl ot ( x(1: end- 1) +del t a_x/ 2, et a) ; yl i m( r ange) ; xl i m( [ mi n_x max_x] ) ;

    gr i d on; h1 = l i ne( [ 3 3] , r ange) ; set ( h1, ' col or ' , ' r ' , ' Li neWi dth' , 2) ; yl abel ( ' \ et a_w ( \ Omega) ' ) ; xl abel ( ' x ( met er s)' ) ; end

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Updat e t he ar r ays/ var i abl es f or t he next i t er at i on. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Ex( : , 1) = Ex( : , 2) ; Ex(: , 2) = 0; Ey( : , 1) = Ey( : , 2) ; Ey(: , 2) = 0; Ez(: , 1) = Ez(: , 2) ; Ez( : , 2) = 0; Hx( : , 1) = Hx( : , 2) ; Hx( : , 2) = 0; Hy( : , 1) = Hy( : , 2) ; Hy( : , 2) = 0; Hz( : , 1) = Hz( : , 2) ; Hz( : , 2) = 0; t = t + del t a_t ;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    27/43

    i deal _gamma = ( eta2- eta1) / ( et a2+et a1) ;mag_i deal _gamma = abs( i deal _gamma)angl e_i deal _gamma = angl e( i deal _gamma) *180/ pi

    i deal _T = 2*et a2/ ( et a2+et a1) ;mag_i deal _T = abs( i deal _T)angl e_i deal _T = angl e( i deal _T) *180/ pi

    vp1 = 2*pi *f 0/ i deal _bet a1;vp2 = 2*pi *f 0/ i deal _bet a2;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Use t he chi r p z- t r ansf or m t o cal cul at e t he r ef l ect i on and t r ansmi ssi on% coef f i c i ent s .%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%t 1_i ndex = r ound( 0. 1/ vp1/ del t a_t ) +1;t 2_i ndex = t 1_i ndex + r ound( 2e- 9/ del t a_t ) ;t 3_i ndex = r ound( 1. 1/ vp1/ del t a_t ) +1;t 4_i ndex = t 3_i ndex + r ound( 2e- 9/ del t a_t ) ;

    i nci dent _f i el d = out put _save_Ez( t 1_i ndex: t 2_i ndex, 1) ;r ef l ect ed_f i el d = out put _save_Ez( t 3_i ndex: t 4_i ndex, 2) ;

    I FZ = czt ( i nci dent _f i el d, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;RFZ = czt ( r ef l ected_f i el d, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;

    gamma = RFZ. / I FZ;T = gamma + 1;

    mag_ gamma = abs( gamma)angl e_gamma = angl e( gamma) *180/ pi

    mag_T = abs( T)angl e_T = angl e(T) *180/ pi

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Use t he chi r p z- t r ansf or m t o cal cul at e t he at t enuat i on r at e and phase% const ant i n medi um 1.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%t 1 i ndex = r ound( 0. 1/ vp1/ del t a t ) +1;

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    28/43

    t 3_i ndex = r ound( ( 0. 52/ vp1) / del t a_t ) +1;t 4_i ndex = t 3_i ndex + r ound( 2e- 9/ del t a_t ) ;

    t r ansmi t t ed_f i el d1 = out put _save_Ez(t 1_i ndex: t 2_i ndex, 4) ;t r ansmi t t ed_f i el d2 = out put _save_Ez(t 3_i ndex: t 4_i ndex, 5) ;

    TFZ1 = cz t ( t r ansmi t t ed_f i el d1, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;TFZ2 = cz t ( t r ansmi t t ed_f i el d2, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;

    al pha2 = - l og( abs( TFZ2. / TFZ1) ) / 0. 01

    t r ansmi t t ed_f i el d1 = out put _save_Ez(t 3_i ndex: t 2_i ndex, 4) ;t r ansmi t t ed_f i el d2 = out put _save_Ez(t 3_i ndex: t 2_i ndex, 5) ;

    TFZ1 = cz t ( t r ansmi t t ed_f i el d1, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;TFZ2 = cz t ( t r ansmi t t ed_f i el d2, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;

    beta2 = angl e(TFZ2. / TFZ1) / 0. 01

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Ref l ecti on Coef f i ci ent Resul t s:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% mag_i deal _gamma = 9. 999380612777624e- 01% angl e_i deal _gamma = 1. 799964510627202e+02% mag_gamma = 1. 000001978810664e+00% angl e_gamma = 1. 799959974761156e+02%% The numer i cal l y cal cul at ed val ues are ver y cl ose to the i deal val ues.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Tr ansmi ssi on Coef f i ci ent Resul t s:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% mag_i deal _T = 8. 759458098238177e- 05% angl e_i deal _T = 4. 499822553136009e+01% mag_T = 6. 988531001897814e- 05% angl e_T = 9. 162055224534703e+01%% The numer i cal l y cal cul at ed val ues ar e moder at el y cl ose t o t he i deal% val ues. They ar e of f a bi t , but t he magni t udes of t he f i el ds used t o% make the cal cul at i ons ar e ver y l ow.%

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    29/43

    0.5

    0.0

    0.5

    600

    400

    200

    0200

    400

    0 0.5 1.0 1.5 2.0 2.5 3.0 3.50

    100

    200300

    400

    500

    EEL 6487 Homework 2, Problem 4a: Time: 10003 picoseconds

    Ez

    (V/m)

    Sx

    (W/m

    2)

    w()

    x (meters)

    = 0= 0= 0 S/m

    = 0= 0

    = 5.8x107S/m

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    30/43

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% EEL 6486% Spr i ng 2014% Homewor k #2, Pr obl em 4% Moore%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Here we i mpl ement a 1- D versi on of t he FDTD equat i ons, as% di scr et i zed by Tavl ove and Hagness [ 2000] . The pr ogr am aut omat i cal l y% di spl ays pl ot s of t he numeri cal sol ut i on when t he wave f r ont i s about% 0. 5 meters f r om t he l ef t - most boundary. We i nt r oduce t he wave at x = 2. 5% meter s usi ng t he TF/ SF f ormul at i on.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% We st ar t by suppl yi ng our const ant s%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%eps0 = 8. 854e- 12;mu0 = 4*pi *1e- 7;c = 1/ sqr t ( mu0*eps0) ;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% We then pr ovi de our S parameter , cal cul ate our r ange f or x, and use t hem% t o cal cul at e del t a_t .%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%S = 1. 0;f 0 = 2e9; %Hzl ambda0 = c/ f 0;

    mi n_x = 0; %met er smax_x = 4; %met er sdel t a_x = 1e- 3; %met er sx = ( mi n_x: del t a_x: max_x) ' ;

    N_l ambda = l ambda0/ del t a_x;

    del t a_t = del t a_x*S/ c;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% We pr ovi de t he per mi t t i vi t y, per meabi l i t y, and conduct i vi t y as a f unct i on

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    31/43

    mu_hal f = mu(1: end- 1) ;si gma_hal f = si gma(1: end- 1) ;

    Ca_hal f = ( 1- si gma_hal f . *del t a_t . / 2. / eps_hal f ) . / ( 1+si gma_hal f . *del t a_t . / 2. / eps_hal f ) ;Cb_hal f = ( del t a_t . / eps_hal f . / del t a_x) . / ( 1+si gma_hal f . *del t a_t . / 2. / eps_hal f ) ;Da_hal f = ones( si ze( Ca_hal f ) ) ;Db_hal f = del t a_t . / mu_hal f . / del t a_x;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% We t hen set our i ni t i al condi t i ons ( E=H=J =0 everywhere) . Based on t he% Yee gr i d, some vect or s ar e l onger t han ot hers. We keep 1 past val ue of% al l vector s, except f or J .%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Hx = zer os(l engt h( x), 2) ;Ey = zer os(l engt h( x), 2) ;Ez = zer os(l engt h( x), 2) ;

    J y = zer os( l engt h( x) , 1) ;J z = zer os( l engt h( x) , 1) ;

    Hy = zer os(l engt h( x)- 1, 2) ;Hz = zer os(l engt h( x)- 1, 2) ;Ex = zer os(l engt h( x)- 1, 2) ;

    J x = zer os( l engt h( x) - 1, 1) ;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Here we cal cul at e t he i ndex of t he sour ce l ocat i on.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%[ val , t f sf _boundar y] = mi n( abs( x - 2. 500) ) ;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% I n or der t o cal cul at e t he r ef l ecti on coef f i ci ent , t r ansmi ssi on% coef f i ci ent , at t enuat i on r at e, and phase const ant i n each medi um, we save% t he val ues at cert ai n l ocat i ons f or al l t i me. Her e we cal cul at e t he% i ndi ces of t hose l ocat i ons. These val ues change based on t he parameters% of medi um 2.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%[ val , save_l ocat i on1] = mi n( abs( x - 2. 60) ) ;[ val , save_l ocat i on2] = mi n( abs( x - 2. 40) ) ;[ val , save_l ocat i on3] = mi n( abs( x - 2. 65) ) ;[ val , save_l ocat i on4] = mi n( abs( x - 3. 01) ) ;[ val , save l ocat i on5] = mi n( abs( x - 3. 02) ) ;

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    32/43

    Hy( t f sf _boundar y- 1, 2) = Hy( t f sf _boundar y- 1, 2) - Db_hal f ( t f sf _boundar y- 1) . *Ez_i nc; Hz( : , 2) = Da_hal f . *Hz( : , 1) + Db_hal f . *( Ey( 1: end- 1, 1) - Ey( 2: end, 1) ) ; Hz( t f sf _boundar y- 1, 2) = Hz( t f sf _boundar y- 1, 2) + Db_hal f ( t f sf _boundar y- 1) . *Ey_i nc;

    Hy_i nc = - 0. 5/ et a1*si n( 2*pi *f 0*t + bet a1*del t a_x/ 2) ; Hz_ i nc = 0;

    Ex( : , 2) = Ca_hal f . *Ex( : , 1) - Cb_hal f . *J x( : , 1) . *del t a_x;

    Ey(2: end- 1, 2) = Ca( 2: end- 1) . *Ey( 2: end- 1, 1) + Cb( 2: end- 1) . *( Hz( 1: end- 1, 2) - Hz( 2: end, 2) -J y( 2: end- 1, 1) . *del t a_x) ; Ey(t f sf _boundar y, 2) = Ey( t f sf _boundar y, 2) + Cb( t f sf _boundar y). *Hz_i nc; Ey( 1, 2) = 0; Ey(end, 2) = 0;

    Ez( 2: end- 1, 2) = Ca( 2: end- 1) . *Ez(2: end- 1, 1) + Cb( 2: end- 1) . *( Hy(2: end, 2) - Hy(1: end- 1, 2) -J z( 2: end- 1, 1) . *del t a_x) ; Ez( t f sf _boundar y, 2) = Ez( t f sf _boundar y, 2) - Cb( t f sf _boundar y) . *Hy_i nc; Ez( 1, 2) = 0; Ez( end, 2) = 0;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Cal cul at e S at hal f poi nt s i n space and whol e poi nt s i n t i me. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TAvg_Ex = ( Ex( : , 1) +Ex(: , 2) ) / 2; TAvg_Ey = ( Ey( : , 1) +Ey(: , 2) ) / 2; TAvg_Ez = ( Ez( : , 1) +Ez( : , 2) ) / 2; STAvg_Ey = ( TAvg_Ey( 1: end- 1)+TAvg_Ey( 2: end) ) / 2; STAvg_Ez = ( TAvg_Ez( 1: end- 1)+TAvg_Ez( 2: end) ) / 2; SAvg_Hx = 0;

    Sx = STAvg_Ey. *Hz( : , 2) - STAvg_Ez. *Hy( : , 2) ; Sy = STAvg_Ez. *SAvg_Hx - TAvg_Ex. *Hz( : , 2) ; Sz = TAvg_Ex. *Hy( : , 2) - STAvg_Ey. *SAvg_Hx;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Cal cul ate wave i mpedance at hal f poi nt s i n space and whol e poi nt s i n % t i me. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% et a = - STAvg_Ez. / Hy( : , 2) ; s = f i nd( Sx < 0) ;

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    33/43

    r ange = [ - 6 6] *1e- 4;

    subpl ot ( 3, 1, 2) ; pl ot ( x(1: end- 1) +del t a_x/ 2, Sx) ; yl i m( r ange) ; xl i m( [ mi n_x max_x] ) ; gr i d on; h1 = l i ne( [ 3 3] , r ange) ; set ( h1, ' col or ' , ' r ' , ' Li neWi dth' , 2) ; yl abel ( ' S_x ( W/ m 2) ' ) ;

    r ange = [ 0 600] ; subpl ot ( 3, 1, 3) ; pl ot ( x(1: end- 1) +del t a_x/ 2, et a) ; yl i m( r ange) ; xl i m( [ mi n_x max_x] ) ; gr i d on; h1 = l i ne( [ 3 3] , r ange) ; set ( h1, ' col or ' , ' r ' , ' Li neWi dth' , 2) ; yl abel ( ' \ et a_w ( \ Omega) ' ) ; xl abel ( ' x ( met er s)' ) ; end

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Updat e t he ar r ays/ var i abl es f or t he next i t er at i on. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Ex( : , 1) = Ex( : , 2) ; Ex(: , 2) = 0; Ey( : , 1) = Ey( : , 2) ; Ey(: , 2) = 0; Ez(: , 1) = Ez(: , 2) ; Ez( : , 2) = 0; Hx( : , 1) = Hx( : , 2) ; Hx( : , 2) = 0; Hy( : , 1) = Hy( : , 2) ; Hy( : , 2) = 0; Hz( : , 1) = Hz( : , 2) ; Hz( : , 2) = 0; t = t + del t a_t ;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    34/43

    i deal _gamma = ( eta2- eta1) / ( et a2+et a1) ;mag_i deal _gamma = abs( i deal _gamma)angl e_i deal _gamma = angl e( i deal _gamma) *180/ pi

    i deal _T = 2*et a2/ ( et a2+et a1) ;mag_i deal _T = abs( i deal _T)angl e_i deal _T = angl e( i deal _T) *180/ pi

    vp1 = 2*pi *f 0/ i deal _bet a1;vp2 = 2*pi *f 0/ i deal _bet a2;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Use t he chi r p z- t r ansf or m t o cal cul at e t he r ef l ect i on and t r ansmi ssi on% coef f i c i ent s .%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%t 1_i ndex = r ound( 0. 1/ vp1/ del t a_t ) +1;t 2_i ndex = t 1_i ndex + r ound( 2e- 9/ del t a_t ) ;t 3_i ndex = r ound( 1. 1/ vp1/ del t a_t ) +1;t 4_i ndex = t 3_i ndex + r ound( 2e- 9/ del t a_t ) ;

    i nci dent _f i el d = out put _save_Ez( t 1_i ndex: t 2_i ndex, 1) ;r ef l ect ed_f i el d = out put _save_Ez( t 3_i ndex: t 4_i ndex, 2) ;

    I FZ = czt ( i nci dent _f i el d, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;RFZ = czt ( r ef l ected_f i el d, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;

    gamma = RFZ. / I FZ;T = gamma + 1;

    mag_ gamma = abs( gamma)angl e_gamma = angl e( gamma) *180/ pi

    mag_T = abs( T)angl e_T = angl e(T) *180/ pi

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Use t he chi r p z- t r ansf or m t o cal cul at e t he at t enuat i on r at e and phase% const ant i n medi um 1.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%t 1 i ndex = r ound( 0. 1/ vp1/ del t a t ) +1;

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    35/43

    t 3_i ndex = r ound( ( 0. 52/ vp1) / del t a_t ) +1;t 4_i ndex = t 3_i ndex + r ound( 2e- 9/ del t a_t ) ;

    t r ansmi t t ed_f i el d1 = out put _save_Ez(t 1_i ndex: t 2_i ndex, 4) ;t r ansmi t t ed_f i el d2 = out put _save_Ez(t 3_i ndex: t 4_i ndex, 5) ;

    TFZ1 = cz t ( t r ansmi t t ed_f i el d1, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;TFZ2 = cz t ( t r ansmi t t ed_f i el d2, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;

    al pha2 = - l og( abs( TFZ2. / TFZ1) ) / 0. 01

    t r ansmi t t ed_f i el d1 = out put _save_Ez(t 3_i ndex: t 2_i ndex, 4) ;t r ansmi t t ed_f i el d2 = out put _save_Ez(t 3_i ndex: t 2_i ndex, 5) ;

    TFZ1 = cz t ( t r ansmi t t ed_f i el d1, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;TFZ2 = cz t ( t r ansmi t t ed_f i el d2, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;

    bet a2 = ( angl e(TFZ2. / TFZ1) +2*pi ) / 0. 01

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Ref l ecti on Coef f i ci ent Resul t s:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% mag_i deal _gamma = 8. 118117194577373e- 01% angl e_i deal _gamma = 1. 799964510627202e+02% mag_gamma = 8. 176454436981953e- 01% angl e_gamma =- 1. 798439594203051e+02%% The numer i cal l y cal cul at ed val ues are ver y cl ose to the i deal val ues.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Tr ansmi ssi on Coef f i ci ent Resul t s:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% mag_i deal _T = 1. 924159944908357e- 01% angl e_i deal _T = 1. 082373892090762e+01% mag_T = 1. 823711838487847e- 01% angl e_T = - 6. 996109752561255e- 01%% The numer i cal l y cal cul at ed val ues ar e r easonabl y cl ose t o t he i deal% val ues.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    36/43

    0.5

    0.0

    0.5

    600

    400

    200

    0200

    400

    0 0.5 1.0 1.5 2.0 2.5 3.0 3.50

    100

    200300

    400

    500

    EEL 6487 Homework 2, Problem 4b: Time: 10003 picoseconds

    Ez

    (V/m)

    Sx

    (W/m2)

    w()

    x (meters)

    = 0= 0= 0 S/m

    = 810= 0

    = 4.0 S/m

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    37/43

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% EEL 6486% Spr i ng 2014% Homewor k #2, Pr obl em 4% Moore%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Here we i mpl ement a 1- D versi on of t he FDTD equat i ons, as% di scr et i zed by Tavl ove and Hagness [ 2000] . The pr ogr am aut omat i cal l y% di spl ays pl ot s of t he numeri cal sol ut i on when t he wave f r ont i s about% 0. 5 meters f r om t he l ef t - most boundary. We i nt r oduce t he wave at x = 2. 5% meter s usi ng t he TF/ SF f ormul at i on.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% We st ar t by suppl yi ng our const ant s%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%eps0 = 8. 854e- 12;mu0 = 4*pi *1e- 7;c = 1/ sqr t ( mu0*eps0) ;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% We then pr ovi de our S parameter , cal cul ate our r ange f or x, and use t hem% t o cal cul at e del t a_t .%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%S = 1. 0;f 0 = 2e9; %Hzl ambda0 = c/ f 0;

    mi n_x = 0; %met er smax_x = 4; %met er sdel t a_x = 1e- 3; %met er sx = ( mi n_x: del t a_x: max_x) ' ;

    N_l ambda = l ambda0/ del t a_x;

    del t a_t = del t a_x*S/ c;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% We pr ovi de t he per mi t t i vi t y, per meabi l i t y, and conduct i vi t y as a f unct i on

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    38/43

    mu_hal f = mu(1: end- 1) ;si gma_hal f = si gma(1: end- 1) ;

    Ca_hal f = ( 1- si gma_hal f . *del t a_t . / 2. / eps_hal f ) . / ( 1+si gma_hal f . *del t a_t . / 2. / eps_hal f ) ;Cb_hal f = ( del t a_t . / eps_hal f . / del t a_x) . / ( 1+si gma_hal f . *del t a_t . / 2. / eps_hal f ) ;Da_hal f = ones( si ze( Ca_hal f ) ) ;Db_hal f = del t a_t . / mu_hal f . / del t a_x;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% We t hen set our i ni t i al condi t i ons ( E=H=J =0 everywhere) . Based on t he% Yee gr i d, some vect or s ar e l onger t han ot hers. We keep 1 past val ue of% al l vector s, except f or J .%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Hx = zer os(l engt h( x), 2) ;Ey = zer os(l engt h( x), 2) ;Ez = zer os(l engt h( x), 2) ;

    J y = zer os( l engt h( x) , 1) ;J z = zer os( l engt h( x) , 1) ;

    Hy = zer os(l engt h( x)- 1, 2) ;Hz = zer os(l engt h( x)- 1, 2) ;Ex = zer os(l engt h( x)- 1, 2) ;

    J x = zer os( l engt h( x) - 1, 1) ;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Here we cal cul at e t he i ndex of t he sour ce l ocat i on.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%[ val , t f sf _boundar y] = mi n( abs( x - 2. 500) ) ;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% I n or der t o cal cul at e t he r ef l ecti on coef f i ci ent , t r ansmi ssi on% coef f i ci ent , at t enuat i on r at e, and phase const ant i n each medi um, we save% t he val ues at cert ai n l ocat i ons f or al l t i me. Her e we cal cul at e t he% i ndi ces of t hose l ocat i ons. These val ues change based on t he parameters% of medi um 2.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%[ val , save_l ocat i on1] = mi n( abs( x - 2. 60) ) ;[ val , save_l ocat i on2] = mi n( abs( x - 2. 40) ) ;[ val , save_l ocat i on3] = mi n( abs( x - 2. 65) ) ;[ val , save_l ocat i on4] = mi n( abs( x - 3. 01) ) ;[ val , save l ocat i on5] = mi n( abs( x - 3. 02) ) ;

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    39/43

    Hy( t f sf _boundar y- 1, 2) = Hy( t f sf _boundar y- 1, 2) - Db_hal f ( t f sf _boundar y- 1) . *Ez_i nc; Hz( : , 2) = Da_hal f . *Hz( : , 1) + Db_hal f . *( Ey( 1: end- 1, 1) - Ey( 2: end, 1) ) ; Hz( t f sf _boundar y- 1, 2) = Hz( t f sf _boundar y- 1, 2) + Db_hal f ( t f sf _boundar y- 1) . *Ey_i nc;

    Hy_i nc = - 0. 5/ et a1*si n( 2*pi *f 0*t + bet a1*del t a_x/ 2) ; Hz_ i nc = 0;

    Ex( : , 2) = Ca_hal f . *Ex( : , 1) - Cb_hal f . *J x( : , 1) . *del t a_x;

    Ey(2: end- 1, 2) = Ca( 2: end- 1) . *Ey( 2: end- 1, 1) + Cb( 2: end- 1) . *( Hz( 1: end- 1, 2) - Hz( 2: end, 2) -J y( 2: end- 1, 1) . *del t a_x) ; Ey(t f sf _boundar y, 2) = Ey( t f sf _boundar y, 2) + Cb( t f sf _boundar y). *Hz_i nc; Ey( 1, 2) = 0; Ey(end, 2) = 0;

    Ez( 2: end- 1, 2) = Ca( 2: end- 1) . *Ez(2: end- 1, 1) + Cb( 2: end- 1) . *( Hy(2: end, 2) - Hy(1: end- 1, 2) -J z( 2: end- 1, 1) . *del t a_x) ; Ez( t f sf _boundar y, 2) = Ez( t f sf _boundar y, 2) - Cb( t f sf _boundar y) . *Hy_i nc; Ez( 1, 2) = 0; Ez( end, 2) = 0;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Cal cul at e S at hal f poi nt s i n space and whol e poi nt s i n t i me. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TAvg_Ex = ( Ex( : , 1) +Ex(: , 2) ) / 2; TAvg_Ey = ( Ey( : , 1) +Ey(: , 2) ) / 2; TAvg_Ez = ( Ez( : , 1) +Ez( : , 2) ) / 2; STAvg_Ey = ( TAvg_Ey( 1: end- 1)+TAvg_Ey( 2: end) ) / 2; STAvg_Ez = ( TAvg_Ez( 1: end- 1)+TAvg_Ez( 2: end) ) / 2; SAvg_Hx = 0;

    Sx = STAvg_Ey. *Hz( : , 2) - STAvg_Ez. *Hy( : , 2) ; Sy = STAvg_Ez. *SAvg_Hx - TAvg_Ex. *Hz( : , 2) ; Sz = TAvg_Ex. *Hy( : , 2) - STAvg_Ey. *SAvg_Hx;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Cal cul ate wave i mpedance at hal f poi nt s i n space and whol e poi nt s i n % t i me. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% et a = - STAvg_Ez. / Hy( : , 2) ; s = f i nd( Sx < 0) ;

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    40/43

    r ange = [ - 6 6] *1e- 4;

    subpl ot ( 3, 1, 2) ; pl ot ( x(1: end- 1) +del t a_x/ 2, Sx) ; yl i m( r ange) ; xl i m( [ mi n_x max_x] ) ; gr i d on; h1 = l i ne( [ 3 3] , r ange) ; set ( h1, ' col or ' , ' r ' , ' Li neWi dth' , 2) ; yl abel ( ' S_x ( W/ m 2) ' ) ;

    r ange = [ 0 600] ; subpl ot ( 3, 1, 3) ; pl ot ( x(1: end- 1) +del t a_x/ 2, et a) ; yl i m( r ange) ; xl i m( [ mi n_x max_x] ) ; gr i d on; h1 = l i ne( [ 3 3] , r ange) ; set ( h1, ' col or ' , ' r ' , ' Li neWi dth' , 2) ; yl abel ( ' \ et a_w ( \ Omega) ' ) ; xl abel ( ' x ( met er s)' ) ; end

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Updat e t he ar r ays/ var i abl es f or t he next i t er at i on. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Ex( : , 1) = Ex( : , 2) ; Ex(: , 2) = 0; Ey( : , 1) = Ey( : , 2) ; Ey(: , 2) = 0; Ez(: , 1) = Ez(: , 2) ; Ez( : , 2) = 0; Hx( : , 1) = Hx( : , 2) ; Hx( : , 2) = 0; Hy( : , 1) = Hy( : , 2) ; Hy( : , 2) = 0; Hz( : , 1) = Hz( : , 2) ; Hz( : , 2) = 0; t = t + del t a_t ;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    41/43

    i deal _gamma = ( eta2- eta1) / ( et a2+et a1) ;mag_i deal _gamma = abs( i deal _gamma)angl e_i deal _gamma = angl e( i deal _gamma) *180/ pi

    i deal _T = 2*et a2/ ( et a2+et a1) ;mag_i deal _T = abs( i deal _T)angl e_i deal _T = angl e( i deal _T) *180/ pi

    vp1 = 2*pi *f 0/ i deal _bet a1;vp2 = 2*pi *f 0/ i deal _bet a2;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Use t he chi r p z- t r ansf or m t o cal cul at e t he r ef l ect i on and t r ansmi ssi on% coef f i c i ent s .%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%t 1_i ndex = r ound( 0. 1/ vp1/ del t a_t ) +1;t 2_i ndex = t 1_i ndex + r ound( 2e- 9/ del t a_t ) ;t 3_i ndex = r ound( 1. 1/ vp1/ del t a_t ) +1;t 4_i ndex = t 3_i ndex + r ound( 2e- 9/ del t a_t ) ;

    i nci dent _f i el d = out put _save_Ez( t 1_i ndex: t 2_i ndex, 1) ;r ef l ect ed_f i el d = out put _save_Ez( t 3_i ndex: t 4_i ndex, 2) ;

    I FZ = czt ( i nci dent _f i el d, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;RFZ = czt ( r ef l ected_f i el d, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;

    gamma = RFZ. / I FZ;T = gamma + 1;

    mag_ gamma = abs( gamma)angl e_gamma = angl e( gamma) *180/ pi

    mag_T = abs( T)angl e_T = angl e(T) *180/ pi

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Use t he chi r p z- t r ansf or m t o cal cul at e t he at t enuat i on r at e and phase% const ant i n medi um 1.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%t 1 i ndex = r ound( 0. 1/ vp1/ del t a t ) +1;

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    42/43

    t 3_i ndex = r ound( ( 0. 52/ vp1) / del t a_t ) +1;t 4_i ndex = t 3_i ndex + r ound( 2e- 9/ del t a_t ) ;

    t r ansmi t t ed_f i el d1 = out put _save_Ez(t 1_i ndex: t 2_i ndex, 4) ;t r ansmi t t ed_f i el d2 = out put _save_Ez(t 3_i ndex: t 4_i ndex, 5) ;

    TFZ1 = cz t ( t r ansmi t t ed_f i el d1, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;TFZ2 = cz t ( t r ansmi t t ed_f i el d2, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;

    al pha2 = - l og( abs( TFZ2. / TFZ1) ) / 0. 01

    t r ansmi t t ed_f i el d1 = out put _save_Ez(t 3_i ndex: t 2_i ndex, 4) ;t r ansmi t t ed_f i el d2 = out put _save_Ez(t 3_i ndex: t 2_i ndex, 5) ;

    TFZ1 = cz t ( t r ansmi t t ed_f i el d1, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;TFZ2 = cz t ( t r ansmi t t ed_f i el d2, 1, 1, exp( - sqr t ( - 1) *2*pi *2e9*del t a_t ) ) ;

    bet a2 = ( angl e(TFZ2. / TFZ1) ) / 0. 01

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Ref l ecti on Coef f i ci ent Resul t s:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% mag_i deal _gamma = 5. 195057303848667e- 01% angl e_i deal _gamma = 1. 798190721495866e+02% mag_gamma = 5. 202587629644551e- 01% angl e_gamma = 1. 777650673937463e+02%% The numer i cal l y cal cul at ed val ues are ver y cl ose to the i deal val ues.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Tr ansmi ssi on Coef f i ci ent Resul t s:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% mag_i deal _T = 4. 804996601879765e- 01% angl e_i deal _T = 1. 956152922781980e- 01% mag_T = 4. 805654472330949e- 01% angl e_T = 2. 419637194948447e+00%% The numer i cal l y cal cul at ed val ues are ver y cl ose to the i deal val ues.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% al pha/ bet a Resul t s, Medi um 1:

  • 8/12/2019 Eel6487 Spring2014 Ho 11 Hw2soln

    43/43

    0.5

    0.0

    0.5

    600

    400

    200

    0200

    400

    0 0.5 1.0 1.5 2.0 2.5 3.0 3.50

    100

    200300

    400

    500

    EEL 6487 Homework 2, Problem 4c: Time: 10003 picoseconds

    Ez

    (V/m)

    Sx

    (W/m2)

    w

    ()

    x (meters)

    = 0= 0= 0 S/m

    = 100= 0

    = 0.01 S/m