Difference between revisions of "ECE 280/Fall 2021/HW5F21"
Jump to navigation
Jump to search
(Created page with "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 cod...") |
|||
Line 3: | Line 3: | ||
* The value of $$A$$ for Exercise 5.4.11 is given as 20. | * 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, 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 == | == Examples == | ||
* To write code for a piecewise periodic function, note that in MATLAB <code>mod(t,T)</code> and in Python <code>np.mod(t,T)</code> 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 <code>mod(t, T)</code> to get the periodic version. For example, the analytical version for $$x_3(t)$$ in III.1 could be:<syntaxhighlight lang=matlab> | * To write code for a piecewise periodic function, note that in MATLAB <code>mod(t,T)</code> and in Python <code>np.mod(t,T)</code> 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 <code>mod(t, T)</code> to get the periodic version. For example, the analytical version for $$x_3(t)$$ in III.1 could be:<syntaxhighlight lang=matlab> |
Latest revision as of 21:12, 1 October 2021
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 Pythonnp.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$$ withmod(t, T)
to get the periodic version. For example, the analytical version for $$x_3(t)$$ in III.1 could be:oru = @(t) (t>=0)*1.0; vinr = @(t) 5*(u(mod(t,T))-2*u(mod(t,T)-T/2)+u(mod(t,T)-T));
while the analytical version for $$f(t)$$ in Exercise 5.4.11 for III.2 could be: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));
oru = @(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));
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))