Skip to content

Instantly share code, notes, and snippets.

@sixtenbe
Created September 1, 2011 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sixtenbe/1185985 to your computer and use it in GitHub Desktop.
Save sixtenbe/1185985 to your computer and use it in GitHub Desktop.
analytic wafeforms
from numpy import linspace
from math import pi, sqrt, sin
#Heavyside step function
H = lambda t: 1 if t > 0 else 0
# pure sine
ACV_A1 = lambda T, Hz = 50: 1000 * sqrt(2) * np.sin(2*pi*Hz * T)
#
ACV_A2 = lambda T, Hz = 50: 1000 * sqrt(2) * np.sin(2*pi*Hz * T) + 500
#
ACV_A3 = lambda T, Hz = 50: 1000 * sqrt(2) * (np.sin(2*pi*Hz * T) +
0.05 * np.sin(2*pi*Hz * T * 4 + pi * 2 / 3))
#
ACV_A4 = lambda T, Hz = 50:( 1000 * sqrt(2) * (np.sin(2*pi*Hz * T) +
0.07 * np.sin(2*pi*Hz * T * 5 + pi * 22 / 18)))
# Realistic triangle
ACV_A5 = lambda T, Hz = 50:( 1000 * sqrt(2) * (np.sin(2*pi*Hz * T) +
0.05 * np.sin(2*pi*Hz * T * 3 - pi) +
0.05 * np.sin(2*pi*Hz * T * 5) +
0.02 * np.sin(2*pi*Hz * T * 7 - pi) +
0.01 * np.sin(2*pi*Hz * T * 9)))
#
ACV_A6 = lambda T, Hz = 50:( 1000 * sqrt(2) * (np.sin(2*pi*Hz * T) +
0.02 * np.sin(2*pi*Hz * T * 3 - pi) +
0.02 * np.sin(2*pi*Hz * T * 5) +
0.0015 * np.sin(2*pi*Hz * T * 7 - pi) +
0.009 * np.sin(2*pi*Hz * T * 9)))
#A7 & A8 convert so that a input of 16*pi corresponds to a input 0.25 in the current verion
ACV_A7 = lambda T: [1000*sqrt(2)*sin(100*pi*t)*(0.9*t/5*H(5-t) + H(t-5)*H(10-t)*(0.9+0.1*(t-5)/5)) for t in T]
ACV_A8 = lambda T: [1000*sqrt(2)*sin(t)*t/(10*pi)*H(10-t/(100*pi)) for t in T]
if __name__ == "__main__":
#create 1 period triangle
x = linspace(0,0.2*pi,8000)
y = ACV_A5(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment