title: Plot Frequency Sweep In Python
body: <p>I want a sinus with linear increasing frequency in the range <code>[f_start : f_stop]</code> over time. </p>
  
  <p>However, when creating the appropriate signal in Python the last period has approximately twice the frequency expected, <code>2*f_stop</code>.</p>
  
  <p>Why?</p>
  
  <p>Here some minimal Python code which illustrates the problem:</p>
  
  <pre><code>import numpy
  import matplotlib.pyplot as plt
  
  Delta_t = 1     # Unit: Seconds
  samples = 1000
  
  total_time = samples*Delta_t
  t = numpy.linspace(0,total_time,num=samples)
  
  f_start = 1.0/total_time             # slow frequency (Period T = 1/f_start = 1000 samples)
  f_stop = 100.0/total_time           # high frequency (Period T = 1/f_stop = 10 samples)
  f_sweep = numpy.linspace(f_start,f_stop,num=samples) # Sweep from slow to high frequency
  
  
  # Create Sinusoids
  sinus_f_start = numpy.sin(2*numpy.pi*f_start*t)
  sinus_f_stop = numpy.sin(2*numpy.pi*f_stop*t)
  sinus_f_sweep = numpy.sin(2*numpy.pi*f_sweep*t)
  
  
  # Plot all sinusoids
  fig = plt.figure()
  
  fig.add_subplot(311)
  plt.plot(t,sinus_f_start)# Perfect! 1000 Samples per period.
  
  fig.add_subplot(312)
  plt.plot(t,sinus_f_stop) # Perfect! 10 Samples per period.
  
  fig.add_subplot(313)
  plt.plot(t,sinus_f_sweep)# Fail! Last period has 5 samples.
  
  plt.show()
  </code></pre>