codexpressure-footprint-spatial-filter.py
pressure-footprint-spatial-filter.py
"""Illustrate ideal strip averaging, not the fluid mechanics of a real tap."""
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
x=np.linspace(0,2,1001)
y=np.sin(2*np.pi*x)
fig,ax=plt.subplots(figsize=(7.6,3.6),dpi=100,facecolor='white')
ax.set_facecolor('white')
ax.plot(x,y,color='#222222',lw=2,label='Point field')
for width,color,label in [(0.5,'#2166ac','Strip width = half a wavelength'),(1.0,'#b2182b','Strip width = one wavelength')]:
gain=np.sinc(width)
assert abs(gain-(2/np.pi if width==.5 else 0))<1e-12
ax.plot(x,gain*y,color=color,lw=2,ls='--' if width==1 else '-',label=label)
# Independently verify the analytic average at a crest.
for width in [.5,1.]:
z=np.linspace(.25-width/2,.25+width/2,100001)
integral=np.trapezoid(np.sin(2*np.pi*z),z)/width
assert abs(integral-np.sinc(width))<1e-8
ax.set(xlabel='Position / wavelength',ylabel='Pressure variation / amplitude',ylim=(-1.12,1.55),xlim=(0,2))
ax.set_title('A finite averaging footprint can erase spatial variation',fontsize=12)
ax.legend(loc='upper right',fontsize=8,frameon=True)
ax.grid(alpha=.2)
fig.tight_layout()
fig.savefig('pressure-footprint-spatial-filter.png',facecolor='white',dpi=100)