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)