Commit 87cc3651 authored by Christian Rohlfing's avatar Christian Rohlfing
Browse files

- added äqu. TP

- minor iterations
parent ff8c6170
%% Cell type:code id: tags:
``` python
# Copyright 2019 Institut für Nachrichtentechnik, RWTH Aachen University
%matplotlib notebook
from ient_nb.ient_plots import *
```
%% Cell type:markdown id: tags:
<div>
<img src="ient_nb/figures/rwth_ient_logo@2x.png" style="float: right;height: 5em;">
</div>
# Diskrete Faltung
%% Cell type:code id: tags:
``` python
M = 17
n = np.arange(0, M)
k = n
n
```
%% Cell type:code id: tags:
``` python
sd = np.array([1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1]) # s(n)
hd = sd
# Plot
fig,ax = plt.subplots()
ient_stem(ax, n, sd, 'rwth')
ax.set_xlabel(r'$\rightarrow n$', bbox=ient_wbbox); ax.set_ylabel(r'$\uparrow s_\mathrm{d}(n)$', bbox=ient_wbbox);
ax.set_ylim([-0.09,1.09]); ient_axis(ax)
```
%% Cell type:code id: tags:
``` python
M = len(n)
Sd = np.real(np.fft.fft(sd, M)) # np.real() discards very small negative values
Hd = np.real(np.fft.fft(hd, M))
# Plot
fig,ax = plt.subplots()
ient_stem(ax, k, Sd, 'rwth')
ax.set_xlabel(r'$\rightarrow k$', bbox=ient_wbbox); ax.set_ylabel(r'$\uparrow S_\mathrm{d}(k)$', bbox=ient_wbbox);
ax.set_ylim([-1.9,7.9]); ient_axis(ax)
```
%% Cell type:code id: tags:
``` python
Gd = Sd * Hd
# Plot
gd = np.real(np.fft.ifft((Gd)))
fig,axs = plt.subplots(2,1)
ax = axs[0]; ient_stem(ax,k,Gd, 'rwth')
ax.set_xlabel(r'$\rightarrow k$', bbox=ient_wbbox); ax.set_ylabel(r'$\uparrow G_\mathrm{d}(n)$', bbox=ient_wbbox);
ax.set_xlabel(r'$\rightarrow k$', bbox=ient_wbbox); ax.set_ylabel(r'$\uparrow G_\mathrm{d}(k)$', bbox=ient_wbbox);
ax.set_ylim([-1,59]); ient_axis(ax)
ax = axs[1]; ient_stem(ax,n,gd, 'rwth')
ax.set_xlabel(r'$\rightarrow n$', bbox=ient_wbbox); ax.set_ylabel(r'$\uparrow g_\mathrm{d}(n)$', bbox=ient_wbbox);
ax.set_ylim([-0.09,8.9]); ient_axis(ax)
```
%% Cell type:markdown id: tags:
This notebook is provided as [Open Educational Resource](https://en.wikipedia.org/wiki/Open_educational_resources) (OER). Feel free to use the notebook for your own purposes. The code is licensed under the [MIT license](https://opensource.org/licenses/MIT).
Please attribute the work as follows:
*Christian Rohlfing, Übungsbeispiele zur Vorlesung "Grundgebiete der Elektrotechnik 3 - Signale und Systeme"*, gehalten von Jens-Rainer Ohm, 2019, Institut für Nachrichtentechnik, RWTH Aachen University.
......
%% Cell type:code id: tags:
``` python
# Copyright 2019 Institut für Nachrichtentechnik, RWTH Aachen University
%matplotlib notebook
from ipywidgets import interact, interactive
import ipywidgets as widgets
from ient_nb.ient_plots import *
from ient_nb.ient_signals import *
```
%% Cell type:markdown id: tags:
<div>
<img src="ient_nb/figures/rwth_ient_logo@2x.png" style="float: right;height: 5em;">
</div>
# Elementarsignale
Folgende Signale wurden bereits in `ient_signals` definiert:
``` python
gauss = lambda t: np.exp(-(t)**2)
unitstep = lambda t: np.where(t>=0, 1, 0)
rect = lambda t: unitstep(t+0.5) - unitstep(t-0.5)
tri = lambda t: rect(t/2)*(1-abs(t))
si = lambda t: np.sinc(t/np.pi) # English notation sinc(t) = sin(pi t)/(pi t)
```
Im Folgenden werden einige Elementarsignale aufgeführt.
%% Cell type:markdown id: tags:
## Signale
Jedes der oben definierten Elementarsignale wird im Folgenden geplottet.
### Gauß-Signal
$\displaystyle s(t) = \mathrm{e}^{\pi t^2}$
%% Cell type:code id: tags:
``` python
fig,ax = plt.subplots(1,1); ax.plot(t, gauss(t));
ax.set_xlabel(r'$\rightarrow t$'); ax.set_ylabel(r'$\uparrow s(t)=\mathrm{e}^{-\pi t^2}$', bbox=ient_wbbox)
ax.axis('equal'); ax.set_xlim([-2.75, 2.75]); ient_grid(ax); ient_axis(ax);
```
%% Cell type:markdown id: tags:
### Sprungfunktion
$\epsilon(t)=\begin{cases}
0\quad\text{für}\ t<0 \\
1\quad\text{für}\ t\geq 0 \text{ .}
\end{cases}$
%% Cell type:code id: tags:
``` python
fig,ax = plt.subplots(1,1); ax.plot(t, unitstep(t));
ax.set_xlabel(r'$\rightarrow t$'); ax.set_ylabel(r'$\uparrow s(t)=\epsilon(t)$', bbox=ient_wbbox)
ax.axis('equal'); ax.set_xlim([-2.25,2.25]); ient_grid(ax); ient_axis(ax);
```
%% Cell type:markdown id: tags:
### Rechteckimpuls
$\mathrm{rect}(t) = \begin{cases}
1\quad\text{für}\ |t| \leq 1/2\\
0\quad\text{für}\ |t| > 1/2\text{ .}
\end{cases}$
%% Cell type:code id: tags:
``` python
fig,ax = plt.subplots(1,1); ax.plot(t, rect(t));
ax.set_xlabel(r'$\rightarrow t$'); ax.set_ylabel(r'$\uparrow s(t)=\mathrm{rect}(t)$', bbox=ient_wbbox)
ax.axis('equal'); ax.set_xlim([-2.25,2.25]); ient_grid(ax); ient_axis(ax);
```
%% Cell type:markdown id: tags:
### Dreieckimpuls
$\Lambda(t) = \begin{cases}
1-|t|\quad\text{für}\ |t|\leq 1\\
0\quad\text{für}\ |t| > 1\text{ .}
\end{cases}$
%% Cell type:code id: tags:
``` python
fig,ax = plt.subplots(1,1); ax.plot(t, tri(t));
ax.set_xlabel(r'$\rightarrow t$'); ax.set_ylabel(r'$\uparrow s(t)=\Lambda(t)$', bbox=ient_wbbox)
ax.axis('equal'); ax.set_xlim([-2.25,2.25]); ient_grid(ax); ient_axis(ax);
```
%% Cell type:markdown id: tags:
### Si-Funktion
$\displaystyle \mathrm{si}(t) = \frac{\sin(t)}{t}$
%% Cell type:code id: tags:
``` python
fig,ax = plt.subplots(1,1); ax.plot(t, si(np.pi*t));
ax.set_xlabel(r'$\rightarrow t$'); ax.set_ylabel(r'$\uparrow s(t)=\mathrm{si}(\pi t)$', bbox=ient_wbbox)
ax.set_xlim([-5.5,5.5]); ient_grid(ax); ient_axis(ax);
```
%% Cell type:markdown id: tags:
## Zeitverschiebung, -dehnung und -spiegelung
%% Cell type:markdown id: tags:
Verschobener Rechteckimpuls $s(t) = \mathrm{rect}\left(t-\frac{1}{2}\right)$
%% Cell type:code id: tags:
``` python
s = lambda t: rect(t-1/2)
# Plot
fig,ax = plt.subplots(1,1); ax.plot(t, s(t));
ax.set_xlabel(r'$\rightarrow t$'); ax.set_ylabel(r'$\uparrow s(t)$', bbox=ient_wbbox)
ax.axis('equal'); ax.set_xlim([-2.25,2.25]); ient_grid(ax); ient_axis(ax);
```
%% Cell type:markdown id: tags:
Gedehnter Rechteckimpuls $s(t) = \mathrm{rect}\left(\frac{t}{2}\right)$
%% Cell type:code id: tags:
``` python
s = lambda t: rect(t/2)
# Plot
fig,ax = plt.subplots(1,1); ax.plot(t, s(t));
ax.set_xlabel(r'$\rightarrow t$'); ax.set_ylabel(r'$\uparrow s(t)$', bbox=ient_wbbox)
ax.axis('equal'); ax.set_xlim([-2.25,2.25]); ient_grid(ax); ient_axis(ax);
```
%% Cell type:markdown id: tags:
Zur Verdeutlichung der Zeitspiegelung wird $s(t) = t \cdot \mathrm{rect}\left(t-\frac{1}{2}\right)$ betrachtet:
%% Cell type:code id: tags:
``` python
s = lambda t: rect(t-0.5)*t
# Plot
fig,ax = plt.subplots(1,1); ax.plot(t, s(t));
ax.set_xlabel(r'$\rightarrow t$'); ax.set_ylabel(r'$\uparrow s(t)$', bbox=ient_wbbox)
ax.axis('equal'); ax.set_xlim([-2.25,2.25]); ient_grid(ax); ient_axis(ax);
```
%% Cell type:markdown id: tags:
Betrachte nun $s(-t)$:
%% Cell type:code id: tags:
``` python
# Plot
fig,ax = plt.subplots(1,1); ax.plot(t, s(-t));
ax.set_xlabel(r'$\rightarrow t$'); ax.set_ylabel(r'$\uparrow s(-t)$', bbox=ient_wbbox)
ax.axis('equal'); ax.set_xlim([-2.25,2.25]); ient_grid(ax); ient_axis(ax);
```
%% Cell type:markdown id: tags:
### Demo: Zeitverschiebung, -dehnung und -spiegelung
$\displaystyle s\left(\pm\frac{t-t_0}{T}\right)$
%% Cell type:code id: tags:
``` python
s = lambda t: rect(t-0.5)*t
# Plot & demo
fig, ax = plt.subplots(1, 1, figsize=(8, 4))
@widgets.interact(T=widgets.FloatSlider(min=0.25, max=4, value=1, step=.1, description=r'Dehnung T', style=ient_wdgtl_style),
t0=widgets.FloatSlider(min=-2, max=2, value=0, step=.1, description=r'Verschiebung $t_0$', style=ient_wdgtl_style),
reflection=widgets.Checkbox(value=False, description='Spiegelung', style=ient_wdgtl_style))
def update_signals(T, t0, reflection):
if reflection:
T = -T
s_plot = s((t-t0)/T)
if not ax.lines: # plot s(t) and g(t)
ax.plot(t, s_plot, 'rwth');
ax.set_xlabel(r'$\rightarrow t$'); ax.set_ylabel(r'$\uparrow s\left(\pm\frac{t-t_0}{T}\right)$')
ax.axis('equal'); ax.set_xlim([-4.75, 4.75]); ient_axis(ax); ient_grid(ax); ax.minorticks_on()
else: # update lines
ax.lines[0].set_ydata(s_plot);
```
%% Cell type:markdown id: tags:
This notebook is provided as [Open Educational Resource](https://en.wikipedia.org/wiki/Open_educational_resources) (OER). Feel free to use the notebook for your own purposes. The code is licensed under the [MIT license](https://opensource.org/licenses/MIT).
Please attribute the work as follows:
*Christian Rohlfing, Übungsbeispiele zur Vorlesung "Grundgebiete der Elektrotechnik 3 - Signale und Systeme"*, gehalten von Jens-Rainer Ohm, 2019, Institut für Nachrichtentechnik, RWTH Aachen University.
......
......@@ -197,7 +197,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
"version": "3.7.3"
}
},
"nbformat": 4,
......
%% Cell type:code id: tags:
``` python
# Copyright 2019 Institut für Nachrichtentechnik, RWTH Aachen University
%matplotlib notebook
from ipywidgets import interact, interactive
import ipywidgets as widgets
from IPython.display import clear_output, display, HTML
from scipy import signal
from ient_nb.ient_plots import *
from ient_nb.ient_signals import *
```
%% Cell type:markdown id: tags:
<div class="inline-block">
<img src="ient_nb/figures/rwth_ient_logo@2x.png" style="float: right;height: 5em;">
</div>
# RL-Netzwerk
%% Cell type:markdown id: tags:
## Berechnung von Betrag und Phase
Spannung
$U_1(F) = R I_1(F)+U_2(F)$
und Strom
$\displaystyle I_1(F) = \frac{U_2(F)}{\mathrm{j}2 \pi F L}$
gibt
$U_1(F) = U_2(F) \left[ \frac{R}{\mathrm{j} 2\pi F L} + 1\right]$
bzw.
$\displaystyle H(F) = \frac{U_2(F)}{U_1(F)} = \frac{\mathrm{j}2 \pi F L}{R+\mathrm{j} 2 \pi F L}$
Mit
$T = \frac{L}{R}$
%% Cell type:code id: tags:
``` python
T = 1e-6
```
%% Cell type:markdown id: tags:
folgt $\displaystyle H(F) = \frac{\mathrm{j} 2 \pi FT}{1+\mathrm{j}2 \pi F T}$.
Eleminiere komplexen Term im Nenner:
$\displaystyle H(F)
= \frac{\mathrm{j} 2 \pi F T}{1+\mathrm{j}2 \pi FT} \frac{1-\mathrm{j}2 \pi FT}{1-\mathrm{j}2 \pi FT}
= \frac{\mathrm{j}2\pi F T+\left(2\pi F T\right)^2}{1+\left(2 \pi F T\right)^2}$
Betrag
$$|H(F)|
= \frac{|2\pi F T|}{\sqrt{1+\left(2 \pi F T\right)^2}}$$
%% Cell type:code id: tags:
``` python
def Habs(F):
return abs(2*np.pi*F*T)/np.sqrt(1+(2*np.pi*F*T)**2);
```
%% Cell type:markdown id: tags:
Phase
$$\varphi(F)
= \mathrm{arctan}\left(\frac{\mathrm{Im}\left\{H(F)\right\}}{\mathrm{Re}\left\{H(F)\right\}}\right)
= \mathrm{arctan}\left(\frac{1}{2\pi F T}\right)$$
%% Cell type:code id: tags:
``` python
def Hphi(F):
return np.arctan(1/(2*np.pi*F*T));
```
%% Cell type:markdown id: tags:
Plotte $|H(F)$ und $\varphi(F)$:
%% Cell type:code id: tags:
``` python
RL = 1/T; RLF = RL/(2*np.pi);
(F, deltaF) = np.linspace(-.75, .75, 4001, retstep=True) + eps # F-axis in MHz
# Plot
fig, axs = plt.subplots(1, 2, figsize=(8,4));
ax = axs[0]; ax.plot(F, Habs(F*1e6), 'rwth');
ax.plot([-RLF/1e6, RLF/1e6], [1/np.sqrt(2), 1/np.sqrt(2)], 'k--',
[-RLF/1e6,-RLF/1e6], [0, 1/np.sqrt(2)], 'k--',
[RLF/1e6,RLF/1e6], [0, 1/np.sqrt(2)], 'k--');
ax.set_yticks([0,1/np.sqrt(2), 1]); ax.set_yticklabels([r'$0$', r'$1/\sqrt{2}$', r'$1$']);
ax.set_xlabel(r'$\rightarrow F$ [MHz]'); ax.set_ylabel(r'$\uparrow |H(F)|$'); ient_axis(ax);
ax.yaxis.get_major_ticks()[1].label.set_verticalalignment('bottom');
ax = axs[1]; ax.plot(F, Hphi(F*1e6), 'rwth');
ax.plot([-RLF/1e6, 0], [-np.pi/4, -np.pi/4], 'k--',
[-RLF/1e6,-RLF/1e6], [0, -np.pi/4], 'k--',
[RLF/1e6, 0], [np.pi/4, np.pi/4], 'k--',
[RLF/1e6,RLF/1e6], [0, np.pi/4], 'k--');
ax.set_yticks([-np.pi/2,-np.pi/4,0,np.pi/4,np.pi/2]);
ax.set_yticklabels([r'$-\pi/2$', r'$-\pi/4$', r'$0$', r'$\pi/4$',r'$\pi/2$']);
ax.set_xlabel(r'$\rightarrow F$ [MHz]'); ax.set_ylabel(r'$\uparrow \varphi(F)$'); ient_axis(ax);
```
%% Cell type:markdown id: tags:
Werte Betrag und Phase aus für $F=100\ \mathrm{kHz}$
%% Cell type:code id: tags:
``` python
F = 100e3; # Hz
print('|H(F)| = {0:.3f}'.format(Habs(F)))
print('phi(F) = {0:.3f}°'.format(Hphi(F)*180/np.pi))
```
%% Cell type:markdown id: tags:
Werte Betrag und Phase aus für $F=300\ \mathrm{kHz}$
%% Cell type:code id: tags:
``` python
print('|H(3F)| = {0:.3f}'.format(Habs(3*F)))
print('phi(3F) = {0:.3f}°'.format(Hphi(3*F)*180/np.pi))
```
%% Cell type:markdown id: tags:
Zusätzlich Betrag für $F=0$
%% Cell type:code id: tags:
``` python
print('|H(0)| = {0:.3f}'.format(Habs(0)))
```
%% Cell type:markdown id: tags:
## Berechnung der Ausgangsspannung
Eingangsspannung (aus Aufgabenstellung):
$u_1(t)
= 1 \mathrm{V}
+ 1 \mathrm{V} \cos\left(2 \pi F t\right)
- 0{,}3 \mathrm{V} \cos\left(6 \pi F t\right)$
Ausgangsspannung:
$u_2(t)
= \underbrace{
|H(0)|\,1 \mathrm{V}}_{=0}
+ |H\left(F\right)|\,1 \mathrm{V}\, \cos\left(2 \pi F t + \varphi(F)\right)
- 0{,}3 \mathrm{V}\, |H(3F)| \cos\left(2\cdot3 \pi F t + \varphi(3F)\right)
\\
=
|H(F)| \, 1 \mathrm{V}\, \cos\left(2 \pi F \left[t - t_0\right]\right)
- 0{,}3\mathrm{V}\, |H(3F)| \cos\left(2\cdot3 \pi F \left[t - t_1\right]\right)$
mit Phasenlaufzeiten
$\displaystyle t_0 = -\frac{\varphi(F)}{2\pi F}$ und $\displaystyle t_1 = -\frac{\varphi(3F)}{6\pi F}$
%% Cell type:code id: tags:
``` python
phaseDelay = lambda F: -Hphi(F)/(2*np.pi*F);
print('t0 = {0:.3e} s'.format(phaseDelay(F)))
print('t1 = {0:.3e} s'.format(phaseDelay(3*F)))
```
%% Cell type:markdown id: tags:
## Skizze der Eingangs- und Ausgangsspannungen
### Skizze von beiden Komponenten von $u_2\left(t\right)$
Skizze $|H\left(F\right)| \cos\left(2 \pi F \left[t-t_0\right]\right)$
%% Cell type:code id: tags:
``` python
def u2p1(t,F): # first component of u2(t)
return Habs(F)*np.cos(2*np.pi*F*(t-phaseDelay(F)));
(t,deltat) = np.linspace(-10, 10, 10001, retstep=True) # t-axis
t0 = phaseDelay(F) # Phase Delay
# Plot
fig,ax = plt.subplots(1,1,figsize=(6,2)); ax.plot(t, u2p1(t/1e6,F), 'rwth');
ax.set_xlabel(r'$t/\mu\mathrm{s}\rightarrow$',x=0.9);
ax.set_ylabel(r'$\uparrow |H\left(F\right)| \cos\left(2 \pi F \left[t-t_0\right]\right)$');
ax.plot([t0*1e6, t0*1e6], [0, u2p1(t0,F)], '--', color='grun', lw=1)
ax.text(t0*1e6,0, r'$t_0$', fontsize=14, horizontalalignment='left', verticalalignment='top',color='grun')
ax.set_xlim(-11, 11); ient_axis(ax);
```
%% Cell type:markdown id: tags:
Skizze $|H\left(3F\right)| \cos\left(6 \pi F \left[t-t_1\right]\right)$
%% Cell type:code id: tags:
``` python
def u2p2(t,F): # second component of u2(t)
return Habs(3*F)*np.cos(6*np.pi*F*(t-phaseDelay(3*F)));
t1 = phaseDelay(3*F) # phase delay
# Plot
fig,ax = plt.subplots(1,1,figsize=(6,2)); ax.plot(t, u2p2(t/1e6,F), 'rwth');
ax.set_xlabel(r'$t/\mu\mathrm{s}\rightarrow$');
ax.set_ylabel(r'$\uparrow |H\left(3F\right)| \cos\left(6 \pi F \left[t-t_1\right]\right)$');
ax.plot([t1*1e6, t1*1e6], [0, u2p2(t1,F)], '--', color='grun', lw=1)
ax.text(t1*1e6,0, r'$t_1$', fontsize=14, horizontalalignment='right', verticalalignment='top',color='grun')
ax.set_xlim(-11, 11); ax.set_ylim(-1.5, 1.5); ient_axis(ax);
```
%% Cell type:markdown id: tags:
Skizze von
$$u_1(t) = 1 \mathrm{V}
+ 1 \mathrm{V} \cos\left(2 \pi F t\right)
- 0{,}3 \mathrm{V} \cos\left(6 \pi F t\right)\quad \text{und}$$
$$
u_2(t)
= |H\left(F\right)|1 \mathrm{V} \cos\left(2 \pi F \left[t-t_0\right]\right)
- 0{,}3\mathrm{V} |H\left(3F\right)| \cos\left(2\cdot3 \pi F \left[t-t_1\right]\right)
$$
für $F=100\,\mathrm{kHz}$ und $F=1\,\mathrm{MHz}$
%% Cell type:code id: tags:
``` python
def u1(t, F):
return 1 + np.cos(2*np.pi*F*t) - 0.3*np.cos(6*np.pi*F*t);
def u2(t, F):
return u2p1(t,F) - 0.3*u2p2(t,F);
# Plot
fig, axs = plt.subplots(1,2,figsize=(6,4));
ax = axs[0];
ax.plot(t, u1(t/1e6,F), 'rwth', label=r'$u_1\left(t\right)/\mathrm{V}$');
ax.plot(t, u2(t/1e6,F), 'grun', label=r'$u_2\left(t\right)/\mathrm{V}$');
ax.set_title(r'$F=100\,\mathrm{kHz}$'); ax.set_xlabel(r'$t/\mu\mathrm{s}\rightarrow$');
ax.set_xlim(-11, 11); ax.legend(); ient_axis(ax);
scale = 10;
ax = axs[1];
ax.plot(t, u1(t/1e6,F*scale), 'rwth', label=r'$u_1\left(t\right)/\mathrm{V}$')
ax.plot(t, u2(t/1e6,F*scale), 'grun', label=r'$u_2\left(t\right)/\mathrm{V}$')
ax.set_title(r'$F=1\,\mathrm{MHz}$'); ax.set_xlabel(r'$t/\mu\mathrm{s}\rightarrow$');
ax.set_xlim(-11/scale, 11/scale); ax.legend(); ient_axis(ax);
```
%% Cell type:markdown id: tags:
## Interaktive Demo
%% Cell type:code id: tags:
``` python
(f,deltaf) = np.linspace(-2, 2, 10001, retstep=True) # f-axis
fig,axs = plt.subplots(1,2,figsize=(8,4));
@widgets.interact(Fsel=widgets.FloatSlider(min=.1, max=2, step=.1, value=.1, description='$F$ [MHz]'))
def update_plot(Fsel):
u1scaled = u1(t/1e6, Fsel*1e6);
u2scaled = u2(t/1e6, Fsel*1e6)
if not axs[0].lines: # Call plot() and decorate axes. Usually, these functions take some processing time
ax = axs[0];
p1, = ax.plot(t, u1scaled, 'rwth', label=r'$u_1\left(t\right)/\mathrm{V}$');
p2, = ax.plot(t, u2scaled, 'grun', label=r'$u_2\left(t\right)/\mathrm{V}$');
ax.set_xlim(-1.1/Fsel, 1.1/Fsel);
ax.set_xlabel(r'$t/\mu\mathrm{s}\rightarrow$');
ax.set_title(r'$F={}\mathrm{{MHz}}$'.format(Fsel)); ient_axis(ax); ax.legend();
ax = axs[1]; ax.plot(f,Habs(f*1e6))
ax.plot([Fsel, Fsel], [0, Habs(Fsel*1e6)], 'ko--', lw=1);
ax.set_xlabel(r'$\rightarrow F/\mathrm{MHz}$'); ax.set_ylabel(r'$\uparrow |H(F)|$');
ax.set_title(r'Übertragungsfunktion'); ient_axis(ax);
else: # If lines exist, replace only xdata and ydata since plt.plot() takes longer time
axs[0].lines[0].set_ydata(u1scaled)
axs[0].lines[1].set_ydata(u2scaled)
axs[1].lines[1].set_xdata([Fsel, Fsel])
axs[1].lines[1].set_ydata([0, Habs(Fsel*1e6)])
axs[0].set_xlim(-1.1/Fsel, 1.1/Fsel);
axs[0].set_title(r'$F={}\mathrm{{MHz}}$'.format(Fsel))
```
%% Cell type:markdown id: tags:
This notebook is provided as [Open Educational Resource](https://en.wikipedia.org/wiki/Open_educational_resources) (OER). Feel free to use the notebook for your own purposes. The code is licensed under the [MIT license](https://opensource.org/licenses/MIT).
Please attribute the work as follows:
*Christian Rohlfing, Übungsbeispiele zur Vorlesung "Grundgebiete der Elektrotechnik 3 - Signale und Systeme"*, gehalten von Jens-Rainer Ohm, 2019, Institut für Nachrichtentechnik, RWTH Aachen University.
......
......@@ -293,7 +293,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
"version": "3.7.3"
}
},
"nbformat": 4,
......
%% Cell type:code id: tags:
``` python
# Copyright 2019 Institut für Nachrichtentechnik, RWTH Aachen University
%matplotlib notebook
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
from scipy import signal # convolution
from scipy.io import wavfile # wavfile
from ient_nb.ient_plots import *
from ient_nb.ient_signals import *
from ient_nb.ient_audio import *
from ient_nb.ient_transforms import *
fs = 22050 # sampling rate
(t,deltat) = np.linspace(0,10, 10*fs, retstep=True) # time axis
# wrapper functions for bandpass, lowpass and filtering
def butter_bandpass(f0, fdelta, fs, order=4):
nyq = 0.5 * fs # Nyquist frequency
normal_min = (f0-fdelta/2) / nyq # normalized
normal_max = (f0+fdelta/2) / nyq # normalized
b, a = signal.butter(order, [normal_min,normal_max], btype='bandpass', analog=False)
return b, a
def butter_lowpass(cutoff, fs, order=4):
nyq = 0.5 * fs # Nyquist frequency
normal_cutoff = cutoff / nyq # normalized cutoff-frequency
b, a = signal.butter(order, normal_cutoff, btype='lowpass', analog=False)
return b, a
def butter_filter(s, b, a):
g = signal.lfilter(b, a, s)
return g
```
%% Cell type:markdown id: tags:
<div>
<img src="ient_nb/figures/rwth_ient_logo@2x.png" style="float: right;height: 5em;">
</div>
# Äquivalenter Tiefpass
## Sprachsignal
Einlesen und darstellen eines Sprachsignals $s(t)$ sowie dessen Fourier-Transformierte $S(f)$. Bei reellwertigen Signalen $s(t)$, wie hier der Fall, ist das Spektrum $S(f)$ eine gerade komplexe Funktion mit $S(-f)=S^\ast(f)$ ist.
%% Cell type:code id: tags:
``` python
fs, data = wavfile.read('data/krawehl_krawehl.wav'); data = data[int(3.25*fs):int(4.5*fs),0] # crop and mono
s = 0.99*data/np.max(np.abs(data)) # Normalisieren
(t, deltat) = np.linspace(0, len(s)/fs, len(s), retstep=True) # time axis in seconds
S, f = ient_dft(s, fs) # Fourier transform
# Plot
fix, axs = plt.subplots(2,1)
ax = axs[0]; ax.plot(t, s, 'rwth'); ient_axis(ax);
ax.set_xlabel(r'$\rightarrow t$ [s]', bbox=ient_wbbox); ax.set_ylabel(r'$\uparrow s(t)$', bbox=ient_wbbox);
ax = axs[1]; ax.plot(f/1000, np.abs(S), 'rwth'); ient_axis(ax); ax.set_xlim([-7.5, 7.5]);
ax.set_xlabel(r'$\rightarrow f$ [kHz]', bbox=ient_wbbox); ax.set_ylabel(r'$\uparrow |S(f)|$');
ient_audio_play(s, fs)
```
%% Cell type:markdown id: tags:
## Tiefpassfilterung
Im Folgenden sei $\tilde{s}(t)$ ein Tiefpasssignal mit $f_\mathrm{g}=3\,\mathrm{kHz}$. Dazu wird $s(t)$ mit einem Butterworth-Tiefpass gefiltert.
%% Cell type:code id: tags:
``` python
fg = 3000
b, a = butter_lowpass(fg, fs) # generate filter coefficients
_, H = signal.freqz(b, a, worN=int(len(t)/2+1)) # compute H(f)=H(z=e^(j 2 pi f)) out of b, a
f = np.linspace(0, fs/2, len(H));
# Plot
fig,ax = plt.subplots(1,1); ax.plot(f/1000, np.abs(H), 'rwth');
ax.axvline(fg, color='k', linestyle='--',lw=0.5); # cutoff frequency
ax.set_xlabel(r'$\rightarrow f$ [kHz]', bbox=ient_wbbox); ax.set_ylabel(r'$\uparrow |H_\mathrm{LP}(f)|$');
ax.set_xlim([0,7.5]); ax.set_ylim([-.25,1.19]); ient_axis(ax);
```