&gt; So, why is a mean (average) not good enough, while a median would be good enough ?<div>&gt; It&#39;s possible, but I&#39;d like to hear an explanation.<br><br></div><div>I&#39;d need to test and compare, all I know is that I tested [avg~] and compared it to sethares&#39; objects in MAX, that do this median filter, and they seem to sound better over there.</div>
<div><br></div><div>But these objects (GNU General Public License v2.0) are actually codes in java, </div><div><br></div><div><div><span class="Apple-tab-span" style="white-space:pre">                </span>for(int i=0; i&lt;framesize; i++) {<span class="Apple-tab-span" style="white-space:pre">        </span>// set the output magnitude by</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>if(i % medlen == 0){<span class="Apple-tab-span" style="white-space:pre">                        </span>// taking moving median of input</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>for(int ij=0; ij&lt;medlen; ij++) {<span class="Apple-tab-span" style="white-space:pre">                        </span>// this takes median</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                        </span>thesevals[ij] = magformed[i+ij];<span class="Apple-tab-span" style="white-space:pre">                </span>// of medlen elements</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>noisefloor[i] = (float)(Statistics.median(thesevals));</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>} else {<span class="Apple-tab-span" style="white-space:pre">                                                </span>// advance median by medlen steps</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>noisefloor[i] = noisefloor[i-1];<span class="Apple-tab-span" style="white-space:pre">        </span>// keeping same value</div></div><div><br></div><div><br><div class="gmail_quote">
2011/12/22 Mathieu Bouchard <span dir="ltr">&lt;<a href="mailto:matju@artengine.ca">matju@artengine.ca</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Le 2011-12-20 à 21:29:00, Alexandre Torres Porres a écrit :<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
this would be kinda like using the [median] or [median_n] objects, but over audio blocks and not number lists.<br>
</blockquote>
<br></div>
Ok, lots of heavy details below...<br>
<br>
The way [median] and [median_n] are built, they take a lot of time. Sorting each window of 32 elements is slow with any full sort. Even the usually slow process of putting elements one by one in a sorted array is faster than any full sort like qsort() or [sort], in this kind of situation, because you need to look at the result of the sort after each insertion/removal.<br>

<br>
But a sort based on binary-trees will make your median filter able to compete with the speed of FFT, for example. You keep your sorted «array» as a sorted binary tree and this makes it fast to insert, delete, and find the middle. But you can&#39;t do that with C++&#39;s std::map because it offers no way to find the middle quickly... you&#39;d need something special.<br>

<br>
There may be ways to bend quicksort so that it can do many similar sorts quickly, but you can&#39;t do that with qsort() nor anything based on it.<br>
<br>
I don&#39;t know how zexy&#39;s [sort]. Apparently it doesn&#39;t use the quicksort method that I assumed it did, it uses the shellsort method instead, which is sometimes slower, sometimes faster. I wonder whether it could speed up your task if you made a kind of [median_n] that would reuse the already-sorted list to speed up the next sort. (This would not improve a quicksort, but I wonder whether it&#39;d improve [sort]).<br>

<br>
Generally, median-based methods are harder to work with, as they involve lots of comparisons and swaps and such, by sorting or by doing things that are like sorting ; whereas mean-based methods involve simple fast passes of addition and multiplication. But both give quite different results, in many situations.<div class="im">
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Since there&#39;s the need of calculating this in and using the result back in the same block round into the audio chain, I can&#39;t put the spectrum into a table, and then calculate the median over bits of it.<br>
</blockquote>
<br></div>
with [tabsend~] and a [bang~], then you can send a whole block into the message domain, compute it, and get it back as a signal, one block later.<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
But then, how to do it? Should I be able to pull this out only if I write a &quot;median~&quot; or [noise_floor~] external?<br>
<br>
Or somehow there&#39;s another way to do this with some existing external, or a similar technique, or even some audio math trick using [fexpr~] or something?<br>
</blockquote>
<br></div>
I don&#39;t think you can do any reasonable sort using [fexpr~]... except perhaps a strange undecipherable network of a hundred [fexpr~] or so. I think it&#39;s easier to write an external.<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
This has to do with the other post I did about a project that attempts to isolate notes into a chord in a spectrum, something like melodyne is does.<br>
</blockquote>
<br></div>
So, why is a mean (average) not good enough, while a median would be good enough ? It&#39;s possible, but I&#39;d like to hear an explanation.<br>
<br>
 ______________________________<u></u>______________________________<u></u>__________<span class="HOEnZb"><font color="#888888"><br>
| Mathieu BOUCHARD ----- téléphone : <a href="tel:%2B1.514.383.3801" value="+15143833801" target="_blank">+1.514.383.3801</a> ----- Montréal, QC</font></span></blockquote></div><br></div>