Transforms (libnmfd.dsp.transforms)

libnmfd.dsp.transforms.forward_stft(x: numpy.ndarray, block_size: int = 2048, hop_size: int = 512, win: Optional[numpy.ndarray] = None, reconst_mirror: bool = True, append_frames: bool = True)Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray][source]

Given a time signal as input, this computes the spectrogram by means of the Short-time fourier transform

Parameters
  • x (np.ndarray) – The time signal oriented as numSamples x 1

  • block_size (int) – The block size to use during analysis

  • hop_size (int) – The hop size to use during analysis

  • win (np.ndarray) – The analysis window

  • reconst_mirror (bool) – This switch decides whether to discard the mirror spectrum or not

  • append_frames (bool) – This switch decides if we prepend/append silence in the beginning and the end

Returns
  • X (np.ndarray) – The complex valued spectrogram in num_bins x num_frames

  • A (np.ndarray) – The magnitude spectrogram

  • P (np.ndarray) – The phase spectrogram (wrapped in -pi … +pi)

libnmfd.dsp.transforms.inverse_stft(X: numpy.ndarray, block_size: int = 2048, hop_size: int = 512, ana_win_func: Optional[numpy.ndarray] = None, syn_win_func: Optional[numpy.ndarray] = None, reconst_mirror: bool = True, append_frames: bool = True, analytic_sig: bool = False, num_samp: Optional[int] = None)Tuple[numpy.ndarray, numpy.ndarray][source]

Given a valid STFT spectrogram as input, this reconstructs the corresponding time-domain signal by means of the frame-wise inverse FFT and overlap-add method described as LSEE-MSTFT in [1].

References

[1] Daniel W. Griffin and Jae S. Lim “Signal estimation from modified short-time fourier transform”, IEEE Transactions on Acoustics, Speech and Signal Processing, vol. 32, no. 2, pp. 236-243, Apr 1984.

Parameters
  • X (np.ndarray) – The complex-valued spectrogram matrix oriented with dimensions num_bins x num_frames

  • block_size (int) – The block size to use during synthesis

  • hop_size (int) – The hop size to use during synthesis

  • ana_win_func (np.ndarray) – The analysis window function

  • syn_win_func (np.ndarray) – The synthesis window function (per default set same as analysis window)

  • reconst_mirror (bool) – This switch decides whether the mirror spectrum should be reconstructed or not

  • append_frames (bool) – This switch decides whether to compensate for zero padding or not

  • analytic_sig (bool) – If this is set to True, we want the analytic signal

  • num_samp (int) – The original number of samples

Returns
  • y (np.ndarray) – The resynthesized signal

  • syn_win_func (np.ndarray) – The envelope used for normalization of the synthesis window

libnmfd.dsp.transforms.log_freq_log_mag(A: Union[numpy.ndarray, List[numpy.ndarray]], freq_res: float, bins_per_octave: int = 36, lower_freq: float = 32.70319566257483, log_comp: float = 1.0)Tuple[numpy.ndarray, numpy.ndarray][source]

Given a magnitude spectrogram, this function maps it onto a compact representation with logarithmically spaced frequency axis and logarithmic magnitude compression.

Parameters
  • A (np.ndarray or List of np.ndarray) – The real-valued magnitude spectrogram oriented as num_bins x num_frames, it can also be given as a list of multiple spectrograms

  • freq_res (float) – The spectral resolution of the spectrogram

  • bins_per_octave (np.ndarray) – The spectral selectivity of the log-freq axis

  • lower_freq (float) – The lower frequency border

  • log_comp (float) – Factor to control the logarithmic magnitude compression

Returns
  • log_freq_log_mag_A (np.ndarray) – The log-magnitude spectrogram on logarithmically spaced frequency axis

  • log_freq_axis (np.ndarray) – An array giving the center frequencies of each bin along the logarithmically spaced frequency axis