Skip to content

Instantly share code, notes, and snippets.

@thomasaarholt
Created August 28, 2020 23:14
Show Gist options
  • Save thomasaarholt/6d2d8f145081501776c990f94380eb33 to your computer and use it in GitHub Desktop.
Save thomasaarholt/6d2d8f145081501776c990f94380eb33 to your computer and use it in GitHub Desktop.
Stackoverflow Distortion Example
import numpy as np
import matplotlib.pyplot as plt
N = 600
probe_positions = np.arange(N)
def probe_function(probe_positions):
return np.sin(2*np.pi*probe_positions / 150)**2
strength = 3
period = 50
shift = 5
disturbance = strength*np.sin((probe_positions - shift)*2*np.pi/period)
disturbed_probe_positions = probe_positions + disturbance
expr =r"{} \times sin((2 \pi \times x - {}) / {})".format(strength, shift, period)
fig, (ax1, ax2) = plt.subplots(nrows=2, figsize=(8,6))
ax1.plot(probe_positions, probe_function(probe_positions))
ax2.plot(probe_positions, probe_function(disturbed_probe_positions))
ax1.set_title('No distortion on probe position')
ax2.set_title('Periodic distortion on probe position by ${}$'.format(expr))
ax1.set_xlabel('Set probe position')
ax2.set_xlabel('Set probe position')
ax1.set_ylabel('Measured value')
ax2.set_ylabel('Measured value')
plt.tight_layout()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment