File:Dirichlet kernels.svg

Summary

Description
English: Plots of the first few Dirichlet kernels made with matplotlib. This function has a period of 2π.
Date
Source Dirichlet.png
Author
Other versions
This is a retouched picture, which means that it has been digitally altered from its original version. Modifications: vectorized. The original can be viewed here: Dirichlet.png: . Modifications made by Azaghal of Belegost.

Category:SVG retouched pictures from raster#Dirichlet%20kernels.svg

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
Category:CC-BY-SA-4.0#Dirichlet%20kernels.svgCategory:Self-published work

Source code

Source Code in python:
from __future__ import division # In case someone wants to use Python 2
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns # Just for the colors

mpl.rcParams['axes.labelsize'] = 20
mpl.rcParams['axes.titlesize'] = 22
mpl.rcParams['legend.fontsize'] = 18
mpl.rcParams['xtick.labelsize'] = 14
mpl.rcParams['ytick.labelsize'] = 14
mpl.rcParams['lines.linewidth'] = 3

def dirichlet(n, x):
    return np.where(x!=0, np.sin((n + .5)*x)/np.sin(.5*x), 2*n + 1)

points = 2**10 + 1
kernels = 4
x_min = -np.pi
x_max = np.pi

x_vals = np.linspace(x_min, x_max, num=points)
n_vals = np.arange(1, kernels + 1)
D = dirichlet(np.resize(n_vals, (points, kernels)).T,
              np.resize(x_vals, (kernels, points)))

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
for kernel, n in zip(D, n_vals):
    ax.plot(x_vals, kernel,
            label=r'$\frac{\sin((' + str(n) + r'+1/2)x)}{\sin(x/2)}$')

ax.xaxis.set_ticks(np.pi*np.arange(-4, 5)/4)
ax.xaxis.set_ticklabels([r'$-\pi$', r'$-\frac{3\pi}{4}$', r'$-\frac{\pi}{2}$',
                         r'$-\frac{\pi}{4}$', r'$0$', r'$\frac{\pi}{4}$',
                         r'$\frac{\pi}{2}$', r'$\frac{3\pi}{4}$', r'$\pi$'])
ax.legend()
ax.set_xlim([x_min, x_max])
ax.set_xlabel(r'$x$')
ax.set_ylabel(r'$D_n(x)$')
ax.xaxis.grid(color='gray')
ax.yaxis.grid(color='gray')
plt.tight_layout()
plt.savefig('dirichlet.svg')
Category:Dirichlet kernels Category:Matplotlib SVG substitution Category:SVG created with Matplotlib
Category:CC-BY-SA-4.0 Category:Dirichlet kernels Category:Matplotlib SVG substitution Category:SVG created with Matplotlib Category:SVG retouched pictures from raster Category:Self-published work