title: Spectogram with unexpected results (Python, scipy.signal)
body: <p>I'm looking for a clarification of what I get wrong in my understanding or implementation of spectogram plotting.</p>
  <p>To be sure that I get everything correct I started with a toy example, so I generated a very simple signal (sum of three periodic signals of different frequency and phase shift, no noise)
  as fallow:</p>
  <pre class="lang-py prettyprint-override"><code>import numpy as np
  sampling_rate = 1.0 / 1000
  duration = 2
  t = np.arange(0, duration, sampling_rate)
  
  # Signal 1 
  A_1 = 0.8 # amplitude of the cosine wave
  f_1 = 100 # frequency of the cosine wave
  phase_1 = 30  #desired phase shift of the cosine in degrees
  phi_1 = phase_1*np.pi/180
  s1 = A_1*np.cos(2*np.pi*f_1*t+phi_1)
  
  # Signal 2 
  A_2 = 0.3 # amplitude of the cosine wave
  f_2 = 8 # frequency of the cosine wave
  phase_2 = 45  #desired phase shift of the cosine in degrees
  phi_2 = phase_2*np.pi/180
  s2 = A_2*np.cos(2*np.pi*f_2*t+phi_2)
  
  # Signal 3 
  A_3 = 0.1 # amplitude of the cosine wave
  f_3 = 60 # frequency of the cosine wave
  phase_3 = -10  #desired phase shift of the cosine in degrees
  phi_3 = phase_3*np.pi/180
  s3 = A_3*np.cos(2*np.pi*f_3*t+phi_3)
  
  # Result
  x = s1 + s2 + s3
  </code></pre>
  <p>I expected that the spectrogram from the &quot;x&quot; signal would be three horizontal lines corresponding to the three frequencies of the generated signal. The signal doesn't change over time so I expected results similar to FFT, but in a different representation.</p>
  <p>But after plotting it with the code below:</p>
  <pre class="lang-py prettyprint-override"><code>from scipy import signal
  import matplotlib.pyplot as plt
  
  freqs, times, spectrogram = signal.spectrogram(x)
  
  plt.figure(figsize=(8, 6))
  plt.imshow(spectrogram, aspect='auto', cmap='hot_r', origin='lower')
  plt.title('Spectrogram')
  plt.ylabel('Frequency band')
  plt.xlabel('Time window')
  plt.tight_layout()
  </code></pre>
  <p>I get something quite unexpected:</p>
  <p><a href="https://i.stack.imgur.com/FMjEI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FMjEI.png" alt="Unexpected spectogram result" /></a></p>
  <p>The found frequencies do not make sense.</p>
  <p>So my question is: where I made a mistake? My expectations were wrong? My implementation is spoiled somehow? Maybe someone can recommend me a good source of knowledge on this topic?</p>
  <p>Thank you very much in advance for your time and help.</p>