rsc3/doc-schelp/HelpSource/Classes/PV_Div.scrbl

70 lines
1.4 KiB
Racket

#lang scribble/manual
@(require (for-label racket))
@title{PV_Div}
Complex division@section{categories}
UGens>FFT
@section{related}
Classes/PV_Mul, Classes/PV_MagDiv
@section{classmethods}
@section{method}
new
@section{argument}
bufferA
fft buffer A.
@section{argument}
bufferB
fft buffer B.
@section{Examples}
In this example we estimate the transfer function of the LPF 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.
@racketblock[
(
s.waitForBoot({
var fftsize = 16384;
b = Buffer.alloc(s, fftsize)
})
);
(
x = {
// Any input should theoretically be OK, white noise is a good choice
var son = WhiteNoise.ar;
// var son = Impulse.ar;
var out = LPF.ar(son, MouseX.kr(100, 10000, 1));
var fft1 = FFT(LocalBuf(b.numFrames), son, wintype: 1);
var fft2 = FFT(b, out, wintype: 1);
// As with most PV_ ugens, the result is *actually* stored in the first fft buf
var result = PV_Div(fft2, fft1);
Out.ar(0, out.dup * 0.1);
}.play;
)
// Now we can grab the FFT buffer and peek at the magnitudes
(
w = Window.new.front;
t = Task{loop{
0.1.wait;
b.loadToFloatArray(action: {|data| {
w.view.children.do(_.remove);
w.refresh;
data[2..].clump(2)
.collect {|a| (a[0].squared + a[1].squared)}
.collect {|a| if(a.isNaN){ 0.post }{ a } }
.plot(parent: w)
}.defer});
}}.play;
)
::
]