Exemplo n.º 1
0
    def synthesis(self, X=None):
        """
        Perform time synthesis of frequency domain to real signal using the
        inverse DFT.

        Parameters
        ----------
        X : numpy array, optional
            Complex signal in frequency domain. Default is to use DFT computed
            from ``analysis``.

        Returns
        -------
        numpy array
            IDFT of ``self.X`` or input if given.
        """

        # check for valid input
        if X is not None:
            if X.shape != self.X.shape:
                raise ValueError(
                    "Invalid input dimensions! Got (%d, %d), expecting (%d, %d)."
                    % (X.shape[0], X.shape[1], self.X.shape[0], self.X.shape[1])
                )

            self.X[
                :,
            ] = X

        # inverse DFT
        if self.transform == "fftw":
            self.b[:] = self.X
            self.x[
                :,
            ] = self._backward()
        elif self.transform == "mkl":
            self.x[
                :,
            ] = mkl_fft.irfft_numpy(self.X, self.nfft, axis=self.axis)
        else:
            self.x[
                :,
            ] = irfft(self.X, self.nfft, axis=self.axis)

        # apply window if needed
        if self.synthesis_window is not None:
            np.multiply(self.synthesis_window, self.x, self.x)

        return self.x
Exemplo n.º 2
0
    a = pyfftw.empty_aligned([nfft, D], dtype="float32")
    b = pyfftw.empty_aligned([nfft // 2 + 1, D], dtype="complex64")
    c = pyfftw.empty_aligned([nfft, D], dtype="float32")
    forward = pyfftw.FFTW(a, b, axes=(0, ))
    backward = pyfftw.FFTW(b, c, axes=(0, ), direction="FFTW_BACKWARD")

    start_time = time.time()
    for k in range(n_trials):
        forward()
    analysis_time = (time.time() - start_time) / n_trials * 1e6
    start_time = time.time()
    for k in range(n_trials):
        backward()
    synthesis_time = (time.time() - start_time) / n_trials * 1e6
    print(
        "avg fftw w/o class : %f [1e-6 sec], (analysis, synthesis)=(%f, %f) [1e-6 sec]"
        % (analysis_time + synthesis_time, analysis_time, synthesis_time))

if mkl_available:
    start_time = time.time()
    for k in range(n_trials):
        X = mkl_fft.rfft_numpy(x)
    analysis_time = (time.time() - start_time) / n_trials * 1e6
    start_time = time.time()
    for k in range(n_trials):
        x_r = mkl_fft.irfft_numpy(X)
    synthesis_time = (time.time() - start_time) / n_trials * 1e6
    print(
        "avg mkl w/o class : %f [1e-6 sec], (analysis, synthesis)=(%f, %f) [1e-6 sec]"
        % (analysis_time + synthesis_time, analysis_time, synthesis_time))