Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

227
Visualizações
How to make spectrogram's x axis start from 0 and end at full duration?

I created a 4 seconds length of data and plotted its spectrogram. nperseg was specified as 100. Due to this window length, the x axis does not start from 0 and end at 4s. Is there a way to align spectrogram's time axis with the original time domain signal?

from scipy import signal
import matplotlib.pyplot as plt
import numpy as np

fs = 100
N = 400
time = np.arange(N) / float(fs)
y = 500*np.cos(2*np.pi*5*time)

f, t, Sxx = signal.spectrogram(y, fs, nperseg = 100)
plt.pcolormesh(t, f, Sxx, shading='gouraud')
plt.ylabel('Frequency [Hz]')
plt.xlabel('Time [sec]')
plt.show()

plt.plot(time, y)

One example is shown in the figure below, both time domain signal and spectrogram start from 0 and end at 1s. Time domain signal and spectrogram

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can plot as you did and use xlim to align the X axes.

from scipy import signal
import matplotlib.pyplot as plt
import numpy as np

fs = 100
N = 400
time = np.arange(N) / float(fs)
y = 500*np.cos(2*np.pi*5*time**2/2)

f, t, Sxx = signal.spectrogram(y, fs, nperseg = 100)

plt.subplot(211)
plt.pcolormesh(t, f, Sxx, shading='gouraud')
plt.ylabel('Frequency [Hz]')
plt.xlabel('Time [sec]')
xlim = plt.xlim() # save the x limits of the first plot
plt.subplot(212)
plt.plot(time, y);

plt.xlim(xlim) # apply the saved limits to the second plot
plt.show()

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda