Various ways to combine float waveforms

In a synthesizer multiple oscillators are usually mixed. This is a simple add-and-scale operation. The resulting waveform will contain the sum of the frequency spectra. Using other kind of 'combine' operation will create intersting new spectra.


In [55]:
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [56]:
x = linspace(0, 10)
y1 = sin(x)
y2 = sin(1.25 * x)
def plot_all(x,y3):
    grid(True)
    plot(x,y1)
    plot(x,y2)
    plot(x,y3)

In [57]:
y3 = np.fmin(y1, y2)
plot_all(x,y3)



In [58]:
y3 = np.fmax(y1, y2)
plot_all(x,y3)



In [59]:
y3 = np.fmod(y1, y2)
plot_all(x,y3)



In [60]:
y3 = np.arctan2(y1, y2) / np.pi
plot_all(x,y3)



In [61]:
def fold(w1, w2):
    w2a = math.fabs (w2);
    if w1 > 0.0:
        if w1 > w2a:
            return w2a - (w1 - w2a)
        else:
            return w1
    else:
        if w1 < -w2a:
            return -w2a - (w1 + w2a)
        else:
            return w1

vfold = np.vectorize(fold)
y3 = vfold(y1, y2)
plot_all(x,y3)



In [61]: