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
Calculating dB; Broken DSP?
11 posts
• Page 1 of 2 • 1, 2
Calculating dB; Broken DSP?
- Code: Select all
streamin x;
streamout out;
out = 20*log10(x);
Why does this DSP code output "400" and only "400"?
- Perfect Human Interface
- Posts: 643
- Joined: Sun Mar 10, 2013 7:32 pm
Re: Calculating dB; Broken DSP?
because x needs to be multiplied with 20 before you do log10
so it should be :
so it should be :
- Code: Select all
out=log10(20*x);
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
Re: Calculating dB; Broken DSP?
Nubeat7 - are you sure?
It's not log10 of (20*x) but 20 times log10(x).
Totally different formula.
For some reason you have to reverse the order. Or - use the multiplier externally. Ranges: >=0
It's not log10 of (20*x) but 20 times log10(x).
Totally different formula.
For some reason you have to reverse the order. Or - use the multiplier externally. Ranges: >=0
- Attachments
-
- dB.fsm
- (1.06 KiB) Downloaded 1314 times
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
Re: Calculating dB; Broken DSP?
tester wrote:
- Code: Select all
streamin in;
streamout out;
out = log10(in)*20;
Thanks tester, this works fine.
Of course, this is mathematically nonsensical, but it works now.
It doesn't work with extra parenthesis in the original order either; I had tried that.
- Perfect Human Interface
- Posts: 643
- Joined: Sun Mar 10, 2013 7:32 pm
Re: Calculating dB; Broken DSP?
It's a bug in the code compiler. (If you connect a text box to the String output of the DSP primitive, you get to see the compiler's assembly code.)
In the original form of the equation, the 'log10(x)' result is put into in register xmm0. The '20' value is then read from memory - straight into the same register! - and then gets multiplied by itself. 20 * 20 = 400!
So, you did nothing wrong - the alternative version just does things in a different order that the compiler doesn't mess up!
In the original form of the equation, the 'log10(x)' result is put into in register xmm0. The '20' value is then read from memory - straight into the same register! - and then gets multiplied by itself. 20 * 20 = 400!
So, you did nothing wrong - the alternative version just does things in a different order that the compiler doesn't mess up!
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
Don't stagnate, mutate to create!
-
trogluddite - Posts: 1730
- Joined: Fri Oct 22, 2010 12:46 am
- Location: Yorkshire, UK
Re: Calculating dB; Broken DSP?
Nubeat7 wrote:because x needs to be multiplied with 20 before you do log10
thanks tester, AFTER the log10
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
Re: Calculating dB; Broken DSP?
This code doesn't work either.
Input values are
y = 3.58509
a = 0
b = 16
c = 1
Clearly not as easy to follow but... it just spits out 0. I did it out manually and it gives me 0.8125, which is exactly what I was looking for.
Even if I change all the input values it just spits out 0.
- Code: Select all
streamin y;
streamin a;
streamin b;
streamin c;
streamout x;
x = -1*((a-y)*(b-c))/(a*(-2*b+c+y)+b*(c+y)-2*c*y);
Input values are
y = 3.58509
a = 0
b = 16
c = 1
Clearly not as easy to follow but... it just spits out 0. I did it out manually and it gives me 0.8125, which is exactly what I was looking for.
Even if I change all the input values it just spits out 0.
- Perfect Human Interface
- Posts: 643
- Joined: Sun Mar 10, 2013 7:32 pm
Re: Calculating dB; Broken DSP?
There is a limitation per lenght in "code", line lenght (some sort of asm translation limit). This is in manual, and I encountered it too. I would split this equation into smaller pieces, and thus - it should be easier to figure out which part is not working if that's still the case.
//edit:
Like this:
Works here.
But generally these parts can be done with regular prims (add, sub, multiply, etc).
//edit:
Like this:
- Code: Select all
streamin y;
streamin a;
streamin b;
streamin c;
streamout x;
float asd1, asd2;
asd1=(a-y)*(b-c);
asd2=a*(-2*b+c+y);
x = -1*asd1/(asd2+b*(c+y)-2*c*y);
Works here.
But generally these parts can be done with regular prims (add, sub, multiply, etc).
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
Re: Calculating dB; Broken DSP?
this is what i thought too but i think its not the reason..
from user guide:
"One limitation of the code component is that you can only have 8 successive operations in an
expression. For example, the expression:
a = 0+1+2+3+4+5+6+7+9+10;
is not allowed because there are 9 addition operations in a row. You can easily get round this by
splitting the expression up into smaller sections using brackets ‘(‘ and ‘)’. For example:
a = (0+1+2+3+4)+(5+6+7+9+10);"
so after the code is very nested it shouldnt be a problem,
if you just put the -1* to the end of the code it works,
if its at the beginning assembly tries to use register xmm999 which does the error, but maybe it is still because of the same problem, you have to think that there are only 8 registers in use so if there is to much to remember i think this can happen..
from user guide:
"One limitation of the code component is that you can only have 8 successive operations in an
expression. For example, the expression:
a = 0+1+2+3+4+5+6+7+9+10;
is not allowed because there are 9 addition operations in a row. You can easily get round this by
splitting the expression up into smaller sections using brackets ‘(‘ and ‘)’. For example:
a = (0+1+2+3+4)+(5+6+7+9+10);"
so after the code is very nested it shouldnt be a problem,
if you just put the -1* to the end of the code it works,
- Code: Select all
x = ((a-y)*(b-c))/(a*(b*-2+c+y)+b*(c+y)-2*c*y)*-1;
if its at the beginning assembly tries to use register xmm999 which does the error, but maybe it is still because of the same problem, you have to think that there are only 8 registers in use so if there is to much to remember i think this can happen..
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
Re: Calculating dB; Broken DSP?
I would be careful anyway. Having too many things in one line - may lead to easy mistakes (human factor).
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
11 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 58 guests