#! /usr/bin/env python3 from scipy import signal import numpy as np import matplotlib.pyplot as plt count = 4 sample_rate = 44100 freq = 1000 timescale = 0.00215 samples = np.arange( timescale * sample_rate) / sample_rate samples_psd = np.arange( 1000 * timescale * sample_rate) / sample_rate fig = plt.figure(1, figsize=( 10, 7)) fig.tight_layout() hoehe, breite = count, 2 index = 0 factor = 1.0 frequency = freq * factor sig = np.sin( 2 * np.pi * samples * frequency) sig_psd = np.sin( 2 * np.pi * samples_psd * frequency) ax = plt.subplot( hoehe, breite, ( index * breite) + 1) plt.title( 'Sinus', loc = 'right', y = 0.6) plt.autoscale( axis = 'y') plt.xlim( [ 0, len( sig)-1]) plt.plot( sig) ax.grid( True) ax = plt.subplot( hoehe, breite, ( index * breite) + 2) plt.xlim( [ 0, 1.0]) plt.ylim( [ -20, 20]) plt.psd( sig_psd) ax.grid( True) plt.ylabel( '') index = 1 factor = 1.0 frequency = freq * factor sig = signal.sawtooth( 2 * np.pi * samples * frequency, width = 0.5) sig_psd = signal.sawtooth( 2 * np.pi * samples_psd * frequency, width = 0.5) ax = plt.subplot( hoehe, breite, ( index * breite) + 1) plt.title( 'Dreieck', loc = 'right', y = 0.6) plt.autoscale( axis = 'y') plt.xlim( [ 0, len( sig)-1]) plt.plot( sig) ax.grid( True) ax = plt.subplot( hoehe, breite, ( index * breite) + 2) plt.xlim( [ 0, 1.0]) plt.ylim( [ -20, 20]) plt.psd( sig_psd) ax.grid( True) #plt.ylabel( '') index = 2 factor = 1.0 frequency = freq * factor sig = signal.square( 2 * np.pi * samples * frequency) sig_psd = signal.square( 2 * np.pi * samples_psd * frequency) ax = plt.subplot( hoehe, breite, ( index * breite) + 1) plt.title( 'Rechteck', loc = 'right', y = 0.6) plt.autoscale( axis = 'y') plt.xlim( [ 0, len( sig)-1]) plt.plot( sig) ax.grid( True) ax = plt.subplot( hoehe, breite, ( index * breite) + 2) plt.xlim( [ 0, 1.0]) plt.ylim( [ -20, 20]) plt.psd( sig_psd) ax.grid( True) plt.ylabel( '') index = 3 factor = 1.0 frequency = freq * factor sig = signal.square( 2 * np.pi * samples * frequency, duty = 0.08) sig_psd = signal.square( 2 * np.pi * samples_psd * frequency, duty = 0.08) ax = plt.subplot( hoehe, breite, ( index * breite) + 1) plt.title( 'Puls', loc = 'right', y = 0.6) plt.autoscale( axis = 'y') plt.xlim( [ 0, len( sig)-1]) plt.plot( sig) ax.grid( True) ax = plt.subplot( hoehe, breite, ( index * breite) + 2) plt.xlim( [ 0, 1.0]) plt.ylim( [ -20, 20]) plt.psd( sig_psd) ax.grid( True) plt.ylabel( '') plt.show()