1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
{\rtf1\mac\ansicpg10000\cocoartf824\cocoasubrtf410
{\fonttbl\f0\fswiss\fcharset77 Helvetica-Bold;\f1\fnil\fcharset77 Monaco;\f2\fswiss\fcharset77 Helvetica;
}
{\colortbl;\red255\green255\blue255;\red191\green0\blue0;\red0\green0\blue191;\red96\green96\blue96;
\red0\green0\blue0;}
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural
\f0\b\fs36 \cf0 FFTDiffMags A simple spectral difference measure
\f1\b0\fs18 \
\
\f2\fs24 Compares the spectra of two signals, finding the magnitude of the difference for each frequency bin. These differences are averaged onto the (control-rate) output.\
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural
\f1\fs18 \cf2 \
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural
\f0\b\fs24 \cf0 FFTDiffMags.kr(chain1, chain2)\
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural
\f1\b0\fs18 \cf2 \
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural
\f2\fs24 \cf0 Note that this crude measure works on a bin-by-bin basis and is not clever enough to detect higher-order similarities between spectra (such as general treble/bass balance).\
\
See also PV_DiffMags which performs the same calculation but doesn't sum the difference values - it leaves them in the frequency-domain buffer for further use.\
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural\pardirnatural
\f1\fs18 \cf0 \
\
\cf2 // How different are the spectra of square waves at different PWM settings?\cf0 \
\cf2 // This test outputs two square waves, one of whose PWM is controlled by \cf0 \
\cf2 // MouseX - in the middle of the screen, the PWMs match,\cf0 \
\cf2 // but at either side they are more different.\cf0 \
\cf2 // Watch the output to channel 0 to see the shape of the returned signal\cf0 \
\
\cf3 Server\cf0 .default_(s = \cf3 Server\cf0 .internal.boot);\
b = \cf3 Buffer\cf0 .alloc(s, 1024, 1);\
c = \cf3 Buffer\cf0 .alloc(s, 1024, 1);\
(\
\{\
\cf3 var\cf0 chain1, chain2, chain, sig1, sig2, difference;\
sig1 = \cf3 Pulse\cf0 .ar(100, \cf3 MouseX\cf0 .kr(0.1, 0.9));\
sig2 = \cf3 Pulse\cf0 .ar(100, 0.5);\
chain1 = \cf3 FFT\cf0 (b.bufnum, sig1);\
chain2 = \cf3 FFT\cf0 (c.bufnum, sig2);\
difference = \cf3 FFTDiffMags\cf0 .kr(chain1, chain2);\
\
difference.poll(1, \cf4 "difference between spectra:"\cf0 );\
\cf5 \
[sig1, sig2] * 0.1;\
\}.scope\
)}
|