title: R: Generate sine wave with variable frequency
body: <p>This might be more of a math question than an R question but here it goes...</p>
  
  <p>I'm trying to generate a low frequency oscillator (LFO2) where the frequency is controlled by another low frequency oscillator (LFO1). LFO1 has a frequency of 0.02 Hz while I want LFO2 to have a frequency that oscillates between 0.00 and 0.11 Hz dependent on the output of LFO1.</p>
  
  <pre><code># length in seconds
  track_length &lt;- 356
  upsample &lt;- 10 # upsample the signal
  
  # LFO rates (Hz)
  rate1 &lt;- 0.02
  rate2_range &lt;- list(0.00, 0.11)
  
  # make plot of LFO1
  x1 &lt;- 1:(track_length*upsample)/upsample
  amp &lt;- (rate2_range[[2]] - rate2_range[[1]])/2
  y1 &lt;- amp*cos(2*pi*rate1*x1) + amp
  plot(x1, y1, type='l')
  </code></pre>
  
  <p>The variable frequency for LFO2 generated by LFO1 looks exactly as I expected.
  <a href="https://i.stack.imgur.com/yf5QJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yf5QJ.png" alt="LFO1 output"></a> </p>
  
  <p>So I go on to make LFO2 using the output of LFO1 like so..</p>
  
  <pre><code># make plot of LFO2
  x2 &lt;- x1
  y2 &lt;- cos(2*pi*y1*x2)
  plot(x2, y2, type='l')
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/BsliZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BsliZ.png" alt="enter image description here"></a></p>
  
  <p>However, the output of LFO2 is not what I expected... It seems to be continuously getting faster and also has some peaks that don't oscillate at the full range. I don't understand this as the only thing I'm adjusting is the frequency and it shouldn't be faster than 0.11 Hz. At first I thought it might be an under sampling issue but I get the same results when upsampling the time series to any degree. </p>
  
  <p>Any idea what I'm missing here?  </p>