Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

Maximum value from mem buffer?

DSP related issues, mathematics, processing and techniques

Maximum value from mem buffer?

Postby Youlean » Wed Dec 10, 2014 4:45 pm

Is there any way to get maximum value from a mem buffer with stream connection (not green)?

I need to find max value from 1024 buffer, and so far I made it with stacking one sample delays, but CPU usage is insane...
Youlean
 
Posts: 176
Joined: Mon Jun 09, 2014 2:49 pm

Re: Maximum value from mem buffer?

Postby KG_is_back » Wed Dec 10, 2014 6:53 pm

Connect the buffer to wave read prim with index counter and connect that to this:

Code: Select all
streamin in;
streamout out;
out=max(out,in);


connect that to analyzer prim, and read the last value from the output float array (the number of values to process should be equal to the size of the buffer).

Alternatively you can use memin input and put the index counter into the code block dirrectly.
KG_is_back
 
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Maximum value from mem buffer?

Postby Youlean » Wed Dec 10, 2014 8:01 pm

Well, I don't think that this will work...

I need to get new max value every sample from 32 samples buffer.
Is this possible with ASM, or ruby?

BTW, thanks KG for helping me out...
Youlean
 
Posts: 176
Joined: Mon Jun 09, 2014 2:49 pm

Re: Maximum value from mem buffer?

Postby KG_is_back » Wed Dec 10, 2014 11:24 pm

it is possible with code component using loop if the buffer is array

Code: Select all
c=0;
maximum=0;
loop(32){
maximum=max(maximum,array[c]);
c=c+1;
}
KG_is_back
 
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Maximum value from mem buffer?

Postby Youlean » Wed Dec 10, 2014 11:55 pm

KG_is_back wrote:it is possible with code component using loop if the buffer is array

Code: Select all
c=0;
maximum=0;
loop(32){
maximum=max(maximum,array[c]);
c=c+1;
}


Sorry KG, but can you write the whole code, I don't understand how to implement this... :(
Youlean
 
Posts: 176
Joined: Mon Jun 09, 2014 2:49 pm

Re: Maximum value from mem buffer?

Postby KG_is_back » Thu Dec 11, 2014 12:15 am

Oh sorry, I think I'm missing the point. So there is something happening with the buffer (you are writing to it at some place in the schematic using write mem prim or asm) in every sample and each time you then want to find the maximum value in that buffer each time, every sample. Is that right?
KG_is_back
 
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Maximum value from mem buffer?

Postby Youlean » Thu Dec 11, 2014 12:49 am

KG_is_back wrote:Oh sorry, I think I'm missing the point. So there is something happening with the buffer (you are writing to it at some place in the schematic using write mem prim or asm) in every sample and each time you then want to find the maximum value in that buffer each time, every sample. Is that right?

Yes.
Youlean
 
Posts: 176
Joined: Mon Jun 09, 2014 2:49 pm

Re: Maximum value from mem buffer?

Postby KG_is_back » Thu Dec 11, 2014 1:10 am

Ok! that needs ASM to work. This should do it...
Attachments
memMax.fsm
(1.09 KiB) Downloaded 1243 times
KG_is_back
 
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Maximum value from mem buffer?

Postby Youlean » Fri Dec 12, 2014 5:52 pm

Sorry for late response..

Thanks a lot, but this is not what I am looking for...

I am looking for something that will emulate "finding max from 16 samples" in my example with much less CPU usage.

Hold max custom amount of samples will not work here, as it is slightly different from finding max from 16 samples...

BTW, is there a way to have really optimized fixed delay (that will delay signal for fixed amount of time). To be low on CPU as one sample delay?

Thanks!
Attachments
Max From Array.fsm
(20.33 KiB) Downloaded 1208 times
Youlean
 
Posts: 176
Joined: Mon Jun 09, 2014 2:49 pm

Re: Maximum value from mem buffer?

Postby KG_is_back » Fri Dec 12, 2014 10:16 pm

Oh, now I get it... this can be done in code component:

Code: Select all
streamin in;
streamout out;
float buf[16];
float c,d;

buf[d]=in;
d=d+1;
d=d&(d<16);
c=0;
out=0;
loop(16){
out=max(out,buf[c]);
c=c+1;
}

It can be optimized in assembly, but the functionality is there...

As for the delay:


Code: Select all
streamin in;
streamout out;

int c=0;
float mem[1024]; //this can be of any size

mov eax,c[0];
add eax,-16;
and eax,16 383; //looping mask - this will force "c" to cycle in 0-16383 range. Works only with powers of two minus one
mov c[0],eax;

movaps xmm0,in;
movaps mem[eax],xmm0;
add eax,{delay*16};
and eax,16 383;
movaps xmm0,mem[eax];
movaps out,xmm0;

This should be the most efficient way to do the fixed delay. Just copy-pase this code into assembler and insert your desired delay multiplied by 16 on the spot "{delay*16}" I have made the buffer fairly big, you may opt to use smaller buffers (it will not make much difference though) if you want - in that case replace every "and eax,16 383;" with 16*buffersize.
You may even easily modify it, to output multiple delays of the input. Simply copy-paste last four lines multiple times - keep in mind the delays will be differential (every next computed delay is computed from the position of the previous one)
Last edited by KG_is_back on Fri Dec 12, 2014 11:30 pm, edited 1 time in total.
KG_is_back
 
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Next

Return to DSP

Who is online

Users browsing this forum: No registered users and 14 guests