smst.models.dft module

Functions that implement analysis and synthesis of sounds using the Discrete Fourier Transform.

For example usage check the smst.ui.models.dftModel_function module.

smst.models.dft.apply_normalized_window(samples, window)
smst.models.dft.apply_zero_phase_window(samples, window, fft_size)
smst.models.dft.from_audio(samples, window, fft_size)

Analyzes time-domain samples of a real signal using the Discrete Fourier Transform (DFT) into magnitude and phase spectrum of positive frequencies.

Parameters:
  • samples – samples of the input signal
  • window – samples of the analysis window
  • fft_size – size of the spectrum (power of two)
Returns:

  • magnitude_db_spectrum: magnitude spectrum (in decibels) of positive frequencies
  • phase_spectrum: unwrapped phase spectrum of positive frequencies

smst.models.dft.half_window_sizes(window_size)
smst.models.dft.select_magnitude_db_spectrum(spectrum)

Computes magnitude spectrum in decibels from complex-valued spectrum.

smst.models.dft.select_phase_spectrum(spectrum, phase_eps=1e-14)

Computes unwrapped phase spectrum out of complex spectrum.

Parameters:
  • spectrum – complex-valued spectrum
  • tol – threshold used to compute phase
smst.models.dft.select_positive_spectrum(spectrum)

Selects positive frequencies from a full spectrum.

smst.models.dft.spectrum_from_phase_and_magnitude(pos_magnitude_db_spectrum, pos_phase_spectrum, fft_size)
smst.models.dft.to_audio(magnitude_db_spectrum, phase_spectrum, window_size)

Synthesizes samples of windowed time-domain signal from the positive magnitude and phase spectrum using the Inverse Discrete Fourier Transform (IDFT).

Parameters:
  • magnitude_db_spectrum – positive magnitude spectrum in decibels
  • phase_spectrum – positive phase spectrum
  • window_size – window size (also size of the output signal)
Returns:

samples: reconstructed samples of the windowed signal

smst.models.dft.unapply_zero_phase_window(fft_buffer, window_size)