How to pick the 7 peak (more repeated) numbers among a group of hertz value.

berane9's icon

berane9

10月 13 2024 | 9:29 午後

  1. I want to pick the most repeated, relevant, or peak numbers from a group of about 140 numbers, where the respective distance among the values be about 10 consecutive numbers.

  2. After obtaining the 7 or 10 relevant numbers, how will I set the list of groups be changed to these relevant numbers (to the 7 or 10 numbers)? Change all the numbers and be substituted by the relevant chosen numbers.

  3. Here are some sample numbers: 1st is the index, 2nd is the time measure, 3rd is the value of a note. The interesting value numbers are the hertz value numbers, according to the 3rd colon in the list.

Source Audio's icon

Source Audio

10月 14 2024 | 7:46 午前

I don't really understand what you want to do,

but look into zl objects and maybe coll.

Sébastien Gay's icon

Sébastien Gay

10月 14 2024 | 2:07 午後

This patch extracts the 7 most frequent values, in decreasing order, out of a list of 140 numbers (Edited):

Max Patch
Copy patch and select New From Clipboard in Max.

berane9's icon

berane9

10月 14 2024 | 3:37 午後

Dear Sebastien,

I appreciate your input; the file you sent me will greatly help me.

I wish I could talk to you about a similar issue.

With kind regards.

Berhane

berane9's icon

berane9

10月 14 2024 | 6:34 午後

Dear Sebastien,

The first issue is solved. This means that the more repeated numbers are found. I will take them as having seven notes of music scale, of course, they are a little different from the European style. But I am interested in the algorithm process.

The second issue is to change all those numbers into the 7 relevant, more repeated numbers. How can I tell the computer to change all the available numbers in the basket, that is different from the 7 notes be changed into the new note or code. Therefore any number that is very close to the 7 note be assigned one from the 7 notes. Any different that the 7 number should stick with the available 7 notes only.

I appreciate your input. Berhane

Sébastien Gay's icon

Sébastien Gay

10月 14 2024 | 7:42 午後

Berhane, could you provide real concret examples of what you want to do ? It may be easier for me (and others) to understand what you want to do with those numbers.

Source Audio's icon

Source Audio

10月 15 2024 | 8:04 午前

you talk about Hz, means you have audio recording ?

And try to notate it using diatonic scale ?

After retuning notes ?

look into ftom

berane9's icon

berane9

10月 15 2024 | 6:28 午後

Dear Sèbastien,

Thanks for your quick reply.

I thought you had some helpful and further support from your part or someone you know. I would like to have someone to help me out on this issue, even with decent pay.

Thanks for asking, anyway, Berhane

Sébastien Gay's icon

Sébastien Gay

10月 15 2024 | 6:59 午後

Hey Berane. I wasn't available today. Did you delete your last post ? I'm still trying to figure out what you concretely want to do.

As suggested by Source Audio, [ftom] can convert frequencies into midi notes values. Like this for instance (where [fzero~] calculates the fundamental frequency of each note received from the audio source ) :

Max Patch
Copy patch and select New From Clipboard in Max.

I dont't know it really helps ....

Roman Thilenius's icon

Roman Thilenius

10月 16 2024 | 4:03 午前

if you want to find the most frequent identical list elements, and you want to avoid comparing each against each, the first thing you should do is to sort the list.

berane9's icon

berane9

10月 16 2024 | 9:22 午前

Thanks dear Roman, Berhane

berane9's icon

berane9

10月 19 2024 | 12:29 午前

Dear forum,

How can I compile a group of numbers with too many short gups? I want to order all of them according to the scales, set them in 5 or 7 chosen numbers, or use a scale of notes. Here are samples of data with a relative scale.

Here is the data:

187 187 187 132 141 141 141 162 168 168 207 213 210 189 165 174 216 222 216 222 216 225 213 207 207 168 171 207 210 150 138 150 153 171 207 174 168 177 186 186 141 171 171 207 213 225 216 219 228 225 213 171 168 174 216 225 228 216 231 177 177 177

And here is the scale: 108 132 150 168 207.

The data should be replaced according to the scale, so the numbers should turn up and down to match with the scale.

Thanks, Berhane

Roman Thilenius's icon

Roman Thilenius

10月 19 2024 | 1:59 午前

you want to quantize Set A to Set B?

(this is not answer, this is question)

Wil's icon

Wil

10月 19 2024 | 3:15 午前

like this what you want?

Max Patch
Copy patch and select New From Clipboard in Max.

***there is no 108 in your first long list


Wil's icon

Wil

10月 19 2024 | 3:37 午前

this one map the first list to list 2

Max Patch
Copy patch and select New From Clipboard in Max.




berane9's icon

berane9

10月 19 2024 | 10:27 午前

Dear Wil,

I checked the results, but the reply seems to be the same as the list printed on the scale.

According to me, the given lists should be replaced by a number that exists in the list of the scale. Therefore all the available lists should be replaced by a value that exists in the scale, which means any list different than the scale should adjusted to a very close number on the scale. The solution should include all numbers in the list, and not be sorted for I need to follow up the existing list of order.

For example, the solution of the list above should be replaced as the following. Here is a sample solution of the above list that I should get:

168. 168. 168. 132. 132. 132. 132. 168. 168. 168. 207. 207. 207. 168. 168. 207. 207. 168. 168. 207. 207. 150. 132. 150. 150. 168. 207. 168. 168. 168. 168. 168. 132. 168. 168. 207. 168. 168. 168. 168. 168. 168.

Wil's icon

Wil

10月 19 2024 | 10:37 午前

Ok.

You want to swap the scale into each closest number on the larger list. I Understand.

This:

187 187 187 132 141 141 141 162 168 168 207 213 210 189 165 174 216 222 216 222 216 225 213 207 207 168 171 207 210 150 138 150 153 171 207 174 168 177 186 186 141 171 171 207 213 225 216 219 228 225 213 171 168 174 216 225 228 216 231 177 177 177

Replace each number with closest from this:

108 132 150 168 207.

187 becomes 168 (three in a row) then 132 stays 132, then 141 becomes 132 etc..

That would be what Roman said- quantize

Sébastien Gay's icon

Sébastien Gay

10月 19 2024 | 11:20 午前

Quick&dirty ;-) ?

Max Patch
Copy patch and select New From Clipboard in Max.
Wil's icon

Wil

10月 19 2024 | 12:10 午後

SÉBASTIEN GAY nice and dirty!

I really want to figure out a dynamic version - been looking for a way to do dynamic multisplit for my own work :0

berane9's icon

berane9

10月 19 2024 | 12:18 午後

Dear Sebastien,

exactly, this outcome is the correct answer I need it.

If I can, I would like to know if there is a short wys to get the same output. Or if there is a formula that can be built the outcome that comes from the split. I mean a mathematical formula that solves the algorithms of the "split" object.

Thanks for the solution, and for your quick reply dear. Berhane

Roman Thilenius's icon

Roman Thilenius

10月 19 2024 | 12:53 午後

yeah, he wants to-nearest, which makes it tricky. i have something like that, but will not post it because with my old version of max such things are getting really huge.

i´d start similar to sebastien:
- iter Set B into groups of 2 elements
- find the mean of these pairs (the split point)
- check the incoming values from Set A for >, == or < against all those mean values of Set B
- route the result to three different directions / let pass or not, aka dynamic mapping. (if not passed, try next mean value until you find a match)

Roman Thilenius's icon

Roman Thilenius

10月 19 2024 | 12:56 午後

>> I mean a mathematical formula that solves the algorithms of the "split" object.

i don´t think there is such a solution, but you might try to use generic iteration/forloop methods or poly~.

otoh it should be ok to limit it to 80 or so serial split objects.

if you have somewhat experience with vexpr this can also help to make that patch shorter.

Source Audio's icon

Source Audio

10月 19 2024 | 1:53 午後

Wil's icon

Wil

10月 19 2024 | 3:07 午後

Just waiting for SOURCE AUDIO :0

thanks - will reverse engineer this for later

Source Audio's icon

Source Audio

10月 19 2024 | 3:35 午後

here is the patch

Max Patch
Copy patch and select New From Clipboard in Max.

berane9's icon

berane9

10月 19 2024 | 4:22 午後

Here is the source code, dear Wil:

Nisgid-1of3.wav

Roman Thilenius's icon

Roman Thilenius

10月 19 2024 | 4:32 午後

good stuff, much shorter than mine. how would you add round-up to yours?

berane9's icon

berane9

10月 19 2024 | 4:42 午後

Dear Source Audio,

the last patch is done perfectly, the one I dreamed about. I find it very efficient to resolve a very complicated scale issues. Thanks so much

Wil's icon

Wil

10月 20 2024 | 1:21 午前

Good to try to understand what happening

for using later


Source Audio's icon

Source Audio

10月 20 2024 | 9:51 午前

@Roman

do you mean to snap to higher of 2 closest matches ?

if value is 111 and list to snap is 100 150 200, then 150.

if 99 then 100

if 151 then 200

if 3000 then 200

maybe like this

Max Patch
Copy patch and select New From Clipboard in Max.

Roman Thilenius's icon

Roman Thilenius

10月 20 2024 | 1:04 午後

i havent tried yet but i just thought of a solution: one could simply invert the values of both sets to round into the other direction. but i do not get it to work.

if value is 111 and list to snap is 100 150 200, then 150.

nono - but that would also be an interesting mode. ("truncate"?)

i mean just rounding in both directions when a value is exactly between the values from Set B, like 15 vs. 10/20

expected result for round-up mode: 20 20

(if we are sure that input is int-only, we could do + 0.1 (or + 1), but that seems unelegant.)

Source Audio's icon

Source Audio

10月 20 2024 | 2:36 午後

Ok, I see.

about simplest solution - adding 0.1 or 1.

would be ok in this case, as I don't think values

to quantize to would be so close to make a difference if input would be higher that little.

complicated solution is to check if sorted list has more than 1 "winner"

and if yes than retreive 2 values and pick higher one.

Source Audio's icon

Source Audio

10月 20 2024 | 3:17 午後

Max Patch
Copy patch and select New From Clipboard in Max.

in case input is exactly in between 2 quantize values, result has 2 indentical values.

that 2 values get sorted and higher one picked.

Wil's icon

Wil

10月 20 2024 | 3:29 午後

i mean just rounding in both directions when a value is exactly between the values from Set B, like 15 vs. 10/20

I too need this solution rounding pitch frequency when playing bass - slightly out of tune, vibrato etc.

Kind of like pitch detection, but instead finding the distance between each pitch and map the nearest correct pitch

Pitch frequencies get further apart as they get higher

But instead of sending a list to quantize. Just need to quantize individual frequencies

In some sense this might also work to quantize motion sensor distances

Also I can use bass to play synths along with the bass! - really good for ear training

Source Audio's icon

Source Audio

10月 20 2024 | 3:41 午後

for pitch in between, it is enough to use mtof and mtof 0.

get float difference, and snap up or down depending on closer match.

Roman Thilenius's icon

Roman Thilenius

10月 20 2024 | 3:41 午後

when i think about it, this application/problem basically only exists for the int-mode of a quantize Set A to Set B patch, isn´t it?

so eventually +1 would be good to go already.

(image shows the result from when mode 1 was turned on)

Roman Thilenius's icon

Roman Thilenius

10月 20 2024 | 3:48 午後

silently moving the offset to Set B

berane9's icon

berane9

10月 20 2024 | 11:07 午後

Dear Forum People, I appreciated all the effort made to best solve the question. The addition of using a decimal place also collaborated to finish up optimal evaluation.

Thanks, Berhane

Source Audio's icon

Source Audio

10月 21 2024 | 7:26 午前

@ Berhane - You are welcome !

@ Roman - that is good one with switch to round up.

P.S.

I forgot about zl.lookup in my first patches, it is easier to deal with then with zl.mth & zl.reg.

berane9's icon

berane9

10月 21 2024 | 3:47 午後

Dear Source Audio,

I liked the observation made on your comment.

About the zl.lookup & zl.reg is interesting point. If your know where to refer to get better explanation would be good, beside the reduced info edited in the documentations.

While the zl.mth issue is about the starting point with zero.

I appreciated your input. Berhane

Source Audio's icon

Source Audio

10月 22 2024 | 11:05 午前

if you want to know more about zl objects see their help file and reference.

In this case zl.lookup serves the same as combination of zl.reg and zl.mth.

so zl.lookup is better because only 1 object is used.

zl.lookup was not part of zl objects in max 4 - max version I spend most time with.

and even that it is kind of obsolete since many years, I still refer to it in my mind.

berane9's icon

berane9

10月 22 2024 | 5:08 午後

Dear Source Audio,

Thanks for the illustration sent recently. I greatly appreciated it. Berhane

Roman Thilenius's icon

Roman Thilenius

10月 22 2024 | 7:02 午後

zl.lookup was not part of zl objects in max 4 - max version I spend most time with.

OT: luckily i got at least working solutions for @scalarmode and .sort in v.4. :)

berane9's icon

berane9

10月 22 2024 | 10:33 午後

Dear Roman,

[silently moving the offset to Set B]

the above patch wwritten before the last one doesn't work properly. It didn't work out for me, and the true value comes always 0. Can you check that algorithm please? Thanks, Berhane