2 summary:: Find a percentile of FFT magnitude spectrum
4 related:: Classes/SpecCentroid, Classes/SpecFlatness
7 Given an link::Classes/FFT:: chain this calculates the cumulative distribution of the frequency spectrum, and outputs the frequency value which corresponds to the desired percentile.
9 For example, to find the frequency at which 90% of the spectral energy lies below that frequency, you want the 90-percentile, which means the value of emphasis::fraction:: should be 0.9. The 90-percentile or 95-percentile is often used as a measure of strong::spectral roll-off::.
11 The optional third argument strong::interpolate:: specifies whether interpolation should be used to try and make the percentile frequency estimate more accurate, at the cost of a little higher CPU usage. Set it to 1 to enable this.
17 an link::Classes/FFT:: chain.
19 argument:: interpolate
24 s = Server.internal.boot;
25 b = Buffer.alloc(s,2048,1);
27 // Simple demo with filtering white noise, and trying to infer the cutoff freq.
31 var in, chain, realcutoff, estcutoff;
32 realcutoff = MouseX.kr(0.00001,22050);
33 in = LPF.ar(WhiteNoise.ar, realcutoff);
35 estcutoff = Lag.kr(SpecPcile.kr(chain, 0.9), 1);
36 realcutoff.poll(Impulse.kr(1), "real cutoff");
37 estcutoff.poll(Impulse.kr(1), "estimated cutoff");
39 Out.kr(0, estcutoff * 22050.0.reciprocal);
43 // Audio input - try different vowel/long-consonant sounds and see what comes out.
44 // Specifically, change from "ssss" through to "aaaa" through to "wwww".
48 in = SoundIn.ar([0,1]).mean;
50 //Out.ar(0, in * 0.1);
51 perc = SpecPcile.kr(chain, 0.5);
52 Out.ar(1, LPF.ar(WhiteNoise.ar, perc)); //NB Outputting to right channel - handy on PowerBooks
53 Out.kr(0, perc * 22050.0.reciprocal);