electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links  |  Store
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » Clavia Nord Modular » Nord Modular G2 Discussion
Median of an array
Post new topic   Reply to topic Moderators: Nord Modular Editors
Page 1 of 1 [25 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
Moody33



Joined: Apr 28, 2009
Posts: 111
Location: France
G2 patch files: 16

PostPosted: Tue Oct 14, 2014 6:35 am    Post subject: Median of an array Reply with quote  Mark this post and the followings unread

Hi all.

I've build a median algorithm. It search for the median (median is not the mean values) between 3 values. I'd like to find an economic solution to find the median between 5, 7 or more values (and not the median of the median, this is possible by duplicated my initial algo in series). Any ideas? Here is my patch.

Thanks.


median.pch2
 Description:

Download
 Filename:  median.pch2
 Filesize:  1.42 KB
 Downloaded:  3562 Time(s)

Back to top
View user's profile Send private message
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 23178
Location: The Netherlands, Enschede
Audio files: 251
G2 patch files: 320

PostPosted: Tue Oct 14, 2014 1:30 pm    Post subject: Reply with quote  Mark this post and the followings unread

Sorry I have no idea as to how to do that for the G2 ... I think I would try the same approach as you used - figure out the selection with comparators .. but it gets large quickly with the sorting needed.

Anyway, I got curious as to what you would use the median calculation for .. just for filtering data, or for a direct musical result?

Just thought it might be interesting to, for example, filter a sequence through a median filter and get the result as a new VCO frequency .. for an extra voice related to but not equal to the sequenced voice ... I made a module for it for my softsynth to test that idea .. I like it Smile

_________________
Jan
also .. could someone please turn down the thermostat a bit.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
Moody33



Joined: Apr 28, 2009
Posts: 111
Location: France
G2 patch files: 16

PostPosted: Tue Oct 14, 2014 2:38 pm    Post subject: Reply with quote  Mark this post and the followings unread

Hi Blue Hell!

In fact, I often used the G2 as a game...So I built this for fun...But you can use the Median algo if you want to skip jump in values and keep the most important and redundant values ...This can be useful in many situation, especially in pitch tracking, but my algo is too short ( array of 3 values) for this application. Sorting the array is not really necessary since we just want the median. There is some article on the net related to fast median algo, but my brain can't deal with math stuff and english is not my native language... So if you are interested, you can take a look.
Back to top
View user's profile Send private message
Tim Kleinert



Joined: Mar 12, 2004
Posts: 1147
Location: Zürich, Switzerland
Audio files: 7
G2 patch files: 236

PostPosted: Tue Oct 14, 2014 2:41 pm    Post subject: Reply with quote  Mark this post and the followings unread

Use bubblesort approach with cascaded min/max modules (as described in the editor help section) and pick the middle value.
Back to top
View user's profile Send private message
Moody33



Joined: Apr 28, 2009
Posts: 111
Location: France
G2 patch files: 16

PostPosted: Tue Oct 14, 2014 2:56 pm    Post subject: Reply with quote  Mark this post and the followings unread

Good idea Tim, I will take a look. But bubblesort seems to be interesting for a few elements. I guess if a kind of recursive algo is possible to find the Median between more than 5 values?
Back to top
View user's profile Send private message
Tim Kleinert



Joined: Mar 12, 2004
Posts: 1147
Location: Zürich, Switzerland
Audio files: 7
G2 patch files: 236

PostPosted: Tue Oct 14, 2014 3:06 pm    Post subject: Reply with quote  Mark this post and the followings unread

Moody33 wrote:
I guess if a kind of recursive algo is possible to find the Median between more than 5 values?

Probably, but it won't update at the system rate (either control or audio) anymore, as every recursion will introduce one sample of delay.
Back to top
View user's profile Send private message
Moody33



Joined: Apr 28, 2009
Posts: 111
Location: France
G2 patch files: 16

PostPosted: Tue Oct 14, 2014 3:52 pm    Post subject: Reply with quote  Mark this post and the followings unread

Quote:
Probably, but it won't update at the system rate


This isn't a problem, any suggestions?
Back to top
View user's profile Send private message
Tim Kleinert



Joined: Mar 12, 2004
Posts: 1147
Location: Zürich, Switzerland
Audio files: 7
G2 patch files: 236

PostPosted: Wed Oct 15, 2014 7:15 am    Post subject: Reply with quote  Mark this post and the followings unread

I'm thinking about it. Mr. Green

(I have something on the workbench, but no guarantee yet if it will work.)
Back to top
View user's profile Send private message
Moody33



Joined: Apr 28, 2009
Posts: 111
Location: France
G2 patch files: 16

PostPosted: Wed Oct 15, 2014 8:37 am    Post subject: Reply with quote  Mark this post and the followings unread

Quote:
I'm thinking about it.


Yeah! Nice ! wave beer
Back to top
View user's profile Send private message
Tim Kleinert



Joined: Mar 12, 2004
Posts: 1147
Location: Zürich, Switzerland
Audio files: 7
G2 patch files: 236

PostPosted: Wed Oct 15, 2014 12:40 pm    Post subject: Reply with quote  Mark this post and the followings unread

*delete*
Last edited by Tim Kleinert on Wed Oct 15, 2014 1:46 pm; edited 1 time in total
Back to top
View user's profile Send private message
Moody33



Joined: Apr 28, 2009
Posts: 111
Location: France
G2 patch files: 16

PostPosted: Wed Oct 15, 2014 12:50 pm    Post subject: Reply with quote  Mark this post and the followings unread

Quote:
Here's a first viable approach for 7 values (expandable):


Thanks Tim, but it don't seems to work. I've set the 6 first value to 64 and -64, the 6th to 1 and if I tweak the 7th one, your patch seems to output the 7th value and not the median which is the 6th element. Confused
Back to top
View user's profile Send private message
Tim Kleinert



Joined: Mar 12, 2004
Posts: 1147
Location: Zürich, Switzerland
Audio files: 7
G2 patch files: 236

PostPosted: Wed Oct 15, 2014 1:08 pm    Post subject: Reply with quote  Mark this post and the followings unread

Thanks for testing it. You're right.

Guess I was too over-confident. Embarassed Laughing I deleted the building block thread.

I know what the mistake is. Don't know yet if I can fix it. Sorry.
Back to top
View user's profile Send private message
Tim Kleinert



Joined: Mar 12, 2004
Posts: 1147
Location: Zürich, Switzerland
Audio files: 7
G2 patch files: 236

PostPosted: Wed Oct 15, 2014 1:16 pm    Post subject: Reply with quote  Mark this post and the followings unread

I think I fixed it. Just needed another treacle-down stage.

Could you please test it again? I won't publish it in the building blocks section until it's 100% robust.

Thanks alot.

cheers

EDIT: It really seems to work now. But please be aware that if the inputted values are highly dynamic, the circuit might not always render the correct result because of the 1.666 ms update cycle. For dynamic input values, one has snap them to the circuit with a bank of S/H modules before the multiplexer, which are clocked by the counter reset pulse (the only yellow cable in the patch).

EDIT2: I added the required S/H bank described above. New version.

EDIT3: I miscalculated the refresh time too. It's way faster. 0.291ms, even at control rate.

EDIT4: As it works, I moved the patch to the building blocks section:
www.electro-music.com/forum/post-404322.html

EDIT5: A further understanding of the patch shows that there is no real benefit in terms of update accuracy by implementing the mentioned S/H stages, so I ditched them again.

Last edited by Tim Kleinert on Wed Oct 15, 2014 4:24 pm; edited 2 times in total
Back to top
View user's profile Send private message
Moody33



Joined: Apr 28, 2009
Posts: 111
Location: France
G2 patch files: 16

PostPosted: Wed Oct 15, 2014 2:23 pm    Post subject: Reply with quote  Mark this post and the followings unread

It seems to works perfectly! Very Happy

The amount of memory is quite high but I don't think we can build a more efficient method due to the amount of math required to get the median value.

Nice work Tim thanks
Back to top
View user's profile Send private message
Tim Kleinert



Joined: Mar 12, 2004
Posts: 1147
Location: Zürich, Switzerland
Audio files: 7
G2 patch files: 236

PostPosted: Wed Oct 15, 2014 2:30 pm    Post subject: Reply with quote  Mark this post and the followings unread

The update rate is quite fast (0.291 ms, 28 samples @ 96k or 7 samples at 24k) and if the input values aren't highly dynamic, and/or the result doesn't have to be absolutely 100% correct all the time, one can do away with the S/H modules and save some mem%.

Thanks too. This afternoon I didn't even know yet what a median was. This was fun. Smile
Back to top
View user's profile Send private message
Moody33



Joined: Apr 28, 2009
Posts: 111
Location: France
G2 patch files: 16

PostPosted: Wed Oct 15, 2014 4:20 pm    Post subject: Reply with quote  Mark this post and the followings unread

Quote:
Thanks too. This afternoon I didn't even know yet what a median was. This was fun


This could be very useful for your pitch tracking algo I guess, It could be efficient with more values, or perhaps with the median of the median? Wink
Back to top
View user's profile Send private message
Tim Kleinert



Joined: Mar 12, 2004
Posts: 1147
Location: Zürich, Switzerland
Audio files: 7
G2 patch files: 236

PostPosted: Wed Oct 15, 2014 4:26 pm    Post subject: Reply with quote  Mark this post and the followings unread

Moody33 wrote:
Quote:
Thanks too. This afternoon I didn't even know yet what a median was. This was fun


This could be very useful for your pitch tracking algo I guess, It could be efficient with more values, or perhaps with the median of the median? Wink

I know nothing about the relationship between median values and pitch-tracking. Embarassed Do you have any useful links?
Back to top
View user's profile Send private message
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 23178
Location: The Netherlands, Enschede
Audio files: 251
G2 patch files: 320

PostPosted: Wed Oct 15, 2014 4:40 pm    Post subject: Reply with quote  Mark this post and the followings unread

Tim,

The idea is that median filtering gets rid of unlikely values .. so when you have jittery signals the median usually is closer to the real value .. or the wanted value ... so .. for your pitch tracker it might make the output better for rapid pitch changes .. with less need of careful parameter setting.

_________________
Jan
also .. could someone please turn down the thermostat a bit.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
Moody33



Joined: Apr 28, 2009
Posts: 111
Location: France
G2 patch files: 16

PostPosted: Wed Oct 15, 2014 4:56 pm    Post subject: Reply with quote  Mark this post and the followings unread

No link sorry, but as I said to Blue Hell, the Median allow to skip jump in values and keep the most important and redundant values. I think the median value could avoid detection error during a pitch tracking, especially when the zero-cross counter jump to the second harmonic of the audio source which is often strong.
For example, the first harmonic is detected during 8 cycles and the second during 2 or 3 cycles before returning to the right pitch during 8 cycles again. If a median of 16 values is applied, those 2 or 3 cycles should be ignored. But if we apply a median of 3 values , those 2 or 3 cycles won't be ignored. Sorry for my bad english but I'm sure you understand what I mean...

This is just an idea!
Back to top
View user's profile Send private message
Moody33



Joined: Apr 28, 2009
Posts: 111
Location: France
G2 patch files: 16

PostPosted: Wed Oct 15, 2014 5:00 pm    Post subject: Reply with quote  Mark this post and the followings unread

Ooops, I've not seen Blue Hell's reply which is short but clear! Laughing
Back to top
View user's profile Send private message
Tim Kleinert



Joined: Mar 12, 2004
Posts: 1147
Location: Zürich, Switzerland
Audio files: 7
G2 patch files: 236

PostPosted: Thu Oct 16, 2014 12:42 am    Post subject: Reply with quote  Mark this post and the followings unread

Guys, this is fascinating stuff! Thanks so much for your explanations.

I didn't think of feeding the circuit with a moving window of data. Although, now that I think back to your patch Moody33, it was in front of my eyes (the shift register). doh Laughing

I'll need some time to ponder the deeper possibilities of this kind of data processing.

cheers,
t
Back to top
View user's profile Send private message
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 23178
Location: The Netherlands, Enschede
Audio files: 251
G2 patch files: 320

PostPosted: Thu Oct 16, 2014 2:54 am    Post subject: Reply with quote  Mark this post and the followings unread

I experimented a bit, short running median filtering is nice for generating a 2nd sequenced line from the main sequence.

It depends a bit on the sequence length what still is useful for the median queue size (for this purpose).

I used values from 3 .. 11 sofar with a sequence of 14 steps (in which a note gets changed every now and then). Should be nice on totally random note sequences too.

_________________
Jan
also .. could someone please turn down the thermostat a bit.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
Moody33



Joined: Apr 28, 2009
Posts: 111
Location: France
G2 patch files: 16

PostPosted: Thu Oct 16, 2014 4:17 am    Post subject: Reply with quote  Mark this post and the followings unread

Blue Hell,

I've also experiment this approach ( and my patch illustrated quickly this idea ) but, to my ears it generates harmonics conflict. It's often better to pitch up the second line to avoid minor/major 2nd relation. And finally , the idea is quite similar to a delay line, but the delay line effect is much better logical for our ear in my opinion.
Back to top
View user's profile Send private message
Moody33



Joined: Apr 28, 2009
Posts: 111
Location: France
G2 patch files: 16

PostPosted: Thu Oct 16, 2014 5:05 am    Post subject: Reply with quote  Mark this post and the followings unread

Here an article about fast median algo with schematics using gates and shift register :
http://www.uio.no/studier/emner/matnat/ifi/INF2310/v12/undervisningsmateriale/artikler/Danielsson-median.pdf

Simply chinese for me Embarassed
Back to top
View user's profile Send private message
Tim Kleinert



Joined: Mar 12, 2004
Posts: 1147
Location: Zürich, Switzerland
Audio files: 7
G2 patch files: 236

PostPosted: Thu Oct 16, 2014 6:42 am    Post subject: Reply with quote  Mark this post and the followings unread

Moody33 wrote:
Here an article about fast median algo with schematics using gates and shift register :
http://www.uio.no/studier/emner/matnat/ifi/INF2310/v12/undervisningsmateriale/artikler/Danielsson-median.pdf

Simply chinese for me Embarassed

"For those from Missouri..." is my favourite line in there.

But yeah, it does look nasty. Twisted Evil

Maybe I'm from Missouri too. Shocked Laughing
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: Nord Modular Editors
Page 1 of 1 [25 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » Clavia Nord Modular » Nord Modular G2 Discussion
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
e-m mkii

Please support our site. If you click through and buy from
our affiliate partners, we earn a small commission.


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use