Turning an autocorrelation formula into code?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I am a programmer and my current project requires me to turn a research paper into runnable code.



My level of math experience is fairly low, but what needs to be done has to be done either way, and I'm determined to learn new things.



The research paper can be found here: https://pdfs.semanticscholar.org/0124/09d447691fd74c49bc407b3818b4617641b2.pdf



On page 2 we can see two formulas, one (the first one):



enter image description here



of which I think I have correctly programmed as it is giving me the following results:



enter image description here



which has similarities to Fig 1a:
enter image description here



However I can not figure out how to get results to resemble Fig 1b and 1c.



Would it be too much to ask for someone to explain what's going on with the second formula on page 2, or even pseudo-code that would reflect the formula?



If it is too much to ask for, I'd like to start by asking:
What is this part of the formula doing? Is it multiplying s[n] and s[n + l] which would result in s[n] * s[n + l]?



More about this as a code code can be found in the following StackOverflow question that I made, which is more code-oriented: https://stackoverflow.com/questions/51352890/is-this-autocorrelation-formula-correctly-programmed?noredirect=1#comment89739564_51352890







share|cite|improve this question























    up vote
    0
    down vote

    favorite












    I am a programmer and my current project requires me to turn a research paper into runnable code.



    My level of math experience is fairly low, but what needs to be done has to be done either way, and I'm determined to learn new things.



    The research paper can be found here: https://pdfs.semanticscholar.org/0124/09d447691fd74c49bc407b3818b4617641b2.pdf



    On page 2 we can see two formulas, one (the first one):



    enter image description here



    of which I think I have correctly programmed as it is giving me the following results:



    enter image description here



    which has similarities to Fig 1a:
    enter image description here



    However I can not figure out how to get results to resemble Fig 1b and 1c.



    Would it be too much to ask for someone to explain what's going on with the second formula on page 2, or even pseudo-code that would reflect the formula?



    If it is too much to ask for, I'd like to start by asking:
    What is this part of the formula doing? Is it multiplying s[n] and s[n + l] which would result in s[n] * s[n + l]?



    More about this as a code code can be found in the following StackOverflow question that I made, which is more code-oriented: https://stackoverflow.com/questions/51352890/is-this-autocorrelation-formula-correctly-programmed?noredirect=1#comment89739564_51352890







    share|cite|improve this question





















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am a programmer and my current project requires me to turn a research paper into runnable code.



      My level of math experience is fairly low, but what needs to be done has to be done either way, and I'm determined to learn new things.



      The research paper can be found here: https://pdfs.semanticscholar.org/0124/09d447691fd74c49bc407b3818b4617641b2.pdf



      On page 2 we can see two formulas, one (the first one):



      enter image description here



      of which I think I have correctly programmed as it is giving me the following results:



      enter image description here



      which has similarities to Fig 1a:
      enter image description here



      However I can not figure out how to get results to resemble Fig 1b and 1c.



      Would it be too much to ask for someone to explain what's going on with the second formula on page 2, or even pseudo-code that would reflect the formula?



      If it is too much to ask for, I'd like to start by asking:
      What is this part of the formula doing? Is it multiplying s[n] and s[n + l] which would result in s[n] * s[n + l]?



      More about this as a code code can be found in the following StackOverflow question that I made, which is more code-oriented: https://stackoverflow.com/questions/51352890/is-this-autocorrelation-formula-correctly-programmed?noredirect=1#comment89739564_51352890







      share|cite|improve this question











      I am a programmer and my current project requires me to turn a research paper into runnable code.



      My level of math experience is fairly low, but what needs to be done has to be done either way, and I'm determined to learn new things.



      The research paper can be found here: https://pdfs.semanticscholar.org/0124/09d447691fd74c49bc407b3818b4617641b2.pdf



      On page 2 we can see two formulas, one (the first one):



      enter image description here



      of which I think I have correctly programmed as it is giving me the following results:



      enter image description here



      which has similarities to Fig 1a:
      enter image description here



      However I can not figure out how to get results to resemble Fig 1b and 1c.



      Would it be too much to ask for someone to explain what's going on with the second formula on page 2, or even pseudo-code that would reflect the formula?



      If it is too much to ask for, I'd like to start by asking:
      What is this part of the formula doing? Is it multiplying s[n] and s[n + l] which would result in s[n] * s[n + l]?



      More about this as a code code can be found in the following StackOverflow question that I made, which is more code-oriented: https://stackoverflow.com/questions/51352890/is-this-autocorrelation-formula-correctly-programmed?noredirect=1#comment89739564_51352890









      share|cite|improve this question










      share|cite|improve this question




      share|cite|improve this question









      asked Jul 17 at 21:04









      vaid

      101




      101




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          First, this is my understanding of skimming the reseach paper. It may not be correct or even 'near the spot'.



          Fig 1a) is not showing the application of any of the formulas, it is showing the input sample (called $s[n]$ in he formulas). That's written in the part below the figure, where it shortly explains what (a), (b) and (c) are. If you have applied forumla (1), you should have gotten something curve 1b).



          Also, formulas (1) and (2) are using a letter "l" (el) for the lag, not (as one would assume from a casual inspection) the number "1" (one).



          You are correct that both formulas are summing up a bunch of products of the form $s[n]times s[n+l]$. They both start that summation at $n=i$ ($i$ seems to be zero in the examples). They differ in how far they sum, formula (1) sums until $n=i+N-l$, while formula (2) sums until $n=i+N-2l$.



          The paper says




          Figure 1b-c show the ACF of the acoustic waveform

          which were normalized and half-wave rectified from Fig. 1a.




          I understand what normalized means (it means that the value for $R_X(l)$ has been divided by $R_X(0)$, such that the curves in 1b) and 1c) start with a value of 1 at $l=0$. I have no idea what "half-wave rectified" means, though.






          share|cite|improve this answer





















          • careful with the second equation, it actually sums until n = i + N - l - 1 theres an "el" and a "one" in there. and you are correct, I should've gotten something like fig b, but I'm not, surely my code is wrong somewhere. hmmm....
            – vaid
            Jul 18 at 12:38











          • Can you post the code? I meas once you understand what the summation does, it should be 2-3 lines of code (for the forumula). About "el" vs. one: I only realized just now that you can copy the text from the pdf and see what is actually used. OTOH, then I don't understand the big difference between 1b) and 1c): Leaving out one summand should not influence the result that much.
            – Ingix
            Jul 18 at 12:59











          • I've included a link to my code in the question.
            – vaid
            Jul 19 at 23:16










          • I've included a link to my code in the question.
            – vaid
            Jul 19 at 23:17










          • I can't comment on the coding things at the moment, but the most important thing I see is that lag is always set to 1. This is not what it is supposed to be. The figures you see in 1b) and 1c) are figures where the lag is the independent variable. In the formula for $R_x$ all things are 'given': The input data s[n], the frame size $N$ etc. The only thing that can be varied by you is the lag. See also the sentence from the area between formula (1) and (2): "The lag value that produces maximum peak will be chosen as the pitch period."
            – Ingix
            Jul 20 at 10:13










          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "69"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          noCode: true, onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2854921%2fturning-an-autocorrelation-formula-into-code%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          First, this is my understanding of skimming the reseach paper. It may not be correct or even 'near the spot'.



          Fig 1a) is not showing the application of any of the formulas, it is showing the input sample (called $s[n]$ in he formulas). That's written in the part below the figure, where it shortly explains what (a), (b) and (c) are. If you have applied forumla (1), you should have gotten something curve 1b).



          Also, formulas (1) and (2) are using a letter "l" (el) for the lag, not (as one would assume from a casual inspection) the number "1" (one).



          You are correct that both formulas are summing up a bunch of products of the form $s[n]times s[n+l]$. They both start that summation at $n=i$ ($i$ seems to be zero in the examples). They differ in how far they sum, formula (1) sums until $n=i+N-l$, while formula (2) sums until $n=i+N-2l$.



          The paper says




          Figure 1b-c show the ACF of the acoustic waveform

          which were normalized and half-wave rectified from Fig. 1a.




          I understand what normalized means (it means that the value for $R_X(l)$ has been divided by $R_X(0)$, such that the curves in 1b) and 1c) start with a value of 1 at $l=0$. I have no idea what "half-wave rectified" means, though.






          share|cite|improve this answer





















          • careful with the second equation, it actually sums until n = i + N - l - 1 theres an "el" and a "one" in there. and you are correct, I should've gotten something like fig b, but I'm not, surely my code is wrong somewhere. hmmm....
            – vaid
            Jul 18 at 12:38











          • Can you post the code? I meas once you understand what the summation does, it should be 2-3 lines of code (for the forumula). About "el" vs. one: I only realized just now that you can copy the text from the pdf and see what is actually used. OTOH, then I don't understand the big difference between 1b) and 1c): Leaving out one summand should not influence the result that much.
            – Ingix
            Jul 18 at 12:59











          • I've included a link to my code in the question.
            – vaid
            Jul 19 at 23:16










          • I've included a link to my code in the question.
            – vaid
            Jul 19 at 23:17










          • I can't comment on the coding things at the moment, but the most important thing I see is that lag is always set to 1. This is not what it is supposed to be. The figures you see in 1b) and 1c) are figures where the lag is the independent variable. In the formula for $R_x$ all things are 'given': The input data s[n], the frame size $N$ etc. The only thing that can be varied by you is the lag. See also the sentence from the area between formula (1) and (2): "The lag value that produces maximum peak will be chosen as the pitch period."
            – Ingix
            Jul 20 at 10:13














          up vote
          0
          down vote













          First, this is my understanding of skimming the reseach paper. It may not be correct or even 'near the spot'.



          Fig 1a) is not showing the application of any of the formulas, it is showing the input sample (called $s[n]$ in he formulas). That's written in the part below the figure, where it shortly explains what (a), (b) and (c) are. If you have applied forumla (1), you should have gotten something curve 1b).



          Also, formulas (1) and (2) are using a letter "l" (el) for the lag, not (as one would assume from a casual inspection) the number "1" (one).



          You are correct that both formulas are summing up a bunch of products of the form $s[n]times s[n+l]$. They both start that summation at $n=i$ ($i$ seems to be zero in the examples). They differ in how far they sum, formula (1) sums until $n=i+N-l$, while formula (2) sums until $n=i+N-2l$.



          The paper says




          Figure 1b-c show the ACF of the acoustic waveform

          which were normalized and half-wave rectified from Fig. 1a.




          I understand what normalized means (it means that the value for $R_X(l)$ has been divided by $R_X(0)$, such that the curves in 1b) and 1c) start with a value of 1 at $l=0$. I have no idea what "half-wave rectified" means, though.






          share|cite|improve this answer





















          • careful with the second equation, it actually sums until n = i + N - l - 1 theres an "el" and a "one" in there. and you are correct, I should've gotten something like fig b, but I'm not, surely my code is wrong somewhere. hmmm....
            – vaid
            Jul 18 at 12:38











          • Can you post the code? I meas once you understand what the summation does, it should be 2-3 lines of code (for the forumula). About "el" vs. one: I only realized just now that you can copy the text from the pdf and see what is actually used. OTOH, then I don't understand the big difference between 1b) and 1c): Leaving out one summand should not influence the result that much.
            – Ingix
            Jul 18 at 12:59











          • I've included a link to my code in the question.
            – vaid
            Jul 19 at 23:16










          • I've included a link to my code in the question.
            – vaid
            Jul 19 at 23:17










          • I can't comment on the coding things at the moment, but the most important thing I see is that lag is always set to 1. This is not what it is supposed to be. The figures you see in 1b) and 1c) are figures where the lag is the independent variable. In the formula for $R_x$ all things are 'given': The input data s[n], the frame size $N$ etc. The only thing that can be varied by you is the lag. See also the sentence from the area between formula (1) and (2): "The lag value that produces maximum peak will be chosen as the pitch period."
            – Ingix
            Jul 20 at 10:13












          up vote
          0
          down vote










          up vote
          0
          down vote









          First, this is my understanding of skimming the reseach paper. It may not be correct or even 'near the spot'.



          Fig 1a) is not showing the application of any of the formulas, it is showing the input sample (called $s[n]$ in he formulas). That's written in the part below the figure, where it shortly explains what (a), (b) and (c) are. If you have applied forumla (1), you should have gotten something curve 1b).



          Also, formulas (1) and (2) are using a letter "l" (el) for the lag, not (as one would assume from a casual inspection) the number "1" (one).



          You are correct that both formulas are summing up a bunch of products of the form $s[n]times s[n+l]$. They both start that summation at $n=i$ ($i$ seems to be zero in the examples). They differ in how far they sum, formula (1) sums until $n=i+N-l$, while formula (2) sums until $n=i+N-2l$.



          The paper says




          Figure 1b-c show the ACF of the acoustic waveform

          which were normalized and half-wave rectified from Fig. 1a.




          I understand what normalized means (it means that the value for $R_X(l)$ has been divided by $R_X(0)$, such that the curves in 1b) and 1c) start with a value of 1 at $l=0$. I have no idea what "half-wave rectified" means, though.






          share|cite|improve this answer













          First, this is my understanding of skimming the reseach paper. It may not be correct or even 'near the spot'.



          Fig 1a) is not showing the application of any of the formulas, it is showing the input sample (called $s[n]$ in he formulas). That's written in the part below the figure, where it shortly explains what (a), (b) and (c) are. If you have applied forumla (1), you should have gotten something curve 1b).



          Also, formulas (1) and (2) are using a letter "l" (el) for the lag, not (as one would assume from a casual inspection) the number "1" (one).



          You are correct that both formulas are summing up a bunch of products of the form $s[n]times s[n+l]$. They both start that summation at $n=i$ ($i$ seems to be zero in the examples). They differ in how far they sum, formula (1) sums until $n=i+N-l$, while formula (2) sums until $n=i+N-2l$.



          The paper says




          Figure 1b-c show the ACF of the acoustic waveform

          which were normalized and half-wave rectified from Fig. 1a.




          I understand what normalized means (it means that the value for $R_X(l)$ has been divided by $R_X(0)$, such that the curves in 1b) and 1c) start with a value of 1 at $l=0$. I have no idea what "half-wave rectified" means, though.







          share|cite|improve this answer













          share|cite|improve this answer



          share|cite|improve this answer











          answered Jul 18 at 10:20









          Ingix

          2,205125




          2,205125











          • careful with the second equation, it actually sums until n = i + N - l - 1 theres an "el" and a "one" in there. and you are correct, I should've gotten something like fig b, but I'm not, surely my code is wrong somewhere. hmmm....
            – vaid
            Jul 18 at 12:38











          • Can you post the code? I meas once you understand what the summation does, it should be 2-3 lines of code (for the forumula). About "el" vs. one: I only realized just now that you can copy the text from the pdf and see what is actually used. OTOH, then I don't understand the big difference between 1b) and 1c): Leaving out one summand should not influence the result that much.
            – Ingix
            Jul 18 at 12:59











          • I've included a link to my code in the question.
            – vaid
            Jul 19 at 23:16










          • I've included a link to my code in the question.
            – vaid
            Jul 19 at 23:17










          • I can't comment on the coding things at the moment, but the most important thing I see is that lag is always set to 1. This is not what it is supposed to be. The figures you see in 1b) and 1c) are figures where the lag is the independent variable. In the formula for $R_x$ all things are 'given': The input data s[n], the frame size $N$ etc. The only thing that can be varied by you is the lag. See also the sentence from the area between formula (1) and (2): "The lag value that produces maximum peak will be chosen as the pitch period."
            – Ingix
            Jul 20 at 10:13
















          • careful with the second equation, it actually sums until n = i + N - l - 1 theres an "el" and a "one" in there. and you are correct, I should've gotten something like fig b, but I'm not, surely my code is wrong somewhere. hmmm....
            – vaid
            Jul 18 at 12:38











          • Can you post the code? I meas once you understand what the summation does, it should be 2-3 lines of code (for the forumula). About "el" vs. one: I only realized just now that you can copy the text from the pdf and see what is actually used. OTOH, then I don't understand the big difference between 1b) and 1c): Leaving out one summand should not influence the result that much.
            – Ingix
            Jul 18 at 12:59











          • I've included a link to my code in the question.
            – vaid
            Jul 19 at 23:16










          • I've included a link to my code in the question.
            – vaid
            Jul 19 at 23:17










          • I can't comment on the coding things at the moment, but the most important thing I see is that lag is always set to 1. This is not what it is supposed to be. The figures you see in 1b) and 1c) are figures where the lag is the independent variable. In the formula for $R_x$ all things are 'given': The input data s[n], the frame size $N$ etc. The only thing that can be varied by you is the lag. See also the sentence from the area between formula (1) and (2): "The lag value that produces maximum peak will be chosen as the pitch period."
            – Ingix
            Jul 20 at 10:13















          careful with the second equation, it actually sums until n = i + N - l - 1 theres an "el" and a "one" in there. and you are correct, I should've gotten something like fig b, but I'm not, surely my code is wrong somewhere. hmmm....
          – vaid
          Jul 18 at 12:38





          careful with the second equation, it actually sums until n = i + N - l - 1 theres an "el" and a "one" in there. and you are correct, I should've gotten something like fig b, but I'm not, surely my code is wrong somewhere. hmmm....
          – vaid
          Jul 18 at 12:38













          Can you post the code? I meas once you understand what the summation does, it should be 2-3 lines of code (for the forumula). About "el" vs. one: I only realized just now that you can copy the text from the pdf and see what is actually used. OTOH, then I don't understand the big difference between 1b) and 1c): Leaving out one summand should not influence the result that much.
          – Ingix
          Jul 18 at 12:59





          Can you post the code? I meas once you understand what the summation does, it should be 2-3 lines of code (for the forumula). About "el" vs. one: I only realized just now that you can copy the text from the pdf and see what is actually used. OTOH, then I don't understand the big difference between 1b) and 1c): Leaving out one summand should not influence the result that much.
          – Ingix
          Jul 18 at 12:59













          I've included a link to my code in the question.
          – vaid
          Jul 19 at 23:16




          I've included a link to my code in the question.
          – vaid
          Jul 19 at 23:16












          I've included a link to my code in the question.
          – vaid
          Jul 19 at 23:17




          I've included a link to my code in the question.
          – vaid
          Jul 19 at 23:17












          I can't comment on the coding things at the moment, but the most important thing I see is that lag is always set to 1. This is not what it is supposed to be. The figures you see in 1b) and 1c) are figures where the lag is the independent variable. In the formula for $R_x$ all things are 'given': The input data s[n], the frame size $N$ etc. The only thing that can be varied by you is the lag. See also the sentence from the area between formula (1) and (2): "The lag value that produces maximum peak will be chosen as the pitch period."
          – Ingix
          Jul 20 at 10:13




          I can't comment on the coding things at the moment, but the most important thing I see is that lag is always set to 1. This is not what it is supposed to be. The figures you see in 1b) and 1c) are figures where the lag is the independent variable. In the formula for $R_x$ all things are 'given': The input data s[n], the frame size $N$ etc. The only thing that can be varied by you is the lag. See also the sentence from the area between formula (1) and (2): "The lag value that produces maximum peak will be chosen as the pitch period."
          – Ingix
          Jul 20 at 10:13












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2854921%2fturning-an-autocorrelation-formula-into-code%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          What is the equation of a 3D cone with generalised tilt?

          Color the edges and diagonals of a regular polygon

          Relationship between determinant of matrix and determinant of adjoint?