Selection of Modes by Energy
selectModesEnergy.RdOrders the modes by decreasing energy and selects those before the largest drop between consecutive energies.
Details
The energy of mode \(k\) is \(P_k = \sum_n c_k[n]^2\). With the permutation \(\pi\) that orders the energies decreasingly, the selection keeps \(\pi(1), \ldots, \pi(v)\) with $$v = \arg\max_{1 \le m < K} \left(P_{\pi(m)} - P_{\pi(m+1)}\right).$$ The source fixes no tie-break, so a largest drop that is zero or not unique stops the function with an error.