#!/usr/bin/python
# -*- coding: utf8 -*-
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
from math import *
code_website = 'http://commons.wikimedia.org/wiki/User:Geek3/mplwp'
try:
import mplwp
except ImportError, er:
print 'ImportError:', er
print 'You need to download mplwp.py from', code_website
exit(1)
name = 'mplwp_window-functions-symmetric.svg'
fig = mplwp.fig_standard(mpl)
xlim = -1.05,1.05; fig.gca().set_xlim(xlim)
ylim = 0,1.04; fig.gca().set_ylim(ylim)
fig.gca().xaxis.set_major_locator(mpl.ticker.MultipleLocator(0.5))
mplwp.mark_axeszero(fig.gca())
l, r, t, b = (42.5, 16.5, 18.5, 26.5)
mplwp.set_bordersize(fig, l, r, t, b)
x = np.linspace(-1, 1, 5001)
plt.plot([-1, -1, 1, 1], [0, 1, 1, 0], label='Boxcar')
def welch(x):
return 1.0 - x**2
plt.plot(x, [welch(xx) for xx in x], label='Welch')
def cosw(x):
return cos(x * pi / 2.0)
plt.plot(x, [cosw(xx) for xx in x], label='Cos')
def lanczos(x):
if x == 0.: return 1.0
return sin(x * pi) / (x * pi)
plt.plot(x, [lanczos(xx) for xx in x], label='Lanczos')
def hamming(x):
return 0.54 + 0.46 * cos(x * pi)
plt.plot([-1] + list(x) + [1], [0] + [hamming(xx) for xx in x] + [0],
label='Hamming')
def hann(x):
return 0.5 + 0.5 * cos(x * pi)
plt.plot(x, [hann(xx) for xx in x], label='Hann')
def blackman(x):
alpha = 0.16
return (1-alpha) / 2.0 + 0.5 * cos(x*pi) + alpha / 2.0 * cos(x*2*pi)
plt.plot(x, [blackman(xx) for xx in x], label='Blackman')
def bartlett(x):
return 1.0 - fabs(x)
plt.plot(x, [bartlett(xx) for xx in x], label='Bartlett')
plt.legend(loc='lower center',
borderaxespad=0.5, labelspacing=0.3, handletextpad=0.4)
plt.savefig(name)
mplwp.postprocess(name)