|
| 1 | +--- |
| 2 | +title: "foo" |
| 3 | +code-block-bg: false |
| 4 | +format: pdf |
| 5 | +--- |
| 6 | +:::: {.callout-caution icon=false} |
| 7 | +## Self implementation |
| 8 | + |
| 9 | +Implement the code yourself by filling out the missing sections: |
| 10 | + |
| 11 | +```{python} |
| 12 | +#| code-fold: true |
| 13 | +#| eval: false |
| 14 | +#| code-summary: "Code fragment for implementation." |
| 15 | +#| fig-cap: "Test" |
| 16 | +import numpy as np |
| 17 | +import matplotlib.pyplot as plt |
| 18 | +%config InlineBackend.figure_formats = ["svg"] |
| 19 | +
|
| 20 | +frequ = 2 * np.pi * 50 |
| 21 | +f = lambda t: 0.8 * np.sin(t * frequ) |
| 22 | +diod = lambda t: (np.exp(1.2 + t) - 1) |
| 23 | +
|
| 24 | +t = np.linspace(0, 2 * np.pi / frequ, 1024, endpoint=False) |
| 25 | +x = np.linspace(np.min(f(t)) * 1.3, np.max(f(t)) * 1.1, 1024) |
| 26 | +
|
| 27 | +ic = lambda t: diod(f(t)) |
| 28 | +
|
| 29 | +k = np.arange(0, 16) * 1 / 16 |
| 30 | +
|
| 31 | +# The provided figures where used to create the illustation |
| 32 | +if True: |
| 33 | + plt.figure() |
| 34 | + plt.plot(f(t), t) |
| 35 | + plt.plot([np.min(t),np.max(t)], [0,0], "gray") |
| 36 | + plt.axis("off") |
| 37 | + #plt.savefig("sin.svg", transparent=True) |
| 38 | + plt.figure() |
| 39 | + plt.plot(x, diod(x)) |
| 40 | + z = np.array([0, np.min(f(t)), np.max(f(t))]) |
| 41 | + plt.plot(z, diod(z), "bx") |
| 42 | + plt.axis("off") |
| 43 | + plt.xlim([-2,5]) |
| 44 | + plt.gcf().patch.set_visible(False) |
| 45 | + #plt.savefig("diode.svg", transparent=True) |
| 46 | +
|
| 47 | + plt.figure() |
| 48 | + plt.plot(t, ic(t)) |
| 49 | + plt.plot(2*np.pi*k/frequ, ic(2*np.pi*k/frequ), "ro") |
| 50 | + plt.axis("off") |
| 51 | + #plt.savefig("ic.svg", transparent=True, bbox_inches ="tight") |
| 52 | +
|
| 53 | +y = ic(k) |
| 54 | +yhat = (np.fft.fft(y)) |
| 55 | +#Necessary correction factor for the FFT |
| 56 | +factor = 1 / 16 |
| 57 | +yy = factor * yhat |
| 58 | +
|
| 59 | +ic_mean = np.mean(ic(np.linspace(0, 1/50, 2**20))) |
| 60 | +c0 = yy[0].real |
| 61 | +effective_value = np.linalg.norm(yy[1:]) |
| 62 | +harmonic_distortion = np.linalg.norm(yy[3:-2])/np.linalg.norm(yy[1:]) |
| 63 | +``` |
| 64 | +:::: |
| 65 | + |
| 66 | +Some text that will not be displayed in the correct color. |
0 commit comments