Overview about non-sinusoidal periodic waveforms.
%matplotlib inline
import matplotlib.pyplot as plt
from IPython.display import Audio
import numpy as np
from _utils import *
plt.rcParams['figure.figsize'] = (16, 4)
fs = 44100 # Sampling rate
dur = 3 # Duration in seconds
t = np.linspace(0, dur, fs*dur) # Time vector
where,
A = 0.25
f = 110
omega = 2*np.pi*f
phi = 0
x_sqr = A*np.sign(np.sin(omega*t + phi))
x_sqr[-1] = 1 # fix normalized output
Audio(x_sqr, rate=fs)
audiovis(x_sqr[:-1], tlim=[0, 0.04])
audio mono
N = 32
K = np.array([range(N)]).T + 1.0
_x_sqrh = np.sin((2*K - 1)*(omega*t + phi))/(2*K - 1)
x_sqrh = A*4/np.pi*np.sum(_x_sqrh, axis=0)
x_sqrh[-1] = 1 # fix normalized output
for h in _x_sqrh:
plt.plot(t, h)
plt.xlim([0, 1/f])
plt.title('Harmonics')
plt.show()
Audio(x_sqrh, rate=fs)
audiovis(x_sqrh[:-1], tlim=[0, 0.04])
audio mono
spectrogram(x_sqrh)
audio mono
A = 0.5
a = 1/(2*f)
floor = np.vectorize(np.floor)
tpw = t + phi/omega # only for saving space
x_tri = A*2/a*(tpw - a*floor(tpw/a + 1/2))*(-1)**floor(tpw/a + 1/2)
x_tri[-1] = 1 # fix normalized output
Audio(x_tri, rate=fs)
audiovis(x_tri[:-1], tlim=[0, 0.04])
audio mono
N = 16
K = np.array([range(N)]).T
_x_trih = (-1)**K*np.sin((2*K + 1)*(omega*t + phi))/(2*K + 1)**2
x_trih = A*8/np.pi**2*np.sum(_x_trih, axis=0)
x_trih[-1] = 1 # fix normalized output
for h in _x_trih:
plt.plot(t, h)
plt.xlim([0, 1/f])
plt.title('Harmonics')
plt.show()
Audio(x_trih, rate=fs)
audiovis(x_trih[:-1], tlim=[0, 0.04])
audio mono
spectrogram(x_trih)
audio mono
A = 0.25
a = 1/f
floor = np.vectorize(np.floor)
x_saw = A*2*(t/a + phi/(omega*a) - floor(t/a + phi/(omega*a) + 1/2))
x_saw[-1] = 1 # fix normalized output
Audio(x_saw, rate=fs)
audiovis(x_saw[:-1], tlim=[0, 0.04])
audio mono
N = 64
K = np.array([range(N)]).T + 1.0
_x_sawh = (-1)**K*np.sin(K*(omega*t + phi))/K
x_sawh = A/2 - A/np.pi*np.sum(_x_sawh, axis=0)
x_sawh[-1] = 1 # fix normalized output
for h in _x_sawh:
plt.plot(t, h)
plt.xlim([0, 1/f])
plt.title('Harmonics')
plt.show()
Audio(x_sawh, rate=fs)
audiovis(x_sawh[:-1], tlim=[0, 0.04])
audio mono
spectrogram(x_sawh)
audio mono
A = 0.25
T = 1/f # Period
tau = 0.1
tau *= T
x1 = (t + phi/(2*np.pi*f)) % T
x_pulse = A*(x1 <= tau)
x_pulse[-1] = 1 # fix normalized output
Audio(x_pulse, rate=fs)
audiovis(x_pulse[:-1], tlim=[0, 0.04])
audio mono
N = 64
K = np.array([range(N)]).T + 1.0
_x_pulseh = 2/(K*np.pi)*np.sin(np.pi*K*tau/T)*np.cos(2*np.pi*K/T*(t + T*phi/(2*np.pi) - tau/2))
x_pulseh = A*(tau/T + np.sum(_x_pulseh, axis=0))
x_pulseh[-1] = 1 # fix normalized output
for h in _x_pulseh:
plt.plot(t, h)
plt.xlim([0, 1/f])
plt.title('Harmonics')
plt.show()
Audio(x_pulseh, rate=fs)
audiovis(x_pulseh[:-1], tlim=[0, 0.04])
audio mono
spectrogram(x_pulseh)
audio mono