Fourierreihe¶

Gleichung der Rechteckkurve \begin{equation} f(x) = 1 \quad 0 \, \le \, x \, \le \, \pi \end{equation} \begin{equation} f(x) = -1 \quad \pi \, \le \, x \, \le \, 2\pi \end{equation}

In [1]:
import matplotlib
import matplotlib.pyplot as plt
import numpy as np

import warnings
# Ignore all warnings
warnings.simplefilter('ignore')
In [2]:
data = [[0,1],[np.pi,1],[np.pi,-1],[2*np.pi,-1],[2*np.pi,1],[3*np.pi,1],[3*np.pi,-1],[4*np.pi,-1]] 

fig, ax = plt.subplots(1,1,figsize=(10,4))
ax.plot([x for (x,y) in data],[y for (x,y) in data],linewidth=3,color='g')
ax.grid(True)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_xlim(0,4*np.pi)
ax.set_ylim(-1.5,1.5)
ax.set_title('Rechteckimpuls')
plt.show()
No description has been provided for this image
In [3]:
fig, ax = plt.subplots(1,1,figsize=(10,4))

xdata = np.linspace(0,4*np.pi,401)
for degree in [1,5,51,501]:
    ydata = np.zeros((401,))
    for d in range(1,degree+1,2):
        koeff = 2*(-(-1)**d + 1)/(np.pi*d)
        ydata = ydata + koeff*np.sin(d*xdata)
    ax.plot(xdata,ydata,linewidth=1,label='N = {}'.format(degree))

ax.grid(True)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_xlim(0,4*np.pi)
ax.set_ylim(-1.5,1.5)
ax.legend()
ax.set_title('Rechteckimpuls')
plt.show()
No description has been provided for this image
In [4]:
fig, ax = plt.subplots(1,1,figsize=(10,4))

degree = np.linspace(1,15,15)
coeff = 2/(np.pi*degree)*(1 - np.cos(np.pi*degree))
ax.bar(degree, coeff)

ax.grid(True)
ax.set_xlabel('degree')
ax.set_ylabel('Amplitude')
plt.show()
ax.set_title('Fourier Koeffizienten')
No description has been provided for this image
In [5]:
data = [[-np.pi,0],[0,0],[0,1],[np.pi,1],[np.pi,-1],[2*np.pi,-1],[2*np.pi,0],[3*np.pi,0]] 

fig, ax = plt.subplots(1,1,figsize=(10,4))
ax.plot([x for (x,y) in data],[y for (x,y) in data],linewidth=3,color='g')
ax.grid(True)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_xlim(-np.pi,3*np.pi)
ax.set_ylim(-1.5,1.5)
ax.set_title('Rechteckimpuls')
plt.show()
No description has been provided for this image
In [6]:
omega = np.linspace(-10,10,4002)
realpart = 2*np.sin(omega*np.pi) - np.sin(2*omega*np.pi)
impart = -1 + 2*np.cos(omega*np.pi) - np.cos(2*omega*np.pi)
amp = np.abs(1/omega*np.sqrt(realpart**2 + impart**2))

fig, ax = plt.subplots(1,1,figsize=(10,4))
ax.plot(omega, amp, linewidth=3, color='royalblue')
ax.grid(True)
ax.set_xlabel('$\omega$')
ax.set_ylabel('$|F(\omega)|$')
ax.set_title('Fouriertransformierte')
plt.show()
No description has been provided for this image
In [7]:
s = np.linspace(0,10,4002)
amp = 1/s*(1-2*np.exp(-s*np.pi) + np.exp(-s*2*np.pi))

fig, ax = plt.subplots(1,1,figsize=(10,4))
ax.plot(s, amp, linewidth=3, color='royalblue')
ax.grid(True)
ax.set_xlabel('$s$')
ax.set_ylabel('$L(s)$')
ax.set_title('Laplace-Transformierte')
plt.show()
No description has been provided for this image
In [ ]: