rsc3/doc-schelp/HelpSource/Classes/Median.schelp

82 lines
1.6 KiB
Text

class:: Median
summary:: Median filter.
categories:: UGens>Filters>Nonlinear
Description::
Returns the median of the last length input points. This non-linear
filter is good at reducing impulse noise from a signal.
classmethods::
method::ar, kr
argument::length
Number of input points in which to find the median. Must be an
odd number from 1 to 31. If
code::length:: is 1
then Median has no effect.
argument::in
The input signal.
argument::mul
Output will be multiplied by this value.
argument::add
This value will be added to the output.
Examples::
code::
// a signal with impulse noise.
{ Saw.ar(500, 0.1) + Dust2.ar(100, 0.9) }.play;
// after applying median filter
{ Median.ar(3, Saw.ar(500, 0.1) + Dust2.ar(100, 0.9)) }.play;
// The median length can be increased for longer duration noise.
// a signal with longer impulse noise.
{ Saw.ar(500, 0.1) + LPZ1.ar(Dust2.ar(100, 0.9)) }.play;
// length 3 doesn't help here because the impulses are 2 samples long.
{ Median.ar(3, Saw.ar(500, 0.1) + LPZ1.ar(Dust2.ar(100, 0.9))) }.play;
// length 5 does better
{ Median.ar(5, Saw.ar(500, 0.1) + LPZ1.ar(Dust2.ar(100, 0.9))) }.play;
// long Median filters begin chopping off the peaks of the waveform
(
{
x = SinOsc.ar(1000, 0, 0.2);
[x, Median.ar(31, x)]
}.play;
)
// another noise reduction application:
Synth.play({ WhiteNoise.ar(0.1) + SinOsc.ar(800,0,0.1) });
// use Median filter for high frequency noise
Synth.play({ Median.ar(31, WhiteNoise.ar(0.1) + SinOsc.ar(800,0,0.1)) });
(
// use LeakDC for low frequency noise
Synth.play({
LeakDC.ar(Median.ar(31, WhiteNoise.ar(0.1) + SinOsc.ar(800,0,0.1)), 0.9)
});
)
::