ECE 280/Fall 2021/HW5F21

From PrattWiki2
Jump to navigation Jump to search

This page will have clarifications and examples for HW 5.

Clarifications

  • The value of $ A $ for Exercise 5.4.11 is given as 20.
  • For Part III, use $ N=51 $ in the code to get up to the 51st harmonic.
  • For Part III.1, use $ T=1 $ and note that the width is half the period.

Examples

  • To write code for a piecewise periodic function, note that in MATLAB mod(t,T) and in Python np.mod(t,T) will produce values that go from 0 to $ T $ as $ t $ goes from 0 to $ T $ and will then repeat that periodically. That means for a periodic function $ g(t) $, if you write the formula for the period from $ 0 $ and $ T $ as $ \hat{g}(t) $, you can replace $ t $ with mod(t, T) to get the periodic version. For example, the analytical version for $ x_3(t) $ in III.1 could be:
    u = @(t) (t>=0)*1.0;
    vinr = @(t) 5*(u(mod(t,T))-2*u(mod(t,T)-T/2)+u(mod(t,T)-T));
    
    or
    u = lambda t: (t>=0)*1.0
    vinr = lambda t: 5*(u(np.mod(t,T))-2*u(np.mod(t,T)-T/2)+u(np.mod(t,T)-T));
    
    while the analytical version for $ f(t) $ in Exercise 5.4.11 for III.2 could be:
    u = @(t) (t>=0)*1.0;
    vinr = @(t) 20*(u(mod(t,T)-1)-2*u(mod(t,T)-2)+2*u(mod(t,T)-3)-u(mod(t,T)-4));
    
    or
    u = lambda t: (t>=0)*1.0
    vinr = lambda t: 20*(u(np.mod(t,T)-1)-2*u(np.mod(t,T)-2)+2*u(np.mod(t,T)-3)-u(np.mod(t,T)-4))