#! /usr/bin/env python3 from scipy import signal import numpy as np import matplotlib.pyplot as plt count = 6 sample_rate = 44100 freq = 1000 timescale = 0.002 samples = np.arange( timescale * sample_rate) / sample_rate def generate_sine( factor = 1): amplitude = 1.0 / factor frequency = freq * factor return amplitude * np.sin( 2 * np.pi * samples * frequency) def generate_rect( max_harmonic = 1): harmonic = 1 signal = generate_sine( harmonic) while harmonic < max_harmonic: harmonic += 2 signal += generate_sine( harmonic) return signal fig = plt.figure(1, figsize=( 6, count * 3)) fig.subplots_adjust( hspace = 0.5) hoehe, breite = count, 1 for index in range( count): harmonic = index * 2 + 1 plt.subplot( hoehe, breite, index + 1) plt.title( 'mit %d. Oberw.' % harmonic, loc = 'right', y = 0.5) plt.step( generate_rect( harmonic), '.') plt.show()