Skip to content

Instantly share code, notes, and snippets.

@rlee287
Last active April 15, 2017 21:01
Show Gist options
  • Save rlee287/746e96c7b9e9dd5cfe2f1a40c7b6dc1a to your computer and use it in GitHub Desktop.
Save rlee287/746e96c7b9e9dd5cfe2f1a40c7b6dc1a to your computer and use it in GitHub Desktop.
The effect of noise on numerical integration
import numpy as np
from scipy import integrate
import matplotlib.pyplot as plt
# Testing data that can be replaced with file load-in
x=np.linspace(0,100,201)
accel=np.zeros_like(x)
accel[30:32]=1
accel[50:52]=-1
velocity=integrate.cumtrapz(accel,x,initial=0)
plt.plot(x,accel,label="Pulses")
plt.plot(x,velocity,label="Integrate")
plt.legend()
plt.show()
import numpy as np
from scipy import integrate
import matplotlib.pyplot as plt
# Testing data that can be replaced with file load-in
x=np.linspace(0,100,201)
accel=np.zeros_like(x)
accel[30:32]=1
accel[50:52]=-1
ran=np.random.rand(201)
ran-=0.5
ran*=0.04
accel+=ran
velocity=integrate.cumtrapz(accel,x,initial=0)
plt.plot(x,accel,label="Pulses")
plt.plot(x,velocity,label="Integrate")
plt.legend()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment