generateMelodicSeed = slow 4
$ linger 0.5
$ repeatCycles 3
-- $ palindrome \n
$ (+ (slow (irand (4)+1) (sometimes (inversion) (run (irand (4)+1)))))
$ slow ((irand 3) + 1)
$ e ("x"<~>(irand 8)) 8
$ "x*16"<~>(irand 5)
hush
let melody = slow 6 $ "0 2 [4 8 .] [3 4 3] 8 4 9"
d1
$ note
((scaleP scalePattern
$ off 4 ((+ 2 ).slow 2)
$ off 1 (inversion.slow 2)
$ off 3 (inversion.slow 3)
$ off 1.5 ((+ 2).rev.slow 2)
$ generateMelodicSeed
))#s "[pe-gtr:10,midi]" #gain 1 #orbit 0 #midichan 1
Window Function
A window function is a tool in Digital Signal Processing that allows a long signal to be broken into small pieces. Many window functions aim to do this without introducing discontinuities at the boundaries of these pieces. The window function does this by gradually reducing the gain of the signal to zero at the edges.
Some window functions have a useful property called overlap add. Signals that have been broken up using window functions with this property can be put back together again just by summing the pieces together where they overlap in time. Here is the property as a mathematical statement: \[ \sum{m=-\inf}^\inf w(n-mR) = 1 \]
spectral leakage
Multiplying by a window function convolves its spectra with the spectra of the signal you are windowing. Windowing a pure tone (\(cos(\omega\t)\)) will cause the energies to accumulate at frequencies other than \(\omega\). The spectral characteristics of the window determine the leakage and play a large role in selecting a window for a given task.
common functions
rectangular window
\[ w[n] = 1, 0 \leq n \leq N \]
triangular window
\[ w[n] = 1 - \abs(\frac{n - \frac{n}{2}{\frac{L}{2}}), 0 \leq n \leq N \]
sine
\[ w[n] = sin(\frac{\pi n}{N}) = cos(\frac{\pi n}{N} - \frac{\pi}{2}), 0 \leq n \leq N \]
a whole family of windows can be generated by taking powers of this window... for some power \(a\) - \(a=0\) -> rectangular - \(a=1\) -> sine - a=2 -> hann window
The even powers may be implemented as sums of cosines...
Hann
\[ w[n] = \frac{1}{2} [1 - cos(\frac{2\pi n}{N})] = sin^2 (\frac{\pi n}{N}) \]
Blackman-Harris
\[ w[n] = a_0 - a_1cos(\frac{2\pi\n}{N}) + a_2cos(\frac{4\pi\n}{N}) - a_3cos(\frac{6\pi\n}{N}) a_0 = 0.35875; a_1 = 0.48829; a_2 = 0.14128; a_3 = 0.01168; \]
Blackman
\[ w[n] = a_0 - a_1cos(\frac{2\pi\n}{N}) + a_2cos(\frac{4\pi\n}{N}) a_0 = \frac{1 - \alpha}{2}; a_1 = \frac{1}{2}; a_2 = \frac{\alpha}{2}; \]
Gaussian
\[ w[n] = \exp(-\frac{1}{2}(\frac{n-\frac{N}{2}}{\sigma\frac{N}{2}})^2), 0 \leq n \leq N. \sigma \leq 0.5 \]
The character of the window depends on selection of \(\alpha\). A common value is \(\alpha = 0.16\).
Welch window
\[ w[n] = 1 - (\frac{n-\frac{N}{2}}{\frac{N}{2}})^2 , 0 \leq n \leq N \]
notes: this window reaches 0 just outside its bounds creating a soft discontinuity
Parzen window
\[ w[n] = w_0(n- \frac{N}{2}), 0 \leq n \leq N w_0 \triangleq \left\{ \begin{array}{11} 1 - 6(\frac{n}{\frac{L}{2}})^2 &\quad 0 \leq \lvert n \rvert \leq \frac{L}{4} \\ 2(1-\frac{\lvert n \rvert}{\frac{L}{2}})^3 & \quad \frac{L}{4} < \lvert n \rvert \leq \frac{L}{2} \end{array} \right\} L = N + 1 \]