Loading ...
Sorry, an error occurred while loading the content.
 

Units/Scale/Range for 'x' in formula modification

Expand Messages
  • Will Styler
    Hi there, I m working on a formula modification to combine two sounds, such that one is added more strongly over time. For instance, so that a second tone
    Message 1 of 3 , Oct 30, 2017
      Hi there,

      I'm working on a formula modification to combine two sounds, such that one is added more strongly over time.  For instance, so that a second tone 'fades in' on top of a first tone:

      # Create two sounds
      Create Sound from formula: "a", 1, 0, 1, 44100, "1/2 * sin(2*pi*1500*x)"
      Create Sound from formula: "b", 1, 0, 1, 44100, "1/2 * sin(2*pi*987.7*x)"
       
      # Create a combination which is constant over time
      selectObject: "Sound a"
      Copy: "ab_combined_constant"
      Formula: "self [col] + Sound_b [col]"
       
      # Create a combination where B fades in
      selectObject: "Sound a"
      Copy: "ab_combined_overtime"
      Formula: "self [col] + ((0.5 * x)*Sound_b [col])"

      I'm using the 'x' operator in that final formula call to insert the timing of the overlap into the formula, increasing the amplitude of sound B over time.  This works, but my problem is that I don't at all understand what units/scale/range 'x' has.  

      According to my (possibly flawed) testing, it doesn't appear to be Zero-to-One, where one is the end of the sound.  It also doesn't appear to be the actual sample number (such that on the first row, it's equal to 1 and on the last, it's equal to 44,1000).  0.5 is an arbitrary number, but seems to capture a nice gradient.  Considering that I'm hoping to use this to make overlaid stimuli where I can control the 'slope and intercept' of the addition so to speak, my lack of understanding is tough.  

      Has anybody else done this successfully, such that, for instance, Sound B is completely absent at the first sample, and equal in power to A in the last?

      Thanks!

      Will
    • Paul Boersma
      ... x is in seconds. It is the time. In seconds. If you want to work relatively to the start and end of the sound, then you can use xmin and xmax. ... It is
      Message 2 of 3 , Oct 31, 2017
        On 31 Oct 2017, at 00:53, Will Styler will@... [praat-users] <praat-users-noreply@...> wrote:

        I'm using the 'x' operator in that final formula call to insert the timing of the overlap into the formula, increasing the amplitude of sound B over time.  This works, but my problem is that I don't at all understand what units/scale/range 'x' has.

        x is in seconds. It is the time. In seconds.

        If you want to work relatively to the start and end of the sound, then you can use xmin and xmax.

        Has anybody else done this successfully, such that, for instance, Sound B is completely absent at the first sample, and equal in power to A in the last?

        It is usual to do

        self * (x - xmin) / (xmax - xmin)

        although that aligns the 0 and 1 heights of your line with the logical time domain, not with the samples.

        If you insist on aligning the 0 and 1 heights with the first and last *sample*, you could do

        self * (x - x1) / ((nx - 1) * dx)

        Here x1 is the time of the first sample, nx is the number of samples, and dx is the sample period, so that (nx - 1) * dx is the time difference between the first and last sample.
        _____

        Paul Boersma
        Professor of Phonetic Sciences
        University of Amsterdam
        Spuistraat 134, room 632
        1012VB Amsterdam, The Netherlands
        http://www.fon.hum.uva.nl/paul/

      • Will Styler
        Thanks much, Paul. No idea why I didn t check for that! I ll update the Using Praat manual with this, too. Will
        Message 3 of 3 , Oct 31, 2017
          Thanks much, Paul.  No idea why I didn't check for that!  I'll update the 'Using Praat' manual with this, too.

          Will

          On Tue, Oct 31, 2017 at 3:24 AM, Paul Boersma <paul.boersma@...> wrote:
          On 31 Oct 2017, at 00:53, Will Styler will@... [praat-users] <praat-users-noreply@ yahoogroups.co.uk> wrote:

          I'm using the 'x' operator in that final formula call to insert the timing of the overlap into the formula, increasing the amplitude of sound B over time.  This works, but my problem is that I don't at all understand what units/scale/range 'x' has.

          x is in seconds. It is the time. In seconds.

          If you want to work relatively to the start and end of the sound, then you can use xmin and xmax.

          Has anybody else done this successfully, such that, for instance, Sound B is completely absent at the first sample, and equal in power to A in the last?

          It is usual to do

          self * (x - xmin) / (xmax - xmin)

          although that aligns the 0 and 1 heights of your line with the logical time domain, not with the samples.

          If you insist on aligning the 0 and 1 heights with the first and last *sample*, you could do

          self * (x - x1) / ((nx - 1) * dx)

          Here x1 is the time of the first sample, nx is the number of samples, and dx is the sample period, so that (nx - 1) * dx is the time difference between the first and last sample.
          _____

          Paul Boersma
          Professor of Phonetic Sciences


        Your message has been successfully submitted and will be delivered to recipients shortly.