1 <!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8">
5 <meta http-equiv=
"Content-Style-Type" content=
"text/css">
7 <meta name=
"Generator" content=
"Cocoa HTML Writer">
8 <meta name=
"CocoaVersion" content=
"949.43">
9 <style type=
"text/css">
10 p
.p1
{margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica
}
11 p
.p2
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
; min-height: 14.0px}
12 p
.p3
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
}
13 p
.p4
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
; color: #001bec}
14 p
.p5
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; min-height: 12.0px}
15 p
.p6
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
}
16 p
.p7
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #9c221b}
17 p
.p8
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #0026b6}
18 p
.p9
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #9c221b; min-height: 12.0px}
19 span
.s1
{font: 18.0px Helvetica
}
20 span
.s2
{color: #000000}
21 span
.s3
{text-decoration: underline
}
22 span
.s4
{text-decoration: underline
; color: #0039dd}
23 span
.s5
{color: #0033f5}
24 span
.s6
{color: #0016bd}
25 span
.s7
{color: #0026b6}
26 span
.Apple-tab-span
{white-space:pre
}
30 <p class=
"p1"><span class=
"s1"><b>PV_Div
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b></span><b>complex division
</b></p>
31 <p class=
"p2"><br></p>
32 <p class=
"p3"><b>PV_Div(bufferA,
<span class=
"Apple-converted-space"> </span>bufferB)
</b></p>
33 <p class=
"p2"><br></p>
34 <p class=
"p3">Complex division.
</p>
35 <p class=
"p3"><b>bufferA
</b> - fft buffer A.
</p>
36 <p class=
"p3"><b>bufferB
</b> - fft buffer B.
</p>
37 <p class=
"p2"><br></p>
38 <p class=
"p4"><span class=
"s2">See also
<a href=
"PV_Mul.html"><span class=
"s3">PV_Mul
</span></a>,
<a href=
"PV_MagDiv.html"><span class=
"s3">PV_MagDiv
</span></a>,
<a href=
"FFT Overview.html"><span class=
"s4">FFT Overview
</span></a>.
</span></p>
39 <p class=
"p2"><br></p>
40 <p class=
"p5"><br></p>
41 <p class=
"p3"><b>Example
</b></p>
42 <p class=
"p3">In this example we estimate the transfer function of the
<a href=
"../Filters/LPF.html"><span class=
"s5">LPF
</span></a> UGen. The transfer function is estimated by dividing the FFT of the output, by the FFT of the input, and looking at the magnitudes in the result.
</p>
43 <p class=
"p5"><br></p>
45 <p class=
"p6">s.waitForBoot {
</p>
46 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"s6">var
</span> fftsize =
16384;
</p>
47 <p class=
"p6"><span class=
"Apple-tab-span"> </span>b =
<span class=
"s6">Buffer
</span>.alloc(s, fftsize)
</p>
50 <p class=
"p5"><br></p>
51 <p class=
"p5"><br></p>
53 <p class=
"p6">x = {
</p>
54 <p class=
"p7"><span class=
"s2"><span class=
"Apple-tab-span"> </span></span>// Any input should theoretically be OK, white noise is a good choice
</p>
55 <p class=
"p8"><span class=
"s2"><span class=
"Apple-tab-span"> </span></span>var
<span class=
"s2"> son =
</span>WhiteNoise
<span class=
"s2">.ar;
</span></p>
56 <p class=
"p7">//
<span class=
"Apple-tab-span"> </span>var son = Impulse.ar;
</p>
57 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"s7">var
</span> out =
<span class=
"s7">LPF
</span>.ar(son,
<span class=
"s7">MouseX
</span>.kr(
100,
10000,
1));
</p>
58 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"s7">var
</span> fft1 =
<span class=
"s7">FFT
</span>(
<span class=
"s7">LocalBuf
</span>(b.numFrames), son, wintype:
1);
</p>
59 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"s7">var
</span> fft2 =
<span class=
"s7">FFT
</span>(b, out, wintype:
1);
</p>
60 <p class=
"p5"><span class=
"Apple-tab-span"> </span></p>
61 <p class=
"p7"><span class=
"s2"><span class=
"Apple-tab-span"> </span></span>// As with most PV_ ugens, the result is *actually* stored in the first fft buf
</p>
62 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"s7">var
</span> result =
<span class=
"s7">PV_Div
</span>(fft2, fft1);
</p>
63 <p class=
"p5"><span class=
"Apple-tab-span"> </span></p>
64 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"s7">Out
</span>.ar(
0, out.dup *
0.1);
</p>
65 <p class=
"p6">}.play;
</p>
67 <p class=
"p9"><br></p>
68 <p class=
"p7">// Now we can grab the FFT buffer and peek at the magnitudes
</p>
70 <p class=
"p6">w =
<span class=
"s6">Window
</span>.new.front;
</p>
71 <p class=
"p6">t =
<span class=
"s6">Task
</span>{loop{
</p>
72 <p class=
"p6"><span class=
"Apple-tab-span"> </span>0.1.wait;
</p>
73 <p class=
"p6"><span class=
"Apple-tab-span"> </span>b.loadToFloatArray(action: {
<span class=
"s6">|data|
</span> {
</p>
74 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>w.view.children.do(
<span class=
"s6">_
</span>.remove);
</p>
75 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>w.refresh;
</p>
76 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>data[
2..].clump(
2)
</p>
77 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>.collect {
<span class=
"s6">|a|
</span> (a[
0].squared + a[
1].squared)}
</p>
78 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>.collect {
<span class=
"s6">|a|
</span> if(a.isNaN){
0.post }{ a } }
</p>
79 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>.plot(parent: w)
</p>
80 <p class=
"p6"><span class=
"Apple-tab-span"> </span>}.defer});
</p>
81 <p class=
"p6">}}.play;
</p>