spectran

Some functions for spectral analysis.

dsplab.spectran.calc_specgram(xdata, sample_rate=1, tdata=None, nseg=256, nstep=None, freq_bounds=None, extra_len=None)[source]

Return spectrogram data prepared to further plotting.

Parameters:
  • xdata (array_like) – Signal values
  • sample_rate (float) – Sampling frequency (Hz)
  • tdata (array_like) – Time values (sec)
  • nseg (integer) – Length of window (number of samples)
  • nstep (integer) – Length of step between Fourier transforms
  • freq_bounds (tuple of 2 float) – Bounds of showed band
  • extra_len (integer) – Number of values using for fft
Returns:

  • np.ndarray – Array of spectrums
  • np.ndarray – Time values

dsplab.spectran.spectrum(xdata, sample_rate=1, window='hamming', one_side=False, return_amplitude=True, extra_len=None, save_energy=False)[source]

Return the Fourier spectrum of signal.

Parameters:
  • xdata (array_like) – Signal values
  • sample_rate (float) – Sampling frequency (Hz)
  • window (str) – Window.
  • one_side (boolean) – If True, the one-side spectrum is calculated (default value is False)
  • return_amplitude (boolean) – If True, the amplitude spectrum is calculated
  • extra_len (int) – If the value is set, the signal is padded with zeros to the extra_len value.
  • save_energy (boolean) – If True, the result of FFT has the same energy as signal. If False, the X (spectrum) is multiplied to 2/len(xdata). Use False if you want to see the correct amplitude of components in spectrum.
Returns:

  • np.ndarray of complex numbers – Spectrum
  • np.ndarray of floats – Frequency values (Hz)

dsplab.spectran.stft(xdata, sample_rate=1, nseg=256, nstep=None, window='hamming', nfft=None, padded=False)[source]

Return result of short-time fourier transform.

Parameters:
  • xdata (numpy.ndarray) – Signal.
  • sample_rate (float) – Sampling frequency (Hz).
  • nseg (int) – Length of segment (in samples).
  • nstep (int) – Optional. Length of step (in samples). If not setted then equal to nseg//2.
  • window (str) – Window.
  • nfft (int) – Length of the FFT. If None or less than nseg, the FFT length is nseg.
Returns:

Result of STFT, two-side spectrums.

Return type:

numpy.ndarray