Skip to content

Instantly share code, notes, and snippets.

@pichenettes
Created September 18, 2016 20:30
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 pichenettes/482565a12afe238379d709972c7447cf to your computer and use it in GitHub Desktop.
Save pichenettes/482565a12afe238379d709972c7447cf to your computer and use it in GitHub Desktop.
Pulse waveform additive synthesis
import numpy
import pylab
ratio = 0.333
t = numpy.arange(1000.0) / 1000.0
s = 0
for n in xrange(1, 1000):
harmonic = numpy.cos(2 * numpy.pi * t * n)
amplitude = 2 * numpy.sin(numpy.pi * n * ratio) / (n * numpy.pi * ratio)
s += harmonic * amplitude
pylab.plot(s)
pylab.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment