Page 1 of 2

multiple peak finding in array

Posted: Mon Jun 03, 2013 12:36 am
by tester
Let say that I have a large array of floats (FFT?). How to find multiple peaks within it?

I guess, the procedure would have to compare each value with it's preceding and succeeding neighbours, to determine, whether it's a peak or not. (or it should be done in different way than dealing with 3 points?).

I guess, there could be some rule, to ignore results if both differences (N to N-1 and N to N+1) are small, within some range. (both sides would have to be in-signifficant). (FFT would be smoothed via Hanning window before it goes to analysis).

I gues, there can be some threshold set, to ignore all values below certain level. (noise trafic, vertical range).

I guess there could be some index limiter, to set the desired FFT range of freqs (horizontal range) for analysis. (i.e. even if array is large, let say, you wish to find peaks within A=230 to B=3000 range).

I guess, it can be easilty done with loops, but it will probably work horribly slow for larger array (128k array?).

But that's all i can guess, maybe I'm missing something.

Could someone make such multiple peak finding in ruby?

MyCo? Trog?
MyCo my Hero? ;-)

Re: multiple peak finding in array

Posted: Mon Jun 03, 2013 12:58 am
by RJHollins
Hi tester,

You're on another interesting mission I see :lol:

Your mention of 'multiple peaks' suggests a more involved solution no doubt.

Without knowing all possible conditions ... you'd have a situation where each sample 'level' would need to be ranked and marked. [so it would seem].

I think there is a prim function that identifies a MAX value in the Array. If not mistaken, it would only give a single result. If this is so ... you could, using a temp array, remove the MAX'd value from the list and then rescan for the remaining MAX value, remove and repeat. Does not seem a very efficient method though.

Is it possible to do an Array 'Sort' by level ? This could possibly organize the array from highest to low. The INDEX number would identify its true position in the original array. Then a type of 'threshold' could be declared to list out the top values now at the start of the list.

Hey ... I know, just a crazy idea. And there's more where that came from :shock:
:lol:

I'll spare the reader until you solve it, or maybe explain more what you're needing to do.

Re: multiple peak finding in array

Posted: Mon Jun 03, 2013 1:30 am
by tester
"Max" prim will find only one peak.

Depending on project, but let say I example this one. Even if I narrow the index range - I still will have around 6-10 peaks to find per range.

As for sorting - it can't work that way, because data are ascending/descending with peak points between. If I sort data, then several lower peaks will disappear within other asc/desc floats, related to higher peaks.

Keep in mind, that these are not digital data. Sonic and other types of spectra.

...which gives me to think about this "smoothing" during analysis. May not work as I thought? :-) I'm trying to imagine a little bit distorted slope vs gentle mountain with semi-flat top...

*

It's not another mission, it's one of the first ones. :-)
I needed to take a break from "tuned" randomizer I'm finishing for my app (drives me crazy a little bit).

Re: multiple peak finding in array

Posted: Mon Jun 03, 2013 1:39 am
by RJHollins
If the MAX would identify the 'largest' value, then that would be a starting point to determine a threshold maybe.
A 'range' below that threshold could then set the condition to compare each sample against.

But from what I'm gasping ... the sample data may not fit the criterion I'm thinking on ...

Just trying to stir the thoughts :)

Re: multiple peak finding in array

Posted: Mon Jun 03, 2013 1:45 am
by tester
Nope. In mentioned above example - peaks tend to go in singles or pairs or triples or quads with very narrow differences between.

Remember when I asked fro high resolution FFT? Trog made one with 128kpts resolution with ruby, and Martin did his excellent work on SM forum for small ranges (unfortunately I was not able to extend it to ~50Hz range without crashing FS). The destination is to get peak freqs for further analysis/processing (microtuning, resonances and stuff like that).

Besides as I said - dealing with it via loops - will be probably much slower than pushing it through ruby.

Re: multiple peak finding in array

Posted: Mon Jun 03, 2013 1:56 am
by RJHollins
I understand better about the peak nature ... very common for transient peaks to cluster.

But you mention 'other' peaks that could exist in lower signal levels ??? That's what confused me.

So, you are not looking to just identify the highest peak values in a sample. It sounds like you want to track the 'internal 'dynamics as well. I'm still guessing about this.

Is this something like a 'envelope tracker' with a dynamic sensitive 'auto' threshold ?

Re: multiple peak finding in array

Posted: Mon Jun 03, 2013 2:00 am
by tester
Nope, it's for my small research.

Re: multiple peak finding in array

Posted: Mon Jun 03, 2013 9:11 am
by MyCo
I accept PayPal :mrgreen:

Re: multiple peak finding in array

Posted: Mon Jun 03, 2013 1:21 pm
by tester
MyCo wrote:I accept PayPal :mrgreen:


I guess we have something in common :mrgreen:

Thanks.

One small thing. "Threshold" node seems to be set for something else or not work. See on attached array example. Threshold should "cut" some values from analysis.

Now - because these are relative decibels in regards to "zero on top", threshold should elliminate from analysis all values below certain level. For examle, the total range is more than -170dB, but I would like to cut out from analysis all values below -60dB. Everything above -60dB would matter here.

How?

Re: multiple peak finding in array

Posted: Mon Jun 03, 2013 2:07 pm
by MyCo
...