float to and from frequency
-
Sure... .25 = approx. 42Hz and .75 = approx. 189Hz I've found a little more information. The displayed values on the end device are arranged into 101 steps so the mid value is actually 0.49 which displays 87Hz (this will be rounded though)
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Are you sure that your given values (for .25, .5, .75) take into account that the range starts at 20Hz ? Because they all seem to be off by roughly 20 Hz here:
x a b f tgt xrev
0,00 10,00 1,00 20,0 20 0,00
0,25 7,75 0,89 62,1 42 0,25
0,50 5,50 0,74 118,7 89 0,50
0,75 3,25 0,51 205,5 189 0,75
1,00 1,00 0,00 400,0 400 1,00x : input
a = 10 - x * 9
b = log(a)
f = 400 - b * 380
tgt : target
xrev = (10-10^((400-f)/380))/9But maybe I'm missing something.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
-
Are you sure that your given values (for .25, .5, .75) take into account that the range starts at 20Hz ? Because they all seem to be off by roughly 20 Hz here:
x a b f tgt xrev
0,00 10,00 1,00 20,0 20 0,00
0,25 7,75 0,89 62,1 42 0,25
0,50 5,50 0,74 118,7 89 0,50
0,75 3,25 0,51 205,5 189 0,75
1,00 1,00 0,00 400,0 400 1,00x : input
a = 10 - x * 9
b = log(a)
f = 400 - b * 380
tgt : target
xrev = (10-10^((400-f)/380))/9But maybe I'm missing something.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
I've double checked the displayed results for those values and they are correct. All the spec says is:
logf [20.000, 400.000, 101] Hz
which means: log float with a range of 20-400Hz, 101 valid steps
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
I've double checked the displayed results for those values and they are correct. All the spec says is:
logf [20.000, 400.000, 101] Hz
which means: log float with a range of 20-400Hz, 101 valid steps
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)I'll give it another thought tomorrow. Maybe someone who's more talented in math will solve it in the meantime ;)
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
-
Mathematics is not my strong point! I'm coding against a protocol (OSC) that connects to an external device that takes a float between 0.0 and 1.0 to represent a frequency between 20Hz and 400Hz. The frequency scale is an inverse log curve so for example 0.5 represents approximately 89Hz. How on earth do I convert from the float to the frequency - and back again too?
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Frame the problem as a puzzle and drop it into the Lounge, I've seen a number of them get some detailed responses as long as they don't consider it a coding question you might get away with it :laugh:
Never underestimate the power of human stupidity RAH
-
Mathematics is not my strong point! I'm coding against a protocol (OSC) that connects to an external device that takes a float between 0.0 and 1.0 to represent a frequency between 20Hz and 400Hz. The frequency scale is an inverse log curve so for example 0.5 represents approximately 89Hz. How on earth do I convert from the float to the frequency - and back again too?
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Hmm, is this what you are asking? Generating a logarithmically spaced numbers[^]
-
Hmm, is this what you are asking? Generating a logarithmically spaced numbers[^]
Brilliant find Kenneth! I have tweaked the C# method on that page to:
float[] logValues = CreateLogValues(20, 400, 101);
public static float[] CreateLogValues(float minimum, float maximum, int valuesCount)
{
double logarithmicBase = Math.E;
double logMinimum = Math.Log(minimum);
double logMaximum = Math.Log(maximum);
double delta = (logMaximum - logMinimum) / (valuesCount - 1);
double accumulatedDelta = 0;
float[] values = new float[valuesCount];
for (int i = 0; i < valuesCount; ++i)
{
values[i] = (float)Math.Pow(logarithmicBase, logMinimum + accumulatedDelta);
accumulatedDelta += delta;
}
return values;
}which is a good start. I should be able to sort the rest from here :) Thanks :thumbsup:
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
I'll give it another thought tomorrow. Maybe someone who's more talented in math will solve it in the meantime ;)
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
Thanks for your help Sascha - I've got a solution, see my response to Kenneth below :thumbsup:
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
Frame the problem as a puzzle and drop it into the Lounge, I've seen a number of them get some detailed responses as long as they don't consider it a coding question you might get away with it :laugh:
Never underestimate the power of human stupidity RAH
Ha ha! I don't think I'd be that brave ;) Nearly there now thanks to Kenneth's find.
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
Brilliant find Kenneth! I have tweaked the C# method on that page to:
float[] logValues = CreateLogValues(20, 400, 101);
public static float[] CreateLogValues(float minimum, float maximum, int valuesCount)
{
double logarithmicBase = Math.E;
double logMinimum = Math.Log(minimum);
double logMaximum = Math.Log(maximum);
double delta = (logMaximum - logMinimum) / (valuesCount - 1);
double accumulatedDelta = 0;
float[] values = new float[valuesCount];
for (int i = 0; i < valuesCount; ++i)
{
values[i] = (float)Math.Pow(logarithmicBase, logMinimum + accumulatedDelta);
accumulatedDelta += delta;
}
return values;
}which is a good start. I should be able to sort the rest from here :) Thanks :thumbsup:
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)I have education in acoustics, were this comes up quite frequent :)
-
Brilliant find Kenneth! I have tweaked the C# method on that page to:
float[] logValues = CreateLogValues(20, 400, 101);
public static float[] CreateLogValues(float minimum, float maximum, int valuesCount)
{
double logarithmicBase = Math.E;
double logMinimum = Math.Log(minimum);
double logMaximum = Math.Log(maximum);
double delta = (logMaximum - logMinimum) / (valuesCount - 1);
double accumulatedDelta = 0;
float[] values = new float[valuesCount];
for (int i = 0; i < valuesCount; ++i)
{
values[i] = (float)Math.Pow(logarithmicBase, logMinimum + accumulatedDelta);
accumulatedDelta += delta;
}
return values;
}which is a good start. I should be able to sort the rest from here :) Thanks :thumbsup:
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Ah, you should be careful though, LogE and Log10 gives you quite different results! And log10 is the one that is used in acoustics. I would know, I have a Masters degree in it :-D
-
Ah, you should be careful though, LogE and Log10 gives you quite different results! And log10 is the one that is used in acoustics. I would know, I have a Masters degree in it :-D
I'll keep my eye on it for other parameters that use the logf type. For the 20-400HZ one Math.E is giving the correct result. Thanks for the heads up.
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
Thanks for your help Sascha - I've got a solution, see my response to Kenneth below :thumbsup:
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)DaveyM69 wrote:
Thanks for your help Sascha
Let's call it an attempt ;) Good to see you got a solution - I'll take a look at it myself, might come in handy some time. cheers, Sascha
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson