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