TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to use pgfmath to convert frequencies in hertz to the mel scale. I'm trying to implement a formula for which I have a Java source and which I have previously implemented with success in XSLT. My attempt with pgfmath yields the results which I would expect up to 1000, afterwards the decimal place is three places to the right of what I would expect. A small latex file demonstrating the problem follows. It includes Java and XSLT versions of the formula. I am new to pgfmath (but regularly use pgf) and my numerical math skills have languished for many years, so I am rather clueless at this point.


% java code borrowed from sphinx4 MelFrequencyFilterBank.java: 
% (2595.0 * (Math.log(1.0 + inputFreq / 700.0) / Math.log(10.0)))
% Implemented in XSLT as follows:
% <xsl:function name="local:hz2mel">
%     <xsl:param name="inputFreq" as="xs:double"/>
%     <xsl:value-of select="2595.0 * (math:log(1.0 + $inputFreq div 700.0)) div math:log(10.0)"/>
% </xsl:function>
% Attempt to implement in pgfmath
\foreach \x in {0, 200, 400, 1000, 1001, 2000, 5000,10000}
         {\x{} $\rightarrow$ \hztomel{\x}\\}

share|improve this question

closed as too localized by percusse, Claudio Fiandrino, lockstep, egreg, bloodworks Feb 3 '13 at 15:00

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

I get 10000 → 3073.0856 and the site you have linked confirms up to some decimals, is that wrong? Also log10 function is defined. – percusse Feb 3 '13 at 13:12
No, it's not wrong. Strangely, when I run the test file through pdflatex I get 10000 → 3.07307 as output in the PDF file. - George – George S. Feb 3 '13 at 13:16
Maybe your PGF version is outdated. I'm using v2.10. You can check yours by putting \listfiles command somewhere in the preamble and reading the log output. – percusse Feb 3 '13 at 13:19
That must be it then. I have version 1.414213 29/9/2007 from the texlive in debian squeeze. I'll get a newer version and report back. Thanks, George – George S. Feb 3 '13 at 13:28
Problem solved. I had PGF version v2.00. Using v2.10 I get the correct output. Thank you very much!!! – George S. Feb 3 '13 at 14:13

Browse other questions tagged or ask your own question.